Re: Reposted for RCM

  •  02-20-2006, 7:47

    Re: Reposted for RCM

    RCM-

    I think I'm confusing myself and you too... I'm only a novice code writer. What I had in mind was to plot a weekly close and calculate the ATR based on that. I suppose that it can be done in different ways, though. The ATR Chandelier Exit code above adds a bit of simplicity to it, but it still isn't simple. BTW, that code is not complete, it lacks the copyright, date, and source availability that was originally included by the author Jose Silva. Also, there have been updates to that code. Apparently, copyright violation is just another thing that doesn't weigh on the wicked; but, I digress.

    Code:
    {Note: original concepts by Jose Silva. Avail: www.metastocktools.com}
    {User Inputs }
    pds:=Input("ATR periods",1,252,10);

    { Weekly SMA }
    EOW:=Cum(1)=LastValue(Cum(1));
    { Reference EOW signals }
    WkEnd:=EOW OR FmlVar("Week's true Start & End","WEEKEND");
    { Week's Close }
    WkCl:=ValueWhen(1,WkEnd,C);
    WkCl:=ValueWhen(1,WkCl>0,WkCl);
    { Weekly SMA }
    z:=Cum(WkEnd*WkCl);
    WkSma:=(z-ValueWhen(2,WkEnd,z));

    { ATR Trailing Stop }
    StLong:=HHV(WkSma-2.5*Mov(ATR(1),pds,E),21);
    StShort:=LLV(WkSma+2.5*Mov(ATR(1),pds,E),21);
    stopLong:=If(WkSma<PREV,StLong,Max(StLong,PREV));
    stopShort:=If(WkSma>PREV,StShort,Min(StShort,PREV));
    { Trade flags/signals }
    In:=Cross(WkSma,Ref(stopShort,-1));
    Out:=Cross(Ref(stopLong,-1),WkSma);
    Init:=Cum(IsDefined(In+Out))=1;
    x:=ValueWhen(1,In-Out<>0 OR Init,In-Out);
    long:=x=1 AND (Alert(x<>1,2) OR Init);
    short:=x=-1 AND (Alert(x<>-1,2) OR Init);
    signals:=long-short;
    flag:=ValueWhen(1,signals<>0 OR Init,signals);
    { Switch between Long/Short stops }
    stop:=Ref(If(flag=1,stopLong,stopShort),-1);

    { Plot }
    stop; If(C>=stop,1,-1)


    This is sort of what I had in mind (ditching the previous P theory). It has a problem using the ATR(1) reference, I think. Maybe you can look at this and adapt it to what you have in mind. If not, it will probably take a better coder than me to take you to the finish line.

    p.s. Be sure to check out Roy Larsen's work on multi-timeframe indicators, too. Avail: http://www.metastocktips.co.nz/other_formulas.html
    Traders' Consortium
View Complete Thread