Know sure thing indicator bug HELP please kst

 

hello good day friends

please can you help

this kst indicator not working:

  • when a new candle occur, my personnal indicator don't update to new value, it seems NULL

so i have to click an other Interval unit to refresh the indicator :(

  • dont see input for weight of each part ? :(

T H A N K S

Files:
kstdct.mq4  6 kb
 
lerecidiviste: don't update to new value, it seems NULL
  1. Not NULL, zero
    SetIndexEmptyValue(4,0.0);
    SetIndexEmptyValue(5,0.0);

  2.    if(counted_bars > 0)
           counted_bars--;
    Remove. Contradictory information on IndicatorCounted() - MQL4 forum

  3. iClose(NULL, 0, i);
    Why use a function call when a simple Close[i] is sufficient.
  4.    limit  = Bars - counted_bars - 1;
       limit1 = Bars - counted_bars - RPeriod1;//w
       limit2 = Bars - counted_bars - RPeriod2;//x
       limit3 = Bars - counted_bars - RPeriod3;//y
       limit4 = Bars - counted_bars - RPeriod4;//z
    
    This is completely wrong. On a new bar counted bars=Bars-1, so limit3 = Bars-(Bars-1)-RPeriod = 1-RPeriod which is less than zero - it wont calculate. Also you're limit1 is used with iMAOnArray(RateOfChange,Bars,MPeriod1.. MPeriod1 != RPeriod1
    //   if(counted_bars > 0)
    //       counted_bars--;
        int lookBackR1  = RPeriod1,
            lookBackM1  = MPeriod1+lookBackR1,
            lookBackR2  = RPeriod2,
            lookBackM2  = MPeriod2+lookBackR2,
            lookBackR3  = RPeriod3,
            lookBackM3  = MPeriod3+lookBackR3,
            lookBackR4  = RPeriod4,
            lookBackM4  = MPeriod4+lookBackR4,
            lookBackKST = MathMaxI(MathMaxI(lookBackM1,lookBackM2)
                                  ,MathMaxI(lookBackM3,lookBackM4)),
            lookBackMA  = per_MA_KST   +lookBackKST;
            lookBackMA21= per_MA_KST_21+lookBackKST;
        limit1 = Bars - MathMaxI(counted_bars , lookBackR1);
        limit1A= Bars - MathMaxI(counted_bars , lookBackM1);
        limit2 = Bars - MathMaxI(counted_bars , lookBackR2);
        limit2A= Bars - MathMaxI(counted_bars , lookBackM2);
        limit3 = Bars - MathMaxI(counted_bars , lookBackR3);
        limit3A= Bars - MathMaxI(counted_bars , lookBackM3);
        limit4 = Bars - MathMaxI(counted_bars , lookBackR4);
        limit4A= Bars - MathMaxI(counted_bars , lookBackM4);
        limit  = Bars - MathMaxI(counted_bars , lookBackKST);
        limitA = Bars - MathMaxI(counted_bars , lookBackMA);
        limitB = Bars - MathMaxI(counted_bars , lookBackMA21);
    :
       for(int i = 0; i < limit1; i++) // Always count down (BETTER) int i=limit1-1; i>=0; i--)
         {
           CurrentClose = iClose(NULL, 0, i);
           PrevClose = iClose(NULL, 0, i + RPeriod1);
           :
       for( i = 0; i < limit1A; i++) ROCEMA1[i]=iMAOnArray(RateOfChange,Bars,MPeriod1,0,MODE_EMA,i);
    :
       for( i = 0; i < limit2A; i++) ROCEMA2[i]=iMAOnArray(RateOfChange,Bars,MPeriod2,0,MODE_EMA,i);
    :
       for( i = 0; i < limit3A; i++) ROCEMA3[i]=iMAOnArray(RateOfChange,Bars,MPeriod3,0,MODE_EMA,i);
    :
       for( i = 0; i < limit4A; i++) ROCEMA4[i]=iMAOnArray(RateOfChange,Bars,MPeriod4,0,MODE_EMA,i);
    :
       for( i = 0; i < limitA; i++) MA_KST[i]=iMAOnArray(KST,Bars,per_MA_KST,0,MODE_EMA,i);
       for( i = 0; i < limitB; i++) MA_KST_21[i]=iMAOnArray(KST,Bars,per_MA_KST_21,0,MODE_EMA,i);
    /////////////////
    int     MathMaxI(int a, int b){
                            if(a>b) return(a);              return(b);             }