EMA, Cycle-Adaptive

Discussion in 'Technical Analysis' started by huss1652, May 27, 2011.

  1. huss1652

    huss1652 New Member

    Joined:
    May 27, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    I believe that converting this code could be highly beneficial to many as well as myself. Could someone please help convert this Metastock Code to Amibroker Formula Language?


    pr:=Input("ZigZag cycle reversal %",0,100,5);
    choose:=Input("EMA periods based on: [1]Cycle, [2]Cycle Avg",1,2,1);
    multi:=Input("EMA periodicity: Cycle/Avg length x",.1,100,2);
    x:=Close;
    zz:=Zig(x,pr,%);
    zzpk:=Ref(zz,-1)>zz AND Ref(zz,-1)>Ref(zz,-2);
    zztr:=Ref(zz,-1)<zz AND Ref(zz,-1)<Ref(zz,-2);
    PkTr:=zzpk OR zztr;CycleLen:=PkTr*(Ref(BarsSince(PkTr),-1)+1);
    CycleCount:=Cum(PkTr)-1;
    CycleCount:=If(CycleCount=0,.000001,CycleCount);
    CycleLenAvg:=Cum(CycleLen)/CycleCount;

    pds:=If(choose=1,ValueWhen(1,CycleLen>0 AND CycleCount>0,CycleLen),CycleLenAvg)*multi;
    Init:=CycleCount=1 AND Alert(CycleCount<1,2);
    pds:=If(pds>BarsSince(Init),BarsSince(Init),pds);
    pds:=If(pds<1,1,pds);
    Ema:=x*2/(pds+1)+PREV*(1-2/(pds+1));
    Ema;
     
Loading...

Share This Page