Straddle Order problems

 

I have a problem with straddle orders. The Buy stop places orders but the sell stop does sometimes. I have a condition on the straddle orders that it will try to place the orders until both buystop

and sell stop are placed.


if( (Hour() == start)&&((buyEU == false)&&(sellEU == false))&&(OCOsetEU == false)&&(QualifiedMarketEU == false) )
       {
       
         invalidEU = true;
         RefreshRates();
         // Carry out trading activity here
         if(OCOsetEU1 == false)
         {
         PendingPriceEU = pHighEU;
         SLEU1 = pHighEU - UsePoint*StopLoss;
         TPEU1 = pHighEU + UsePoint*TakeProfit;
         Print("Working on EURUSD1 oco");
         OTicketEU1 = OpenBuyStopOrder("EURUSD", LotSizeEU, PendingPriceEU, SLEU1 ,TPEU1, Slippage, MagicNumber, 0, "Buy Stop Order");
         
         if(OTicketEU1 > 0)OCOsetEU1 = true;
         }
  
         RefreshRates();
         // Carry out trading activity here
         if(OCOsetEU2 == false)
         {
           PendingPriceEUS = pLowEU;
         SLEU2 = pLowEU + UsePoint*StopLoss;
         TPEU2 = pLowEU - UsePoint*TakeProfit;
         Print("Working on EURUSD2 oco");
         OTicketEU2 = OpenSellStopOrder("EURUSD", LotSizeEU, PendingPriceEUS, SLEU2 ,TPEU2, Slippage, MagicNumber, 0, "Sell Stop Order");
        
          if(OTicketEU2 > 0)OCOsetEU2 = true;
         }
        if( (OCOsetEU1 == true)&&(OCOsetEU2 == true) )OCOsetEU = true;
        }
 
  1.  OTicketEU1 = OpenBuyStopOrder("EURUSD", LotSizeEU, PendingPriceEU, SLEU1 ,TPEU1, 
                                   Slippage, MagicNumber, 0, "Buy Stop Order");
     if(OTicketEU1 > 0)OCOsetEU1 = true;

    Always test return codes.

     OTicketEU1 = OpenBuyStopOrder("EURUSD", LotSizeEU, PendingPriceEU, SLEU1 ,TPEU1, 
                                   Slippage, MagicNumber, 0, "Buy Stop Order");
     if (OTicketEU1 < 0){ Alert("OrderSend failed: ", GetLastError()); return; }
     OCOsetEU1 = true;
    

  2. EA's must adjust for 4/5 digit brokers, tp, sl, AND slippage
    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){
         if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 https://www.mql5.com/en/forum/135345
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    

  3. if(OTicketEU2 > 0)OCOsetEU2 = true;
    Where do you ever set OCOsetEU2 to false?
    OCOsetEU2 = OTicketEU2 > 0;
 
WHRoeder:
  1. Always test return codes.


  2. EA's must adjust for 4/5 digit brokers, tp, sl, AND slippage
  3. Where do you ever set OCOsetEU2 to false?

The OCOsetEU2 is initialized to false before the init() function at the top
Reason: