[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Cynthia Kase indicators



PureBytes Links

Trading Reference Links


In reply to email requests for the complete PeakOscillator code with 
improvements.

-------------------------------------------
All using this code, or some other code with a normal distribution 
(like Black-Scholes), or any statistics-based TA, I'd encourage
to 
join me in suggesting 

http://amibroker.com/submit.html

to introduce the standard normal cumulative distribution and its 
inverse (Excel NORMSDIST and NORMSINV) as native AFL functions. This 
might speed up execution. Thanks. 
-------------------------------------------

NOTES:

1.
Re. yes/no smoothing an AspenGraphics rep (who have this indicator 
built-in) informed as follows:

"
>From my reading of the code, the difference between the long and short
indexes is smoothed by averaging over three points; the smoothing of 
the Peak Oscillator itself is done over 50 data points.
"
Well, smoothing over 50 datapoints leaves no signals at all so this 
is definitely not recommended. Cynthia Kase doesn't mention
smoothing 
the long and short indexes, all she says (in the BridgeTrader 
article) is:

"the PeakOscillator is the difference between KSDIup and KSDIdn with 
some
smoothing added".

Any smoothing seems arbitrary so I have smoothed the KPO plot with a 
3-period WMA which you can of course remove or adapt.
 
2.
Even if you choose SD_pop as standard deviation you cannot replace 
this with AFL StDev because StDev does not support variable periods 
used in SDcycl and SDhist.

/* code start */

/*
Definition of 3 different standard deviation measurements.
SD_pop is the population or biased version, similar to AFL StDev.
SD_sam is the sample or non-biased version which Kase describes in
her book and assumedly uses in her indicators.
SD_nnc is the non-centered version in which not the distances
between the values and the mean are squared but instead the values
themselves. Though not formally a standard deviation it appears used
by traders especially for measuring short-term volatility in strong
trends.
*/

function SD_pop(input,n)
{ return sqrt( (n*Sum(input^2,n)-(Sum(input,n))^2) / n^2 ); }

function SD_sam(input,n)
{ return sqrt( (n*Sum(input^2,n)-(Sum(input,n))^2) / (n^2-n) ); }

function SD_nnc(input,n)
{ return sqrt( Sum(input^2,n) / n ); }

/* Set your preferred standard deviation measurement SD */
//function SD(input,n) { return SD_pop(input,n); }
function SD(input,n) { return SD_sam(input,n); }
//function SD(input,n) { return SD_nnc(input,n); }

/* Set minimum and maximum lookbacks */
minLB = 8;
maxLB = 65;

/* Set percentiles for PeakOut lines using numbers between 1 and 99
*/
PCcycl = 98;
PChist = 90;

/* Definition of Kase PeakOscillator KPO */

function Kup(n)
{ return log(H/Ref(L,-n)); }

function Kdn(n)
{ return log(Ref(H,-n)/L); }

function Kvol(n)
{ return SD(log(Ref(C,-1)/C), n); }

function KSDIup(n)
{ return Kup(n)/(Kvol(n)*sqrt(n)); }

function KSDIdn(n)
{ return Kdn(n)/(Kvol(n)*sqrt(n)); }

maxKSDIup = 0;
for (i=minLB;i<=maxLB;i++)
{ maxKSDIup = IIf(KSDIup(i)>maxKSDIup,KSDIup(i),maxKSDIup); }

maxKSDIdn = 0;
for (i=minLB;i<=maxLB;i++)
{ maxKSDIdn = IIf(KSDIdn(i)>maxKSDIdn,KSDIdn(i),maxKSDIdn); }

KPO = maxKSDIup - maxKSDIdn;

/* Definition of PeakOut lines POmax and POmin */

UPcycle = minLB;
for (i=minLB+1;i<=maxLB;i++)
{ UPcycle = IIf(KSDIup(i)==maxKSDIup,i,UPcycle); }

DNcycle = minLB;
for (i=minLB+1;i<=maxLB;i++)
{ DNcycle = IIf(KSDIdn(i)==maxKSDIdn,i,DNcycle); }

function f(x)
{ return sqrt(-2*log(1-x)) ; }

function g(x)
{ return f(x) - (2.515517 + 0.802853*f(x) + 0.010328*f(x)^2) / (1 +
1.432788*f(x) + 0.189269*f(x)^2 + 0.001308*f(x)^3) ; }

function NDSINV(x)
{ return IIf(0<x AND x<0.5, -g(1-x), IIf(0.5<=x AND x<1, g(x),
0)) ; }

if (PCcycl<1) PCcycl=1;
if (PCcycl>99) PCcycl=99;
if (PChist<1) PChist=1;
if (PChist>99) PChist=99;

THcycl = NDSINV(0.5*(PCcycl/100+1));
THhist = NDSINV(0.5*(PChist/100+1));

CYCL = IIf(KPO>=0,UPcycle,DNcycle);
MNcycl = MA(KPO,CYCL);
SDcycl = SD(KPO,CYCL);
Vcycl1 = MNcycl + THcycl*SDcycl;
Vcycl2 = MNcycl - THcycl*SDcycl;
POcycl = IIf(KPO>0,Vcycl1,IIf(KPO<0,Vcycl2,0));

HIST = BarIndex()-maxLB+1;
MNhist = MA(KPO,HIST);
SDhist = SD(KPO,HIST);
Vhist1 = MNhist + THhist*SDhist;
Vhist2 = MNhist - THhist*SDhist;
POhist = IIf(KPO>0,Vhist1,IIf(KPO<0,Vhist2,0));

POmax = IIf(abs(POcycl)>abs(POhist),POcycl,POhist);
POmin = IIf(abs(POcycl)<abs(POhist),POcycl,POhist);

/* KPO, POmax & POmin plots */

/* uncomment and/or alter this line to plot smoothed KPO */
KPO = WMA(Nz(KPO),3);

GraphXSpace = 3;

Plot(POmax,"PeakOutMAX",colorRed,styleLine);
Plot(POmin,"PeakOutMIN",colorBlue,styleLine);

Col = IIf(abs(KPO)>=abs(POmax) AND Ref(abs(KPO),1)<Ref(abs
(POmax),1),colorViolet,IIf(abs(KPO)>=abs(POmin) AND Ref(abs(KPO),1)
<Ref(abs(POmin),1),colorPink,colorGreen));
Plot(KPO,"KPeakOsc",Col,styleHistogram|styleThick);

/* UPcycle & DNcycle plots, for use in separate pane */

//Plot(UPcycle,"UPcycle",colorGreen,styleLine|styleDots);
//Plot(DNcycle,"DNcycle",colorRed,styleLine|styleDots);

/* code end */

-treliff


--- In amibroker@xxxxxxxxxxxxxxx, "treliff" <treliff@xxxx> wrote:
> 
> I myself never coded the Dev-stop yet.  
> 
> By the way there were a few code improvements mentioned here:
> 
> http://finance.groups.yahoo.com/group/amibroker/message/61756
> http://finance.groups.yahoo.com/group/amibroker/message/61855
> 
> I'd be very interested to hear if any of you guys managed to 
extract 
> some consistent profits with it, at least in backtesting. I hardly 
> use any traditional TA, still think Kase's work is exceptional but 
> never got to implement it.  
> 
> -treliff
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "MPLM (Intel EPSD) Razvan Andrei" 
> <randrei@xxxx> wrote:
> > Hi,
> > I think I found the problem, was in data: for a period equal with 
> minLB the
> > Close was constant, as a result Kvol become 0 and KSDIup and 
KSDIdn 
> cannot
> > be calculated (division by 0!).
> > Thanks,
> > Razvan
> >   -----Mesaj original-----
> >   De la: Jerry Gress [mailto:pleasenospamplease@x...]
> >   Trimis: 10 februarie 2005 12:32
> >   Către: amibroker@xxxxxxxxxxxxxxx
> >   Subiect: RE: [amibroker] Re: Cynthia Kase indicators
> > 
> > 
> >   HI,
> > 
> > 
> > 
> >   I have no problems with this code, Using AB 4.60 on tick 
intraday 
> data.
> > The only problem is high cpu usage in real time over 50%.
> > 
> > 
> > 
> >   Jerry Gress
> > 
> >   Stockton, Ca.
> > 
> > 
> > 
> >   -----Original Message-----
> >   From: MPLM (Intel EPSD) Razvan Andrei [mailto:randrei@x...]
> >   Sent: Wednesday, February 09, 2005 11:41 PM
> >   To: amibroker@xxxxxxxxxxxxxxx
> >   Subject: [amibroker] Re: Cynthia Kase indicators
> > 
> > 
> > 
> >   Hi,
> > 
> >   thank you for your code. I paste it as it was in your post and 
I 
> have a
> > small problem: for many stocks, everything is going well until a 
> moment when
> > KPeakOsc becomes {Empty} PeakOutMax and PeakOutMin become 0. 
After 
> this
> > moment PeakOutMax and Min remain {Empty}. Do you have any ideea 
how 
> can I
> > avoid this?
> > 
> >   Did you managed to look (and code ;)) the Kase Dev-Stop?
> > 
> >   Thanks again,
> > 
> >   Razvan
> > 
> >     -----Mesaj original-----
> >     De la: treliff [mailto:treliff@x...]
> >     Trimis: 4 februarie 2005 18:43
> >     Către: amibroker@xxxxxxxxxxxxxxx
> >     Subiect: [amibroker] Re: Cynthia Kase indicators
> > 
> > 
> >     there's a thread here re. the PeakOscillator which includes 
KSDI
> > 
> >     http://finance.groups.yahoo.com/group/amibroker/message/60990
> > 
> > 
> >     --- In amibroker@xxxxxxxxxxxxxxx, Stas Desy <stasdesy@xxxx> 
> wrote:
> >     > Hi All,
> >     >
> >     > Does anybody now of an implementation of Cynthia Kase
> >     > studies in AB ?
> >     > I'm particularly interested in KSDI (serial dependency
> >     > index).
> > 
> > 
> > 
> > 
> > 
> >     Check AmiBroker web page at:
> >     http://www.amibroker.com/
> > 
> >     Check group FAQ at:
> > http://groups.yahoo.com/group/amibroker/files/groupfaq.html
> > 
> > 
> > 
> >     Check AmiBroker web page at:
> >     http://www.amibroker.com/
> > 
> >     Check group FAQ at:
> > http://groups.yahoo.com/group/amibroker/files/groupfaq.html
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> >     Check AmiBroker web page at:
> >     http://www.amibroker.com/
> > 
> >     Check group FAQ at:
> > http://groups.yahoo.com/group/amibroker/files/groupfaq.html
> > 
> > 
> >           Yahoo! Groups Sponsor
> >                 ADVERTISEMENT
> > 
> > 
> > 
> > 
> > 
> > ------------------------------------------------------------------
--
> --------
> >     Yahoo! Groups Links
> > 
> >       a.. To visit your group on the web, go to:
> >       http://groups.yahoo.com/group/amibroker/
> > 
> >       b.. To unsubscribe from this group, send an email to:
> >       amibroker-unsubscribe@xxxxxxxxxxxxxxx
> > 
> >       c.. Your use of Yahoo! Groups is subject to the Yahoo! 
Terms 
> of
> > Service.





------------------------ Yahoo! Groups Sponsor --------------------~--> 
What would our lives be like without music, dance, and theater?
Donate or volunteer in the arts today at Network for Good!
http://us.click.yahoo.com/Tcy2bD/SOnJAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/