Jump to content

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


Recommended Posts

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

Link to comment

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
  • Posts

    • Sainsburys full year earnings and Unilever’s first quarter trading update both say the same thing, UK consumers are in for higher prices. The war in Ukraine, supply chain issues and the effects of ongoing Covid all to blame.      
    • US Dollar (DXY) Daily Price and Analysis US Q1 GDP may stall the greenback’s advance. A 20-year high nears for the US dollar. The multi-month US dollar rally continues with the greenback printing a fresh high today ahead of the first look at US Q1 GDP at 12.30 GMT. The US dollar basket (DXY) has been boosted by renewed weakness in the Euro and the Japanese Yen, as investors move from lower-yielding to higher-yielding currencies, while safe-haven flows continue to benefit the greenback. The US growth release later in the session is expected to show a sharp slowdown from the robust Q4 figure of 6.9%. The markets are currently pricing in growth of just 1% for the first three months of this year, with the slowdown mainly due to a reduction in inventory accrual over the quarter. This release is unlikely to move the greenback, unless there is a large miss or beat, as the Fed believe that 2022 US growth will be robust enough to let them tighten monetary policy sharply without damaging the economy. The latest US Core PCE data – the Fed’s preferred inflation reading – is released on Friday and this may have more effect on the US dollar than today’s GDP data. For all market moving economic data and events, see the DailyFX Calendar. The ongoing US dollar rally has been aided by weakness across a range of G7 currencies including the Euro, the Japanese Yen, and the British Pound. The Euro continues to battle with lowly growth expectations, exacerbated by energy concerns, the British Pound is mired by weak economic data, while the Japanese Yen is in freefall as the BoJ continues with its ultra-loose monetary policy.   The US dollar continues to press higher and looks set to break above 103.96, the March 2020 high. Above here the US dollar would be back at levels last seen nearly two decades ago. The March resistance will likely hold in the short-term, especially with month-end portfolio rebalancing at the end of the week, but US dollar strength is set to continue in the months ahead. USDOLLAR (DXY) WEEKLY PRICE CHART – APRIL 28, 2022 {{THE_FUNDAMENTALS_OF_BREAKOUT_TRADING}} What is your view on the US Dollar – bullish or bearish?   Apr 28, 2022 | DailyFX Nick Cawley, Strategist
    • While Tesla has nothing directly to do with Elon Musk buying Twitter - TSLA stock closed down 12% on news that Musk may have to sell stock and use other holdings to stand against the loan to finalise the purchase of the social media giant.        
×
×
  • Create New...