Need help on developing arrow alert custom indicator

 

Dear All,

I develope an arrow alert custom indicator, but there is an issue

First I explained the rules of this custom indicator :

On TF H1

- Buy, when previous candle Close is higher than 2nd candle High on the day

- Sell, when previous candle Close is lower than 2nd candle Low on the day

The issue is I can't prevent the show of next alert after the 2nd candle nearest alert was painted

Only need 1 alert as the nearest to the 2nd candle

Pictures :

BUY

buy

SELL

SELL

Thank you

 
   static datetime timeDay1,timeDay2;
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(5000-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation   
      //Indicator Buffer 1
      
      if(timeDay1!=iTime(_Symbol,PERIOD_D1,iBarShift(_Symbol,PERIOD_D1,time[i])) && close[1+i] > high[iBar] //Candlestick Close > Candlestick High
        )
        {
         Buffer1[i] = low[i]; //Set indicator value at Candlestick Low
         timeDay1=iTime(_Symbol,PERIOD_D1,iBarShift(_Symbol,PERIOD_D1,time[i]));
         timeDay2=0;
         if(i == 1 && time[1] != time_alert) myAlert("indicator", "Buy"); //Alert on next bar open
         time_alert = time[1];
        }
      else
        {
         Buffer1[i] = 0;
        }
      //Indicator Buffer 2
      if(timeDay2!=iTime(_Symbol,PERIOD_D1,iBarShift(_Symbol,PERIOD_D1,time[i])) && close[1+i] < low[iBar] //Candlestick Close < Candlestick Low
        )
        {
         Buffer2[i] = high[i]; //Set indicator value at Candlestick High
         timeDay2=iTime(_Symbol,PERIOD_D1,iBarShift(_Symbol,PERIOD_D1,time[i]));
         timeDay1=0;
         if(i == 1 && time[1] != time_alert) myAlert("indicator", "Sell"); //Alert on next bar open
         time_alert = time[1];
        }
      else
        {
         Buffer2[i] = 0;
        }
     }
 
Ernst Van Der Merwe:

Thank you Sir

I will aplly it

 

where I should place that codes?

meet many errors on placing

thank you

 
Krisma Freddy:

where I should place that codes?

meet many errors on placing

thank you

Change the TimeFrame input to change the frequency of arrows.