- 2021.08.26
- www.mql5.com
Thank you, after reading the post, I've arrived here, when the loop is written this way:
for (i = prev_calculated, i = rates_total, i++)
and these variables are printed:
Print(i, rates_total, prev_calculated);
this is the result:
i: 100853, rates_total: 100860, prev_calculated: 0
i: 100854, rates_total: 100860, prev_calculated: 0
i: 100855, rates_total: 100860, prev_calculated: 0
In this result, "i" has values while prev_calculated is zero, even after they have been assigned the same value.When the loop is written this way:
for (i = 0, i = rates_total, i++)
and the same variables are printed:
this is the result:
i: 100849, rates_total: 100853, prev_calculated: 100853
i: 100850, rates_total: 100853, prev_calculated: 100853
i: 100851, rates_total: 100853, prev_calculated: 100853
In this result prev_calculated and rates_total have the same valueTry the following ...
// Simplified logic (uncompiled, untested, simply typed out) for( int i = prev_calculated < 1 ? 0 : prev_calculated - 1; !_StopFlag && i < rates_total; i++ ) { BullishBuffer[i] = close[i] > open[ i] ? low[ i] : EMPTY_VALUE; BearishBuffer[i] = close[i] < open[ i] ? high[i] : EMPTY_VALUE; };
Also, I suggest you use the "#property" definitions to set the colour and other display properties instead of hard coding them during the OnInit().
That way they can be change by the user in the Indicator's properties panel.
Thanks for your response. The calculation is currently ongoing on the developing index.
The attached images demonstrate the up arrow initially, followed by the appearance of the down arrow shortly afterwards.
How can I ascertain the index value of a closed bar, such as the bullish one depicted in the reference image, for the code to look like this:
if(BarIsBullish) { BullishBuffer[i] = low[index of bar after closing]; } else if(BarIsBearish) { BearishBuffer[i] = high[index of bar after closing]; }
These have been modified according to your suggestions.
#property indicator_color1 InputColor1 #property indicator_color2 InputColor2 input color InputColor1 = clrGreen; input color InputColor2 = clrRed;
Thanks for your response. The calculation is currently ongoing on the developing index.
The attached images demonstrate the up arrow initially, followed by the appearance of the down arrow shortly afterwards.
How can I ascertain the index value of a closed bar, such as the bullish one depicted in the reference image, for the code to look like this:
These have been modified according to your suggestions.
to work with closed bar you need reference the bar [i-1]
if(BarIsBullish) { BullishBuffer[i-1] = low[i-1]; } else if(BarIsBearish) { BearishBuffer[i-1] = high[i-1]; }
And for this need at least 2 bars, so
for( int i = prev_calculated < 2 ? 1 : prev_calculated - 1; !_StopFlag && i < rates_total; i++ )
No, you are not properly applying the suggested correction. Here is the full example, compiled and tested ...
#property indicator_chart_window #property indicator_buffers 2 #property indicator_plots 2 #property indicator_label1 "Bullish" #property indicator_color1 clrGreen #property indicator_type1 DRAW_ARROW #property indicator_label2 "Bearish" #property indicator_color2 clrRed #property indicator_type2 DRAW_ARROW double BullishBuffer[], BearishBuffer[]; int OnInit() { SetIndexBuffer( 0, BullishBuffer, INDICATOR_DATA ); SetIndexBuffer( 1, BearishBuffer, INDICATOR_DATA ); PlotIndexSetInteger( 0, PLOT_ARROW, 233 ); PlotIndexSetInteger( 1, PLOT_ARROW, 234 ); return INIT_SUCCEEDED; }; 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[] ) { for( int i = prev_calculated < 1 ? 0 : prev_calculated - 1; !_StopFlag && i < rates_total; i++ ) { BullishBuffer[i] = close[i] > open[i] ? low[ i] : EMPTY_VALUE; BearishBuffer[i] = close[i] < open[i] ? high[i] : EMPTY_VALUE; }; return rates_total; };
And the update for your most recent request ...
for( int i = prev_calculated <= 1 ? 1 : prev_calculated - 1; !_StopFlag && i < rates_total; i++ ) { BullishBuffer[i] = close[i] > open[i] ? low[ i - 1] : EMPTY_VALUE; BearishBuffer[i] = close[i] < open[i] ? high[i - 1] : EMPTY_VALUE; };
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
For instance, this indicator calculates data on the index that is currently being formed. The result is the display of upward and downward arrows if both conditions are met during the formation. Ideally, only one arrow should be displayed per bar.