An Amibroker formula glitch....suggestions welcome to fix

Discussion in 'Programming' started by themickey, Sep 11, 2018.

  1. I'm experimenting on a simple type volatility formula and the results I get from an exploration leaves me with numerous zeros in the results.
    Anyone know how to overcome this?
    With the lookback period set to say a fixed period of example 300 days, I still get this issue, therefore I doubt the lookback period formula is the issue.

    VT1 = Cum(Nz(DateNum()>=1160127)); // MAX LOOKBACK DATE
    VT2 = IIf(-20+(BarIndex())<VT1,-20+(BarIndex()),VT1); // ADJUSTED LOOKBACK TIME
    MA20 = MA(C,20);
    VT3 = MA20>Ref(MA20,-1); // RISING MA20
    VT4 = Sum(VT3,VT2); // SUM OF RISING MA20
    VT5 = H>MA20;
    VT6 = L>MA20;
    VT7 = L<MA20;
    VT8 = IIf(VT3,Sum(VT5,VT4),0); // SUM OF H>MA20
    VT9 = IIf(VT3,Sum(VT6,VT4),0); // SUM OF L>MA20
    VT10 = IIf(VT3,Sum(VT7,VT4),0); // SUM OF L<MA20
    Filter = 1;
  2. fan27


    Are they trailing decimal zeros? Perhaps post what you expect to get vs what you are getting.
  3. The column results are returning zero, for example, if my exploration is returning results for 500 stocks, maybe 250 of the results have been calculated and 250 of the remainder return a zero. It's early AM here now so will send a pic in a few hours time.
  4. Amibroker exploration will step through all the elements of the array within the specified range(All quotes, 1 recent bars, 1 recent day, From-to dates). The IIF statements have zero option so there are plenty of zeros in those arrays. It tough to control the output result in the Amibroker exploration. What you can do is to cut and paste into Excel spreadsheet and filter out the zeros.
  5. Approx 60% of all results show a zero result for columns VT8, VT9 & VT10.
    2018-09-12 10.58.17.jpg
    Last edited: Sep 11, 2018
  6. Seems the problem lays in the fact if current price is less than MA20 or MA20 is falling, then it wont calculate any historical result.
    fan27 likes this.
  7. Zeros can easily be filtered out in AB, no need for transposing to a seperate spreadsheet, however the overall results whichever way is inaccurate if 60% of the exploration result is missing.
  8. Fixed! Used a different approach, also modified VT2 line. :)