IF I'm wrong Please correct me.

 

Hi All,


I'm trying to write a Alert condition as it showing in the image.


I wrote the following code for that condition .


Is it right because I get the alert In the candle 1??? while need it the alert in candle 0




   double MA_0 = iMA(NULL,0,MaPeriod,0,MA_Method,MA_Price,0);// bar 0
   double MA_1 = iMA(NULL,0,MaPeriod,0,MA_Method,MA_Price,1);// bar 1
   double MA_2 = iMA(NULL,0,MaPeriod,0,MA_Method,MA_Price,2);// bar 2

   double CrossDown = Close[2] > MA_2 && Close[1] < MA_1 && Close[0] < Close[1] && Volume[0] ==1;

         static datetime MostRecentBarStart=0;
         if (Time[0] != MostRecentBarStart && CrossDown )
         
         {
                 MostRecentBarStart = Time[0];
                  Alert("Close Down : "+ Symbol(), " ");
         }

 
 double CrossDown = Close[2] > MA_2 && Close[1] < MA_1 && Close[0] < Close[1] && Volume[0] ==1;
  1. Bars is unreliable (a refresh/reconnect can change number of bars on chart) volume is unreliable (miss ticks) Always use time. New candle - MQL4 forum
  2. You are only looking at the start of a new bar.
 

Ok I will remove that , what about other code is it ok??


Thanks