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)
|
So, you want to "filter" the signal -- use if the current Low-to-High range is greater than the 10-bar average. I only use the EOD version, but the following should work, or at least be close to what you want: Code:
Mult:= Input("ATR Multiplier",0.1,3,1);
Nb:= Input("NbPeriods",1,8,8);
x:= Input("Price:[1](H+L)/2 [2]Close",1,2,1);
RangePds:=Input("Range",2,250,10);
Plot:=Input("Plot 0=Signal 1=SuperTrend",0,1,0);
TruRan:= Wilders(ATR(1),Nb)*Mult;
HiLimit:=If(x=1,(H+L)/2-TruRan,C-TruRan);
LoLimit:=If(x=1,(H+L)/2+TruRan,C+TruRan);
LB:=If(HiLimit>=PREV AND HiLimit<C,HiLimit,If(C<PREV,HiLimit-0.1,PREV));
UB:=If(LoLimit<PREV AND LoLimit>C,LoLimit,If(C>PREV,LoLimit+0.1,PREV));
Trend:=If(UB>Ref(UB,-1),1,If(LB<Ref(LB,-1),-1,PREV));
Super:=If((Trend=1 AND Ref(Trend,-1)=-1) OR (Trend=1 OR Trend=0),LB,UB);
Range:=H-L;
RangeAvg:=Ref(Mov(Range,RangePds,S),-1);
Filter:=Range>RangeAvg;
Entry:=Cross(CLOSE,Super) AND Filter;
Exit:=Cross(Super,CLOSE) AND Filter;
{ REMOVE EXTRA SIGNALS, +1=Buy -1=Sell }
Signal:=Cum(IsDefined(Entry+Exit))=1; { Enough data ? }
Signal:=ValueWhen(1,Entry-Exit<>0 OR Signal,Entry); { Current }
Entry:=Signal*(Alert(Signal=0,2) OR Entry*Cum(Entry)=1); { Current or 1st }
Exit:=(Signal=0)*(Alert(Signal,2) OR Exit*Cum(Exit)=1); { Current or 1st }
Entry:=(Exit=0)*entry; { favor EXIT }
Signal:=Entry-Exit; { Signal }
Season:=ValueWhen(1,Signal<>0,Entry)*2-1; { Signal active }
{ PLOT }
If(Plot,Super,Signal);
|