How corretly call object line value for breakout entry condition

To add comments, please log in or register
Aung Swar
96
Aung Swar  

I want help from some experience coders in Object line breakout entry EA.

Can someone help me.

I coded highest and lowest line on chart


int highestcandle = iHighest(Symbol(),0 ,MODE_HIGH,50,2);
     
     ObjectDelete("HLine");
     ObjectCreate("HLine",OBJ_HLINE,0,Time[0],High[highestcandle]);
    double  LineValHigh  = NormalizeDouble(ObjectGetValueByShift("HLine",2),Digits );
     
     int lowestcandle =iLowest(Symbol(), 0, MODE_LOW, 50, 2);
     ObjectDelete("LLine");
     ObjectCreate("LLine",OBJ_HLINE,0,Time[0],Low[lowestcandle]);
    double LineValLow  = NormalizeDouble(ObjectGetValueByShift("LLine",2),Digits );

get this two lines


want to open buy order when price breakout Highest line and sell when price breakout lowest line

here is codes

if ( OrdersTotal() == 0 ){
       if (New_Bar())
       
           {
          if (Close[1] >LineValHigh ) //if price above a line
             {
              int ticket = OrderSend ( Symbol(),OP_BUY ,SetLotSize(), Ask, 3, Ask-StopLoss*Point,Ask+TakeProfit*Point,MagicNumber,"Set by system");
              if ( ticket < 0 )
              {
                Alert("Error");
              }
             }
           }
           else
           {
             if (Close[1] <LineValLow ) //if price below b line
             {
               int ticket = OrderSend ( Symbol(),OP_SELL ,SetLotSize() , Bid, 3, Bid+StopLoss*Point,Bid-TakeProfit*Point,MagicNumber,"Set by system");
              if ( ticket < 0 )
              {
                Alert("Error");
              }
           }
          }
          
          
    bool New_Bar() {
   static datetime New_Time=0; // New_Time = 0 when New_Bar() is first called
   if(New_Time!=Time[0]){      // If New_Time is not the same as the time of the current bar's open, this is a new bar
      New_Time=Time[0];        // Assign New_Time as time of current bar's open
      return(true);
   }
   return(false);
   }
   

but order not open as I coded and open badly as compiler not work . As shown in picture , orders are open between lines. Can someone help this problem.

I want to know my error in this case because I learned mql4 alot of but still not get right concept.

Marco vd Heijden
Moderator
12407
Marco vd Heijden  
if(Bid > High[iHighest(Symbol(),0 ,MODE_HIGH,50,2)])
 {
   int ticket = OrderSend ( Symbol(),OP_BUY ,SetLotSize(), Ask, 3, Ask-StopLoss*Point,Ask+TakeProfit*Point,MagicNumber,"Set by system");

   if ( ticket < 0 )
       {
         Alert("Error");
       }  
 }
Aung Swar
96
Aung Swar  
Marco vd Heijden:

Hi thanks for comment but still not open correctly at breakout point .orders open early before breakout point .This is why theory not apply in reality. Need to add another filters?

To add comments, please log in or register