EA won't place trades - "failed market sell" "invalid request"

 

My EA won't place any trades when I backtest it, just comes up with "failed market sell 0.03 GBPUSDme sl:1.40524 tp:1.40024 [invalid request]. Not sure why, it should open a buy trade when the 1H 50 EMA is above the 1H 200 EMA, the 15M 50 EMA is above the 15M 200 EMA, when there is a bullish engulfing candle or bullish pin bar, when the price is below the 5M 50 EMA and should only open a position if there are no open buy trades or if the price is below the opening price of any currently open buy trades. For sell trades, all of this should just be reversed. Been going through my code for a while but I can't see why this is happening. Any tips would be appreciated.


Thanks 

Files:
 
tebbsy96:

 "failed market sell 0.03 GBPUSDme sl:1.40524 tp:1.40024 [invalid request].

Is "GBPUSDme" the name of the financial instrument that you want to trade?

 
tebbsy96: "failed market sell 0.03 GBPUSDme sl:1.40524 tp:1.40024 [invalid request]. Not sure why, … Any tips would be appreciated.
  1. Your code
       bool IsNewBar=false;
       if(Old_Time!=New_Time[0])  
          {
          IsNewBar=true;
          }
    Simplified
       bool IsNewBar=Old_Time!=New_Time[0];

  2. Old_Time is never updated.

  3. Your code
       bool Bullish_Pin_Bar=false;
       if(p_close>p_open)
          {
          if(p_close-p_open<0.25*(p_high-p_low))
             {
             if(p_open>p_low+(0.75*(p_high-p_low)))
             Bullish_Pin_Bar=true;
             }
          }
    
    Simplified
    double range=p_high-p_low; 
      bool Bullish_Pin_Bar=  p_close>p_open
    // Redundent test ⋙⋙ && p_close-p_open < 0.25*range
                           && p_open>p_low + 0.75*range;

  4. mrequest.action=TRADE_ACTION_DEAL;
    mrequest.price=NormalizeDouble(latest_price.ask,_Digits);
    mrequest.sl=NormalizeDouble(latest_price.ask-StopLoss*_Point,_Digits);
    mrequest.tp=NormalizeDouble(latest_price.ask+TakeProfit*_Point,_Digits);
    mrequest.symbol=_Symbol;
    mrequest.volume=NormalizeDouble(Lotsize,_Digits);
    mrequest.magic=EA_Magic;
    mrequest.type=ORDER_TYPE_BUY;
    mrequest.type_filling=ORDER_FILLING_FOK;
    mrequest.deviation=50;
    OrderSend(mrequest,mresult); //--send order
    
    Don't copy and paste code. You have 8 of these; are they all correct? Make them a function and you only need to check once.

  5. You buy at the Ask and sell at the Bid.
    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using the Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
      Most brokers with variable spread widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134.

  6.       PositionGetDouble(POSITION_PRICE_OPEN);
    What do you think that does?

 
WindmillMQL:

Is "GBPUSDme" the name of the financial instrument that you want to trade?

Yes it is.
 
William Roeder:
  1. Your code
    Simplified

  2. Old_Time is never updated.

  3. Your code
    Simplified

  4. Don't copy and paste code. You have 8 of these; are they all correct? Make them a function and you only need to check once.

  5. You buy at the Ask and sell at the Bid.
    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using the Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
      Most brokers with variable spread widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134.

  6. What do you think that does?

Yeah i'll look into changing the SL and TP, thanks for the advice. 

Regarding point 6, I thought that function would return the the opening price of an open position? 

 
William Roeder:
  1. Your code
    Simplified

  2. Old_Time is never updated.

  3. Your code
    Simplified

  4. Don't copy and paste code. You have 8 of these; are they all correct? Make them a function and you only need to check once.

  5. You buy at the Ask and sell at the Bid.
    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using the Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
      Most brokers with variable spread widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134.

  6. What do you think that does?

Also, regarding point 4, I had the the wrong filling type. Thats sorted now so it is placing orders but its not placing them at the right time, something must be wrong with my entry conditions. 
 
  1. tebbsy96: Regarding point 6, I thought that function would return the the opening price of an open position? 

    Which you then throw away.

  2. tebbsy96 placing orders but its not placing them at the right time, something must be wrong with my entry conditions. 
    #2.2
 
tebbsy96:
Yes it is.
I was asking this because the error message you received is "invalid request". This could mean that the name of the symbol is incorrect, or that any of the prices you submitted are not valid.
 
William Roeder:
  1. Which you then throw away.

  2. #2.2

Yeah both of them were dumb mistakes by me. Sorted then out, thanks for the help.