Indicator won't update on new bar. - page 2

 
expdal3:

Hi @William Roeder

I bump into this issue where my custom Indicator work fine when attached on the chart but not in strategy tester (i.e. the indicator just stop at the prev_calculated bar which is the starting time of the testing period). I follow your guide above to computing the 'limit' of the loop but seems not avail. Can you please have a look, thank

Hi @William Roeder 

after I SetIndexBuffer the array MADiff_array then the indicator working. I use ArraySetAsIndex for this before and the array seemed to be flipped backward. I am not sure how it happen as I have followed clearly the MQL4 documentation as MADiff array is initially intended  to be non-visible buffer (run at the back). Can you help explain why ArraySetAsIndex not worked in this case.

Thanks,

Andre

 
expdal3: the indicator just stop at the prev_calculated bar which is the starting time of the testing period). I follow your guide above to computing the 'limit' of the loop but seems not avail.
   int lookback = MathMax(InpMAMethod1,InpMAMethod2);
   int limit =Bars-1-MathMax(lookback, prev_calculated);
⋮
//--- return value of prev_calculated for next call
   return(rates_total);

No, you didn't follow it exactly. You return rates_total, therefor the next tick you compute limit = Bars - 1 - rates_total (-1) and you do nothing. Look at #9 closer.

 
expdal3: I use ArraySetAsIndex for this before and the array seemed to be flipped backward.
  1. There is no such thing as ArraySetAsIndex.
  2. Buffers default to asSeries. Other arrays should be set the same.
  3. Why are you resizing your MADiff_array each bar? Move it outside your for loop with the others.
 
William Roeder:
  1. There is no such thing as ArraySetAsIndex.
  2. Buffers default to asSeries. Other arrays should be set the same.
  3. Why are you resizing your MADiff_array each bar? Move it outside your for loop with the others.

@William Roeder: you sharp eyes are amazing. Silly mistake like this is really hard to detect. I have fixed those points as you advised and now the indicator has worked fine.

I enclosed here the revamped version which I introduce additional arrays buffer (take back those not required to be exported to other program) to collect the cross direction and time of the cross.

Thank you again.

Andre

Files:
MaRS.mq4  14 kb
 

i seem to have the exact same problem with a code i downloaded (it just doesn't create new "candles") i really dont know mql5 coding (its so odely specific) can someone please tell me what's wrong, thx


code:

//+------------------------------------------------------------------+
//|                                           Bollinger bands %b.mq5 |
//|                                   Copyright 2014, mohsen khashei |
//|                                               mkhashei@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, mohsen khashei"
#property link      "mkhashei@gmail.com"
#property version   "1.10"
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Bollinger bands %b"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrYellow
#property indicator_style1  STYLE_SOLID
#property indicator_level1 0.0
#property indicator_level2 0.5
#property indicator_level3 1.0
#property indicator_minimum -0.3
#property indicator_maximum 1.3
#property indicator_width1  4

//---- input parameters
input int    BBPeriod=4;        //Period
input int    BBShift=0;         // Shift
input double StdDeviation=2.3;  //Standard Deviation
input ENUM_APPLIED_PRICE appliedprc=PRICE_CLOSE; //Applied Price
//--- indicator buffers
double         UpperBuffer[];
double         LowerBuffer[];
double         MiddleBuffer[];
double         BLGBuffer[];
int    bbhandle;


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[])
  {
//---
   ArraySetAsSeries(close,true);
   if(BarsCalculated(bbhandle)<rates_total) return(0);
   if(CopyBuffer(bbhandle,0,0,rates_total,MiddleBuffer)<=0) return (0);
   if(CopyBuffer(bbhandle,1,0,rates_total,UpperBuffer)<=0) return (0);
   if(CopyBuffer(bbhandle,2,0,rates_total,LowerBuffer)<=0) return (0);
  
   int pos=prev_calculated-1;
   if(pos<=0) pos=0;
   for(int i=pos; i<=rates_total-(BBPeriod+BBShift+1); i++)
     {
    
     BLGBuffer[i]=((close[i]-LowerBuffer[i])/(UpperBuffer[i]-LowerBuffer[i]));

     }
   return(rates_total);
  }
  
  
  
  //+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,BLGBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,MiddleBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(2,UpperBuffer ,INDICATOR_CALCULATIONS);
   SetIndexBuffer(3,LowerBuffer ,INDICATOR_CALCULATIONS);
   ArraySetAsSeries(BLGBuffer,true);
   ArraySetAsSeries(MiddleBuffer,true);
   ArraySetAsSeries(UpperBuffer,true);
   ArraySetAsSeries(LowerBuffer,true);
    if(Bars(_Symbol,_Period)<=60)
  {
  Alert("We have less than 60 bars for Indicator exited now!!");
  return (-1);
  
  }
   bbhandle=iBands(NULL,0,BBPeriod,BBShift,StdDeviation,appliedprc);
    if(bbhandle<=0){
  Alert("Can not create handle ",GetLastError(),"!!");
  return (-1);
  }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
  
//+------------------------------------------------------------------+
 
john tanton:

i seem to have the exact same problem with a code i downloaded (it just doesn't create new "candles") i really dont know mql5 coding (its so odely specific) can someone please tell me what's wrong, thx


code:

Why have you posted in the MQL4 section when the code is MQL5????

Please repost in the correct section and delete this post.