Check price every tick and open Order when certain price is reached

 

Guys I have no ideia why I cant make this simple operation in my  EA code work.

I first tried to compare the doubles of both prices but I realized that there is something tricky about comparing doubles so I decided to apply some math instead but still cant make it work. 


Please Help.


double H3 = ((yesterday_high - yesterday_low)* D3) + yesterday_close;

double L3 = yesterday_close - ((yesterday_high - yesterday_low)*(D3))



void OnTick()
  {



if(Close[0] - L3 == 0){

Print("L3 price hit");

   Sleep(60000); 
   
    if(Close[0] - L3 > 0 && !L3TradeOpen){
            
        TicketBuyOrder = OrderSend(Symbol(),OP_BUY,CalculateLotSize(),Bid,Slippage,Bid-70*Point,0,"My order BUY",magicNumber,0,clrGreen);         
        Print("Buy Order:" + IntegerToString(TicketBuyOrder));
        L3TradeOpen = true;
        magicNumber++;
}
   else L3TradeOpen = false;
       
}  
   
if(Close[0] - H3 == 0) {

 Print("H3 price hit");
   
   Sleep(60000); 
   
    if(Close[0] - H3 < 0 && !H3TradeOpen){
     
        TicketSellOrder = OrderSend(Symbol(),OP_SELL,CalculateLotSize(),Ask,Slippage,Ask + 70*Point,0,"My order SELL",magicNumber,0,clrRed);            
        Print("Sell Order:" + IntegerToString(TicketSellOrder));
        H3TradeOpen = true;
        magicNumber++;
}
   else H3TradeOpen = false;
    

}
}

 
angomes:

I first tried to compare the doubles of both prices but I realized that there is something tricky about comparing doubles so I decided to apply some math instead but still cant make it work. 

and yet you are still comparing Doubles.

if(Close[0] - L3 == 0){
} 
   
if(Close[0] - H3 == 0) {
} 

If you want to determine if a level is hit, you first need to know whether price starts above or below the level.

If it starts above the level, check for if price is <= the level, then you will know that price has hit or crossed the level.

 
When comparing doubles you should avoid using the "==" operator. Only use ">" or "<" operators.
Reason: