are buffers needs refresh ?

 

I run an indicator and it shows a buffer in the past market.. which is correct but the problem starts here that when I want to run the buffer in live of chart.. it detects correctly but when it wants to show the running buffer.. The new values of the buffer are not connected to the continuation of the buffer.. My buffer type is draw_setion.



pleas check picture 

Files:
xfbd.PNG  49 kb
 
Have you set the PlotIndexSetDouble(plot#,EMPTY_VALUE,0.0) for the section lines ? (i may be wrong)
 
Lorentzos Roussos #:
Have you set the PlotIndexSetDouble(plot#,EMPTY_VALUE,0.0) for the section lines ? (i may be wrong)

thank you soooooo muuuuuucchhh .

its work

but can you explane more about this (  PlotIndexSetDouble(plot#,EMPTY_VALUE,0.0)  ) ..that way its work ? 

 
Lorentzos Roussos #: Have you set the PlotIndexSetDouble(plot#,EMPTY_VALUE,0.0) for the section lines ? (i may be wrong)
This is wrong. You meant:
PlotIndexSetDouble(plot#,PLOT_EMPTY_VALUE,0.0)
 
Mosy D.m #:

thank you soooooo muuuuuucchhh .

its work

but can you explane more about this (  PlotIndexSetDouble(plot#,EMPTY_VALUE,0.0)  ) ..that way its work ? 

Anytime.

It is a value you set and when this value is met in the buffer it means there should be no drawing ,or like the documentation says :

Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Drawing Styles
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Drawing Styles
  • www.mql5.com
Drawing Styles - Indicator Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Lorentzos Roussos #:

Anytime.

It is a value you set and when this value is met in the buffer it means there should be no drawing ,or like the documentation says :

but why its work currectly in past and not work currectly in live ( before i add "  PlotIndexSetDouble  " item) ?

 
Mosy D.m #:

but why its work currectly in past and not work currectly in live ( before i add "  PlotIndexSetDouble  " item) ?

I cannot answer that unfortunately . Were you setting the value to 0.0 at the start of the calculation inside the loop ? or did you loop up to rates_total-2 (only when new bars form)

 
Lorentzos Roussos #:

I cannot answer that unfortunately . Were you setting the value to 0.0 at the start of the calculation inside the loop ? or did you loop up to rates_total-2 (only when new bars form)

both 

past and live 

 
Mosy D.m #:

both 

past and live 

Hmm . i created a test case . In the test case the past is showing up wrong too when "Set PlotEmptyValue ?" is false 

Maybe you can compare and see what the difference is 

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots   2
//--- plot Highs
#property indicator_label1  "Highs"
#property indicator_type1   DRAW_SECTION
#property indicator_color1  clrChartreuse
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Lows
#property indicator_label2  "Lows"
#property indicator_type2   DRAW_SECTION
#property indicator_color2  clrFuchsia
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
input bool set_plot_empty_value=false;//Set PlotEmptyValue ?'
//let's do a simple one when new high reset low and link to previous high
//                      when new low reset high and link to previous low
//--- indicator buffers
double         Highs[];//these are the sections 
double         Lows[];
double         lastHigh[];
double         lastLow[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Highs,INDICATOR_DATA);
   SetIndexBuffer(1,Lows,INDICATOR_DATA);
   SetIndexBuffer(2,lastHigh,INDICATOR_DATA);
   SetIndexBuffer(3,lastLow,INDICATOR_DATA);
   if(set_plot_empty_value){
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
   }
   PlotIndexSetInteger(2,PLOT_DRAW_TYPE,DRAW_NONE);
   PlotIndexSetInteger(3,PLOT_DRAW_TYPE,DRAW_NONE);
//---
   return(INIT_SUCCEEDED);
  }
void mrResetto(){
//in the city of compton keep it rocking we keep it rocking 
  //when this is on let's also set the values to 0.0 for the test
  if(set_plot_empty_value){
  ArrayFill(Highs,0,ArraySize(Highs),0.0);
  ArrayFill(Lows,0,ArraySize(Lows),0.0);
  }
ArrayFill(lastHigh,0,ArraySize(lastHigh),0.0);
ArrayFill(lastLow,0,ArraySize(lastLow),0.0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---
  int from=MathMax(0,prev_calculated-1);
  if(from==0)
    {
    //reset
      mrResetto();
    //let's throw the first last high and last low  
      lastHigh[0]=high[0];
      lastLow[0]=low[0];
      from=1;
    }
    //let's ignore the live bar for now
  for(int i=from;i<rates_total-1;i++)
  {
  //propagate the previous high 
    lastHigh[i]=lastHigh[i-1];
    lastLow[i]=lastLow[i-1];
  //if new high  
    if(high[i]>lastHigh[i]){
    //link the section : does it happen automatically ? 
      Highs[i]=high[i];
      lastLow[i]=low[i];
      lastHigh[i]=high[i];
    }
  //if new low 
    if(low[i]<lastLow[i]){
    //link the section 
      Lows[i]=low[i];
      lastLow[i]=low[i];
      lastHigh[i]=high[i];
    }
  }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Reason: