Hey guys,
I have written a alert indicator. I found out that, the indicator send out alert before the candle closed. Kindly let me know which part of my code need to be amended. Thanks!
Hi dear,
The problem is here:
double ma1 =iMA(NULL,15,MAPeriod1,0,MAMethod1,PRICE_CLOSE,i+1); //6 double ma1P =iMA(NULL,15,MAPeriod1,0,MAMethod1,PRICE_CLOSE,i+2); double ma1A =iMA(NULL,15,MAPeriod1,0,MAMethod1,PRICE_CLOSE,i); double ma2 =iMA(NULL,15,MAPeriod2,0,MAMethod2,PRICE_CLOSE,i+1); //18 double ma2P =iMA(NULL,15,MAPeriod2,0,MAMethod2,PRICE_CLOSE,i+2); double ma2A =iMA(NULL,15,MAPeriod2,0,MAMethod2,PRICE_CLOSE,i); H = High[i]; L = Low[i]; C = Close[i]; O = Open[i]; H1 = High[i+1]; L1 = Low[i+1];
Your Alert is sent at current price. You have to send it at previous candle close.
So, try this:
double ma1 =iMA(NULL,15,MAPeriod1,0,MAMethod1,PRICE_CLOSE,i+2); //6 double ma1P =iMA(NULL,15,MAPeriod1,0,MAMethod1,PRICE_CLOSE,i+3); double ma1A =iMA(NULL,15,MAPeriod1,0,MAMethod1,PRICE_CLOSE,i+1); double ma2 =iMA(NULL,15,MAPeriod2,0,MAMethod2,PRICE_CLOSE,i+2); //18 double ma2P =iMA(NULL,15,MAPeriod2,0,MAMethod2,PRICE_CLOSE,i+3); double ma2A =iMA(NULL,15,MAPeriod2,0,MAMethod2,PRICE_CLOSE,i+1); H = High[i+1]; L = Low[i+1]; C = Close[i+1]; O = Open[i+1]; H1 = High[i+2]; L1 = Low[i+2];
By the way,
Why do you write this code?!!
CrossUp[i-1] = Low[i-1] - Range * 0.6;
and
CrossDown[i-1] = High[i-1] + Range * 0.6;
If you want to see the arrows on current candle, try this code:
CrossUp[i] = Low[i] - Range * 0.6;
and
CrossDown[i] = High[i] + Range * 0.6;
Regards,
Arash
limit = Bars - counted_bars; /* Range = 0; AvgRange = 0; for (int counter = i; counter <= i+9; counter++) { AvgRange = AvgRange + MathAbs(High[counter] - Low[counter]); } Range = AvgRange / 10; */ for(i=0; i <= limit; i++) { Range = 0; AvgRange = 0; for (int counter = i; counter <= i+9; counter++) { AvgRange = AvgRange + MathAbs(High[counter] - Low[counter]); } Range = AvgRange / 10;Maybe you should put this part in the next "for loop".
Hi dear,
The problem is here:
Your Alert is sent at current price. You have to send it at previous candle close.
So, try this:
By the way,
Why do you write this code?!!
and
If you want to see the arrows on current candle, try this code:
and
Regards,
Arash
Thanks Arash! Will try the code out later!
Maybe you should put this part in the next "for loop".
This is just for the arrow icon to be set within certain range. Hence, with or without loop is ok.
Hi dear,
The problem is here:
Your Alert is sent at current price. You have to send it at previous candle close.
So, try this:
By the way,
Why do you write this code?!!
and
If you want to see the arrows on current candle, try this code:
and
Regards,
Arash
Hi Arash,
For the code below, the alert that send out did not meet my below condition, do you have any idea how I should change it?
if ( (H > H1 && L > L1 && C < L1) || (H>H1 && L<L1 && C>H1))
Hi Arash,
For the code below, the alert that send out did not meet my below condition, do you have any idea how I should change it?
This condition depends on your strategy.
Did you test this condition on the chart?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey guys,
I have written a alert indicator. I found out that, the indicator send out alert before the candle closed. Kindly let me know which part of my code need to be amended. Thanks!