As you can see, there are two parts:
1. named //new bar - draw indicator on new bar if xyz - in real time, normal work
Forget point 1. I just wont to print signal on every candle where second previous candle was down. Not in real time but for all in history of a chart.
if (Close[i]<Open[i]) draw_labe(code_120_down,color_120_down,i); //works OK, prints signals
if (Close[i+1]<Open[i+1]) draw_labe(code_120_down,color_120_down,i); //doesn't work
Let us simplify the code:
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time,
const double &open,
const double &high,
const double &low,
const double &close,
const long &tick_volume,
const long &volume,
const int &spread)
void draw_labe(int code,color col,int f)
It works. We verify the second bar. And draw on the second bar.
It works but not as it should.
1. it draws on bar [i+2] not on the bar [i]. In other words we wont: "Show on bar [i] if bar [i+2] was down".
2. it draws in present time not on the history.
The goal is to click compile on the clear chart and in that moment have a chart full of indicators like this
(the picture does not show our test conditions, it ilustrate the effect of calculations on history made in the moment of compilation)
OK, but what about real formulas when we calculate together [i+1] [i+2] [i+3] ?
My oryginal code draw labels on real time (although I am not sure that calculate correct - another problem)
Now the problem is that my code draw on historical but only when condition is if (Close[i]<Open[i])
Does not draw when if (Close[i+2]<Open[i+2])
Does not draw when if (Close<Open)
That is the point.
Your indicators creates a lot of objects. It is better to go to DRAW_ARROW.