Hi,
Just noticed this Clear method thread and have plotted this code together with code from the VSTpro
and there is a difference.
I did query the code with Jose Silva and gained the OK to post it on this forum,
Yesterday I posted several charts using the Clear method on the
VSTcharts blog.
The code below was extracted from the VSTpro Clear method template.
{Clear swing method based on S&C article
"Getting Clear With Short-Term Swings":
http://www.traders.com/Documentation/FEEDbk_docs/2010/09/Black.html
Note that the MetaStock "Clear" code as provided by Equis at
www.traders.com is incorrect.
Code adapted from VSTpro original code.
http://www.metastocktools.com/vst
Coded by Jose Silva at
http://www.metastocktools.com }
{ ----------- Start of custom code ----------- }
{User inputs}
swUp:=Input("Signals: Minimum UpSwing change %",0,25,0);
swDw:=Input("Signals: Minimum DwSwing change %",0,25,0);
rev:=Input("Reverse trade signals? [1]Yes [0]No",0,1,0);
display:=Input("Display: [1]'Clear' swing line [2]Signals",1,2,1);
{Ignore inside bars, avoid up/dw same-bar clash}
insideBar:=L>Ref(L,-1) AND H<Ref(H,-1);
{Clean price direction signals}
up:=H>Ref(H,-1) AND insideBar=0;
upSignal:=up AND Alert(up=0,2);
dw:=L<Ref(L,-1) AND insideBar=0;
dwSignal:=dw AND Alert(dw=0,2);
init:=Cum(IsDefined(upSignal+dwSignal))=1;
bin:=ValueWhen(1,upSignal-dwSignal<>0 OR init,
upSignal);
up:=bin*(Alert(bin=0,2)
OR upSignal*Cum(upSignal)=1);
dw:=(bin=0)*(Cum(bin)>0)*(Alert(bin,2)
OR dwSignal*Cum(dwSignal)=1);
{Clear Long/Short signals, swing line}
ClearUp:=Cross(L,ValueWhen(1,up,Ref(H,-1)))
AND insideBar=0;
ClearDw:=Cross(ValueWhen(1,dw,Ref(L,-1)),H)
AND insideBar=0;
init:=Cum(IsDefined(ClearUp+ClearDw))=1;
bin:=
ValueWhen(1,ClearUp-ClearDw<>0 OR init,ClearUp);
Clear:=If(bin,HighestSince(1,ClearUp,L),
LowestSince(1,ClearDw,H));
{Swing signals}
entry:=Clear>Ref(Clear,-1)*(1+swUp/100);
exit:=Clear<Ref(Clear,-1)*(1-swDw/100);
{ ------------ End of custom code ------------ }
{Reverse signals choice}
entry1:=entry;
entry:=If(rev,exit,entry1);
exit:=If(rev,entry1,exit);
{Display on price chart}
If(display=1,Clear,entry-exit)