You're going to have to show some code if you want help...
honest_knave:
You're going to have to show some code if you want help...
You're going to have to show some code if you want help...
The core of the code is trivial (I skipped the loop over all the historical candles)
int OnCalculate(...) { // this is the value to be plotted // it changes constantly because it is calculated using the close of the // previous 9 candles plus the current one double target_price = TargetPrice(...); // I want the same value plotted in the 10 candles used to calculate the // price for (int i = 0; i < 10; i++) { TargetPriceBuffer[i] = target_price; } return rates_total; }
Either I have misunderstood what you want or there is something else in the rest of your code that is important to this problem.
For example, load this indicator onto any chart. The last 10 bars will always form a straight line at the current bar's high. Anything older than 10 bars will hold its value:
#property indicator_chart_window double TargetPriceBuffer[]; int OnInit() { SetIndexBuffer(0,TargetPriceBuffer); SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,2,clrWhite); 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[]) { double target_price = High[0]; for (int i = 0; i < 10; i++) { TargetPriceBuffer[i] = target_price; } return(rates_total); }

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
In my indicator I change in OnCalculate the values of the buffer of the last 10 candles. MT4 always shows the old values values for the past candles, not the new values; only the value of the current candle is constantly refreshed. I added a call to WindowRedraw() after the buffer is updated but this does not solve the problem.
How can I tell MT4 to read again the values of the buffer in the past candles?