Search code examples
mql4

Why Buy order is not placed when calculated Stoploss and Take profit are used


I have a simple BUY order that, when the Take Profit and Stoploss are in points (ie: Ask+10*_Point), operates correctly. But when I change the take profit and stop loss from points to my own calculated values (CL_OP), the BUY order is not placing trades. How can I solve the issue:

    input int _Hour =16;
    input int _Minute =30;
    
    
  
    bool NewBar()
      {
       static datetime OldTime = 0;
    
       if(OldTime < Time[0])
         {
          OldTime = Time[0];
          return(true);
         }
       else
         {
          return(false);
         }
      }
    
   
    void OnTick()
      {
         int Hour_Int = Hour();
         int Minute_Int = Minute();
         
       double CL_OP = (Close[1] - Open[1]);
       bool LastBearHiLoEngulf = (Close[1] < Open[1]  &&  High[1] > High[2] && Low[1] < Low[2] );
         
      if(NewBar())
      if(OrdersTotal()==0)
      
      // Apply signals on Buy opportunities  
      if( Hour_Int == _Hour && Minute_Int == _Minute && LastBearHiLoEngulf == TRUE)
               {
      
      int buyticket = OrderSend
      
      (
                                   Symbol(),                                 // all symbols
                                   OP_BUY,                                   // Buy without delay
                                   1,                                        // 1 Microlots
                                   Ask,                                      // for market price
                                   3,                                        // 3 pips slippage
                                   Ask - CL_OP,                              // Stop Loss -  1000*_Point
                                   Ask + CL_OP  ,                              // Take profitworks with 100*_Point
                                   "Buy LastBearHiLoEngulf Target:      ",      // comment
                                   144,                                      // Magic number
                                   0,                                        // no experiation day
                                   Green                                     // draw green arrow  
                                   );
              }

  }

Solution

  • double CL_OP = (Close[1] - Open[1]);

    CL_OP is not a normal price to open trade. Actually, it is the Size of the Candle 1!

    It should be something like this:

    double CL_OP = Close[1] + (Close[1] - Open[1]);