icustom problems

 

Hi all,

Recently I have started learning to make custom indicators. I figured that a good learning project would be to make the kaufman adaptive moving average. With the help from the
indicators I found in the the code base and the documentation on this subject I have made the attached indicator. At first sight it seemd to work as it should, but when it is attached to a live chart
or to a chart while testing in visal mode, it doesn't seem to draw correctly.. It does draw, but when the properties window is openend and closed (without changing any parameter) the indicator values on the newly drawn bars
change to, what I believe are the correct values. It seems the values on the historical bars are drawn correctly but the values for newly formed bars are not. At this point I am kind of stuck. I have read
again the documentation on IndicatorCounted ( i think it might have to do with that) but after looking it over and over, I fail to spot the problem.

It would be greatly appreciated if someone could have a look and clear this up for me.

Files:
 
  1. remove your array resizes and add those arrays as buffers in init.
  2. or resize them correctly.
    bool    ResizeBuffer(double& buffer[], int size){
        if (ArraySize(buffer) != size){
            ArraySetAsSeries(buffer, false);    // Shift values B[2]=B[1]; B[1]=B[0]
            if (ArrayResize(buffer, size) <= 0){
                trading.disabled    = "ArrayResize [1] failed: "+GetLastError()
                                    + " Trading disabled.";
                Alert(trading.disabled);    Print(trading.disabled);
                return(false);  }
            ArraySetAsSeries(buffer, true);
        }
        return(true);
    }
    
  3. You have no problem with iCustom - next time use a better title.
 
Also it might help you to look over the code for that kaufman indicator (KAMA) in the codebase
 
SDC:
Also it might help you to look over the code for that kaufman indicator (KAMA) in the codebase

Thanks guys. I will try putting my arrays as buffers.

@ WHRoeder, I'm not sure that I understand why ArraySetAsSeries is set to false and back again to true in the above function you provided. Could you please explain?
thanks!

 
  1. Series set to true

    ElementsABCD
    Index3210

    Series set to false

    ElementsABCD
    Index0
    1
    2
    3

    Resized

    ElementsABCD?
    Index0
    1
    2
    3
    4

    Series set to true

    ElementsABCD?
    Index4
    3
    2
    1
    0

    Elements Shifted.


  2. Series set to true

    ElementsABCD
    Index3210

    Resized

    Elements?
    A
    B
    C
    D
    Index4
    3
    2
    1
    0

    Elements not shifted.
 
WHRoeder:
  1. Series set to true

    ElementsABCD
    Index3210

    Series set to false

    ElementsABCD
    Index0
    1
    2
    3

    Resized

    ElementsABCD?
    Index0
    1
    2
    3
    4

    Series set to true

    ElementsABCD?
    Index4
    3
    2
    1
    0

    Elements Shifted.


  2. Series set to true

    ElementsABCD
    Index3210

    Resized

    Elements?
    A
    B
    C
    D
    Index4
    3
    2
    1
    0

    Elements not shifted.

Thanks a lot! Very useful indeed.