Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 5/13/2005(UTC) Posts: 715 Location: Midwest, USA
Was thanked: 1 time(s) in 1 post(s)
|
After making a few assumptions, here is some code: Code:{_Test}{ INPUT }Periods:=input("Periods: ",5,50,20);
{ CALC }Bmid:=mov(C,Periods,S);Btop:=Bmid+(2*stdev(C,Periods));Bbot:=Bmid-(2*stdev(C,Periods));
{ BUY }Entry:=cross(MACD(),Mov(MACD(),9,E)); { MACD }
TrailingStop:=if(HIGH>Btop,Bmid,Bbot);
{ LATCH - Store value of stop }Latch:=If(PREV=0, { no trade }If(Entry,Bbot,0), { Initial Stop }If(LOW<PREV,0, { stop hit }Max(PREV,TrailingStop) { raise stop }));
{ REMOVE REDUNDANCY }Entry:=Alert(Latch=0,2)*(Latch>0) or cum(Latch>0)=1;Exit:=Alert(Latch,2)*(Latch=0);Signal:=Entry-Exit;Season:=If(Latch>0,1,-1);
{ PLOT - Advance visually. Style-DOT Weight-3}ValueWhen(1,Ref(Latch,-1)>0,Ref(Latch,-1));
A simple visual:
Some test results:
|