Jump to content

Cannot place orders in any Expert Advisor; Error Code 130 and 131


Recommended Posts

Posted

I have been attempting to place a trade, any trade, in my Demo Account, using an Expert Advisor. When the EA issues a Buy or Sell order, I get error code 130 or 131.

Yes, I have the AutoTrading button enabled on the chart, and "Live Trading" is checked. 

Yes, I am trading EURUSD.FX. And yes, I can place a manual trade, either Buy or Sell.

For your information, I am using Linux, with Wine that emulates Windows. I have not experienced any other issues, and as I said, I can issue manual Buy and Sell orders. So I don't think Wine is getting in the way. I think it's something with my Buy and Sell order within the EA. Maybe the wrong lot size, or some other parameter. I have tried changing the lot size, but it makes no difference.

I am posting here the code from my EA, and the code for the function, which gets called from the EA. I am also posting a screen print, showing the actual error code.

I realize that if I get this code to work, I will be submitting Buy or Sell orders extremely rapidly, until I run out of margin. I am on a Demo Account, so I'm not worried about that right now. I'll address that issue when I can actually get some orders submitted.

So, what gives? What am I doing wrong? Thanks.

bool CheckOpenOrders(){ 
        // We need to scan all the open and pending orders to see if there are any.
        // OrdersTotal returns the total number of market and pending orders.
        // What we do is scan all orders and check if they are of the same symbol as the one where the EA is running.
        for( int i = 0 ; i < OrdersTotal() ; i++ ) { 
                // We select the order of index i selecting by position and from the pool of market/pending trades.
                OrderSelect( i, SELECT_BY_POS, MODE_TRADES ); 
                // If the pair of the order is equal to the pair where the EA is running.
                if (OrderSymbol() == Symbol()) return(true); 
        } 
        // If the loop finishes it mean there were no open orders for that pair.
        return(false); 

//+------------------------------------------------------------------+
//|                                                 Alternator01.mq4 |
//|                                                     Len Cheatham |
//|                                             https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "Len Cheatham"
#property link      "https://www.mql4.com"
#property version   "1.00"
#property strict
#include <C:/Program Files (x86)/IG MetaTrader 4 Terminal/MQL4/Include/Strings/CustomFunctions01.mqh>
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   Alert("Are there open orders for this currency? ",CheckOpenOrders()); 
   Alert("");
   Alert("Symbol = ", Symbol());  
   if (Close[0] > Open[0])
   {
     int orderID = OrderSend(_Symbol,OP_BUY,0.0001,Ask,10,1.001,1.001);
     if(orderID < 0) Alert("Buy Order rejected, Order error: " + GetLastError());
//     if(CheckOpenOrders())
//     {
//       if // Sell the current 
//     }
   }
   else
     {
       if (Close[0] < Open[0])
       {
         int orderID = OrderSend(_Symbol,OP_SELL,0.0001,Bid,10,1.001,1.001);
         if(orderID < 0) Alert("Sell Order rejected, Order error: " + GetLastError());
       }
     }
  }
//+------------------------------------------------------------------+
 

Screenshot from 2022-03-24 09-22-41.png

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • image.png

  • Posts

    • Hey guys, I came across and event to earn big rewards with only 6 Days to Mine (Dec 10–16) Reward Pools: USDT Pool: 3,960 $HYPE (660/day) And BTC Pool: 2,640 $HYPE (440/day) with Staking Limits are maximum of 10,000 USDT & maximum of 0.1 BTC. Don’t miss out on this exclusive opportunity to mine $HYPE while staking your assets on BingX exchange.
    • $KIP Protocol is making waves in the blockchain world with its AI-driven approach to Web3 innovation. Built on the Ethereum blockchain, KIP offers a secure and scalable foundation, enabling users to harness the potential of AI in decentralized ecosystems. To celebrate its growth, KIP Protocol has launched an exciting opportunity for participants to earn rewards through its listing carnival on BingX. A massive 3,000,000 KIP tokens are up for grabs, offering users a chance to trade and earn while supporting the protocol's ecosystem. By combining Ethereum’s robust infrastructure with AI's transformative capabilities, KIP Protocol is positioned to lead the way in creating intelligent and decentralized solutions. This initiative underscores the increasing synergy between blockchain and emerging technologies, making it a project worth exploring. Are you ready to trade, earn, and be part of the next wave in blockchain innovation?
    • Airdrops are a popular method in the crypto space to reward loyal users and encourage new adopters. Tomarket is no exception, aiming to reward its most active players by distributing 80% of its TOMA token supply through a series of Tomarket airdrop stages. This initiative recognizes the contributions of users who have supported Tomarket’s growth on the TON blockchain. (To participate click here) The Four Phases of the Airdrop Tomarket airdrop is being carried out in four distinct stages, each designed to reward different segments of the community. Stage 1: Completed on October 31, 30% of the TOMA tokens were released to early participants. Stage 2: A further 30% of the TOMA supply will be revealed before the official token listing on December 20. Stage 3: An additional 17% of the TOMA tokens will be distributed during this phase, though the exact timing is still to be determined. Stage 4: The final 3% will be allocated to early adopters, with specific timing for this stage yet to be announced. How to Qualify for the Tomarket Airdrop Participating in the Tomarket airdrop is simple, but there are a few tasks you need to complete to be eligible: Add the Tomato Emoji: Add a tomato emoji to your Telegram display name to show you're part of the Tomarket community. Reach Bronze Level: Achieve at least Level 4 (Bronze) in the Tomarket game to prove your activity on the platform. Connect a TON Wallet: Link your Tomarket account to a TON wallet to receive the tokens. Join the Telegram Channel: Make sure you’re a member of the Tomarket announcement channel on Telegram to stay updated on all airdrop details. Optional Premium Medal: You can purchase a premium medal for $5, which unlocks additional rewards and gives you access to 100% of your tokens during the Tomarket airdrop. How to Claim Tomarket Airdrop Tokens Once the Tomarket airdrop is live, you’ll be able to claim your Tomarket airdrop tokens directly within the Tomarket app. From there, you can withdraw the tokens to your external wallet for easy access. This streamlined process ensures that getting your rewards is quick and hassle-free. Exclusive Features and the Farming Pool Beyond the Tomarket airdrop, the project is introducing a Farming Pool for TOMA token holders. This feature will allow users to earn more tokens by referring others and participating in various exclusive projects. For players who purchase the premium medal, additional benefits will unlock, enhancing the overall gaming experience. These benefits could include more opportunities to earn tokens, access to special promotions, and other unique features that will be revealed in the future. Explore upcoming crypto airdrops: https://markets.coinpedia.org/airdrops/
×
×
  • Create New...
us