Download MetaTrader 5
To add comments, please log in or register
Publish your programs in the Market. Make money with your knowledge!
ale
68
ale 2015.07.09 08:58 

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?

honest_knave
969
honest_knave 2015.07.09 09:05  
You're going to have to show some code if you want help...
ale
68
ale 2015.07.09 09:14  
honest_knave:
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;
}
honest_knave
969
honest_knave 2015.07.09 09:55  

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);
  }

 

/
To add comments, please log in or register