{- Filename: HvW Trading Navigator -} function _Volatility(Series: TSeries; Periode: integer): TSeries; var Len, i: integer; S: TSeries; begin Len := GetArrayLength(Series); S := CreateSeries(Len); { bereken de logaritme van het quotient van de slotkoers en de vorige slot } for i:=FirstValidIndex(Series)+1 to Len-1 do S[i] := ln(Series[i] / Series[i-1]); { de vermenigvuldigingsfactor 253 is voor dagkoersen; zie de Wall Street/AlexPro online help bij de Volatility indicator } Result := MultiplySeriesBy(StdDev(S, Periode), 100*sqrt(253)); // hier heb ik sqrt 52weken genomen ipv sqrt 253 dag end; var WMAPeriode4, WMAPeriode62, VolLevel: Integer; i, iFirst, StopLoss, VolPeriode : Integer; wma4, wma62, Svol : TSeries; SLLong, SLShort, MSL, ShowStopLoss : TSeries; SLLevel: Real; ShowAll: Boolean; State: integer; begin VolLevel := CreateParameterInteger('VolatilityLev', 1, 1000, 1000, true); WMAPeriode4 := CreateParameterInteger('WMAPeriode4', 1, 999, 4, true); WMAPeriode62 := CreateParameterInteger('WMAPeriode62', 1, 999, 62, true); StopLoss := CreateParameterInteger('StopLoss %' , 1, 999, 20, true); ShowAll := CreateParameterBoolean('ShowAll', false, true); VolPeriode := CreateParameterInteger('Volatility periode', 1, 999, 26, false); with Indicator do begin RequiredBars := MaxInt(WMAPeriode62, WMAPeriode4) + VolPeriode; NewBand := false; ScaleRange := srCommon; SignalView := svShowInMain; end; wma4 := MA(Close, maWeighted,WMAPeriode4); wma62 := MA(Close, maWeighted,WMAPeriode62); SLLong := MultiplySeriesBy(DivideSeriesBy(Close, 100), (100-StopLoss)); SLShort := MultiplySeriesBy(DivideSeriesBy(Close, 100), (100+StopLoss)); MSL := CreateSeries(Barcount); ShowStopLoss := CreateSeries(Barcount); SLLevel := 0; sVol := Volatility(Close, VolPeriode, BarInterval); State := 0; iFirst := MaxInt(FirstValidIndex(wma4), MaxInt(FirstValidIndex(sVol), FirstValidIndex(wma62))); for i:= iFirst+1 to BarCount-1 do begin if State = 1 then begin if Close[i] < SLLevel then SLLevel := SLLong[i] else SLLevel := Max(SLLevel, SLLong[i]); MSL[i]:= SLLevel; if IsValid(MSL[i-1]) then begin if Close[i] < MSL[i-1] then begin State := 0; ExitLong(i); end; end; end else if State = -1 then begin if Close[i] > SLLevel then SLLevel := SLShort[i] else SLLevel := Min(SLLevel, SLShort[i]); MSL[i]:= SLLevel; if IsValid(MSL[i-1]) then begin if Close[i] > MSL[i-1] then begin State := 0; ExitShort(i); end; end; end; if true then begin if (Close[i] > wma4 [i]) and (Close[i-1] > wma4[i-1]) and (Close[i] > Close[i-1]) and (wma62[i] > wma62[i-1]) and (sVol[i] < VolLevel) then begin if EnterLong(i) then begin State := 1; SLLevel := SLLong[i]; end; end else if (Close[i] < wma4 [i]) and (Close[i-1] < wma4[i-1]) and (Close[i] < Close[i-1]) and (wma62[i] < wma62[i-1]) and (sVol[i] < VolLevel) then begin if EnterShort(i) then begin State := -1; SLLevel := SLShort[i]; end; end; MSL[i] := SLLevel; if ShowAll or (State <> 0) then ShowStopLoss[i] := MSL[i]; end; end; with CreateLine(wma4) do begin Name :='wma4'; Color := clLime; end; with CreateLine(wma62) do begin Name :='wma62'; Color := clPurple; end; with CreateLine(ShowStopLoss) do begin Name :='SL'; Color := clYellow; LineType := ltCandlestick; end; END.