/*[[ Name := DiNapoli_Stoch Author := Copyright © 2004, a1cor. Notes := Stochastic Preferred DiNapoli Separate Window := Yes First Color := Red First Draw Type := Line First Symbol := 217 Use Second Data := Yes Second Color := Blue Second Draw Type := Line Second Symbol := 218 Minimum Chart Limits := 0.000000 Maximum Chart Limits := 100.000000 ]]*/ Inputs: FastKLen(8),SlowKLen(3),SlowDLen(3); Variables: shift(0), loopbegin(0), first(True), prevbars(0); Variables: FastK(0), PreferredSlowK(0), PreferredSlowD(0), prev(0); Variables: Value1(0), Value2(0); SetLoopCount(0); // check for additional bars loading or total reloading If Bars < prevbars Or Bars-prevbars>1 Then first = True; prevbars = Bars; // loopbegin prevent counting of counted bars exclude current If first Then Begin loopbegin = Bars-FastKLen-1; If loopbegin < 0 Then Exit; // not enough bars for counting first = False; // this block is to be evaluated once only End; // loop from first bar to current bar (with shift=0) loopbegin = loopbegin+1; // current bar is to be recounted too For shift = loopbegin Downto 0 Begin Value1 = Low[Lowest(MODE_LOW,shift+FastKLen-1,FastKLen)]; Value2 = High[Highest(MODE_HIGH,shift+FastKLen-1,FastKLen)] - Value1; if Value2 > 0 then FastK = (C[shift] - Value1) / Value2 * 100 else FastK = 0; prev = GetIndexValue(shift+1); PreferredSlowK = prev + (FastK - prev) / SlowKLen; SetIndexValue(shift, PreferredSlowK); prev = GetIndexValue2(shift+1); PreferredSlowD = prev + (PreferredSlowK - prev) / SlowDLen; SetIndexValue2(shift, PreferredSlowD); loopbegin = loopbegin-1; // prevent to previous bars recounting End;