Hi, Commenting only on the code structure; You can improve things by not repeating the same calcuations unnecessarily.
Mike // Stochastic Trend Filter Periods = Param( "Periods", 15, 1, 200, 1 ); Ksmooth = Param( "%K avg", 50, 1, 200, 1 ); EMAKsmooth = EMA( C, Ksmooth ); PriorEMAKsmooth = Ref( EMAKsmooth, -1 ); StochKKsmooth = StochK( Periods, Ksmooth ); Plot( IIf( EMAKsmooth > PriorEMAKsmooth, StochKKsmooth, 0 ), "", 27 ); Plot( IIf( EMAKsmooth < PriorEMAKsmooth, StochKKsmooth, 0 ), "", 4 ); --- In [email protected], "Gerard Carey" <gcfina...@...> wrote: > > The Stochastic Trend Filter > A trader mate of mine asked me to create a stochastic filter for him. > He wanted one that would use stochastics to determine the character > of the predominant trend. > He wanted to do some backtesting, taking only (short-term) long > trades when a stochastic filter showed the predominant trend was > positive & only (short-term) shorts when it was negative. > He uses stochos as an important part of his trading system. > I'm sure he knows them upside down & inside out, so he obviously just > wanted somebody to take a fresh look, without any of his bias. > After checking it out he reckons it's cool and works better than what > he used previously, tho he reckons there are nuances he wants to > investigate further. So for him it's early days. > Anyway here 'tis for your evaluation and edification. > I trust it may be of value. > > Regards, good trading and have a good weekend, > Gerard > > // Stochastic Trend Filter > periods = Param( "Periods", 15, 1, 200, 1 ); > Ksmooth = Param( "%K avg", 50, 1, 200, 1 ); > > Plot( IIf(EMA(C,Ksmooth)>Ref(EMA(C,Ksmooth),-1),StochK( periods , > Ksmooth),0),"",27) ; > Plot( IIf(EMA(C,Ksmooth)<Ref(EMA(C,Ksmooth),-1),StochK( periods , > Ksmooth),0),"",4) ; > > /* > INTERPRETATION > So the deal is; > NB. The Filter is designed for those taking relatively short term > trades, say up to 15 bars max. > When green line is on top the Predominant trend is positive, take > only long signals, red on top then only shorts are allowed. > That's it. > Its rather simple construction belies the effort spent on its > development. > In short what I needed to do was to identify, in a general way, the > trends a data series may contain, and then determin the specific > trend ( the predominant one) that should be applied to a specific > trading time frame. > */ >
