MIDAS TOP/BOTTOM FINDER
//
SetBarsRequired(sbrAll);
sd = ParamDate("Input Date","2012-02-14",0);
st=ParamTime("input time","1:44",0);
dn = DateNum();
tn=TimeNum();
start = dn == sd AND tn==st;
mp = ParamField("Price field",-1);
PV1= Cum(mp * V);
CV1= Cum( V );
D=Param("D",6120000000,50000,9000000000000);
PV=PV1-ValueWhen(sd==dn AND tn==st,PV1,1);
CV=CV1-ValueWhen(sd==dn AND tn==st,CV1,1);
E=CV*(1-CV/D);
ET=CV-E;
startloop=EndValue(ValueWhen(sd==dn AND tn==st,BarIndex(),1));
endloop=EndValue(IIf(CV>D,ValueWhen(CV<D,BarIndex( ),1),BarCount));
barint=0;
TBF=mp;
for (j=startloop+1;j<endloop;j++)
{
k=0;
i=startloop+1;
while (ET[j]>0 AND k==0)
{
if (CV>ET[j])
{
k=1;
}
i=i+1;
}
if (k==1)
{
barint[j]=i-1;
}
Volint[j]=CV[barint[j]]-ET[j];
Mpint[j]=Low[barint[j]]*Volint[j];
CVint[j]=CV[j]-CV[barint[j]]+Volint[j];
PVint[j]=PV[j]-PV[barint[j]]+Mpint[j];
TBF[0]=Low[0];
TBF[j]=PVint[j]/CVInt[j];
}
TBF1=IIf(BarsSince(start),TBF,Null);
PCT=100*CV/D;
tbf2=IIf(BarIndex()<endloop,TBF1,Null);
Plot(TBF2,"PCT="+WriteVal(PCT,1.0)+"TBF",ParamColo r( "Color", colorCycle ), ParamStyle("Style") );
//
(Coded in AMIBROKER by me)
WORD OF CAUTION----- this is a very sophisticated tool pinpointing the end of a trending move and usually used either to book profits or to add positions------ do not use it without going through LEVINE's basic lessons on MIDAS ( freely available on web) and/or David Hawkins and Andrew Coles work