TradersBulletin oktober 2007

Kant-en-klare, geteste indicatoren en handelssystemen
Plaats reactie
Eric
Berichten: 3332
Lid geworden op: za sep 10, 2005 2:41 am
Locatie: Den Haag

TradersBulletin oktober 2007

Bericht door Eric »

http://www.keyword.nl/homepage/pdf/trad ... 200701.pdf


Intraday traden met cycli door Michael Ahrens

Michael Ahrens gebruikt in zijn artikel een 5 en 10-bar Double Stochastic die door elkaar zijn getekend.

Code: Selecteer alles

{- Filename: Double Stochastics (dual) -}

function PctK(aHigh, aLow, aClose: TSeries; aLength: integer): TSeries;
var
  sHigh, sLow, sLowDiff: TSeries;
  Deler: real;
  Count, i: integer;
begin
  Count := GetArrayLength(aClose);
  sHigh := HighSeries(aHigh, aLength);
  sLow := LowSeries(aLow, aLength);
  sLowDiff := SubtractSeries(aClose, sLow);
  Result := CreateSeries(Count);

  for i:=FirstValidIndex(sHigh) to Count-1 do
  begin
    Deler := sHigh[i] - sLow[i];
    if Deler = 0 then Deler := 1;
    Result[i] := sLowDiff[i] / Deler * 100;
  end;
end;

var 
  nLength1, nLength2, nUpGrens, nDnGrens: integer;
  sTemp, sDS1, sDS2: TSeries;
begin
{ Indicator parameters } 
  nLength1 := CreateParameterInteger('Length 1', 1, 999, 5, true);
  nLength2 := CreateParameterInteger('Length 2', 1, 999, 10, true);
  nUpGrens := CreateParameterInteger('Bovengrens', 1, 999, 70, true);
  nDnGrens := CreateParameterInteger('Ondergrens', 1, 999, 30, true); 

{ Indicator eigenschappen } 
  with Indicator do 
  begin 
    ShortName := 'DSS (dual)';
{ Aantal benodigde koersen om eerste indicatorwaarde te berekenen } 
    RequiredBars := 5*nLength2;
  end; 

  sTemp := MA(PctK(High, Low, Close, nLength1), maExponential, 3);
  sDS1 := MA(PctK(sTemp, sTemp, sTemp, nLength1), maExponential, 3);
  sTemp := MA(PctK(High, Low, Close, nLength2), maExponential, 3);
  sDS2 := MA(PctK(sTemp, sTemp, sTemp, nLength2), maExponential, 3);

  with CreateLine(sDS2) do
  begin
    Name := 'DS2';
    Color := clRed;
  end;
  with CreateLine(sDS1) do
  begin
    Name := 'DS1';
    Color := clBlue;
  end;
  with CreateLine(FillSeries(CreateSeries(BarCount), nUpGrens)) do
  begin 
    Name := 'UpGrens'; 
    Color := clSilver; 
    LineContent := lcConstant;
  end; 
  with CreateLine(FillSeries(CreateSeries(BarCount), nDnGrens)) do 
  begin 
    Name := 'DnGrens'; 
    Color := clSilver; 
    LineContent := lcConstant;
  end;
end.
Laatst gewijzigd door Eric op wo okt 17, 2007 1:19 pm, 2 keer totaal gewijzigd.
Eric
Berichten: 3332
Lid geworden op: za sep 10, 2005 2:41 am
Locatie: Den Haag

Bericht door Eric »

Geef een indicator kleur met TA-script door Eric Jansen

Let op: deze scripts werken alleen in Wall Street build 221 of hoger, en kunnen in AlexPro pas gebruikt worden in de komende versie (najaar 2007).

Code: Selecteer alles

{- Filename: Month of Year Performance -}

function MonthPerf(Month: integer): TSeries;
var
  i, iYear, iMonth, iDay, WrkMonth: integer;
  Started: boolean;
  StartPrice: real;
begin
  Result := FillSeries(CreateSeries(BarCount), 0);
  Started := false;
  if BarCount > 0 then
  begin
    DecodeDate(DateTime[0], iYear, WrkMonth, iDay);
    for i:=1 to BarCount-1 do
    begin
      Result[i] := Result[i-1];
      DecodeDate(DateTime[i], iYear, iMonth, iDay);
      if iMonth <> WrkMonth then
      begin
        if Started and (WrkMonth = Month) then
        begin
          Result[i] := Result[i] + Close[i] - Close[i-1];
        end;
        Started := true;
        StartPrice := Close[i];
        WrkMonth := iMonth;
      end else
      begin
        if Started and (iMonth = Month) then
          Result[i] := Result[i] + Close[i] - Close[i-1];
      end;
    end;
  end;
end;

var
  i, Year, Month, Day: integer;
  sPerf: TSeries;
  Colors: array[1..12] of TColor;
begin
{ alle koersen meenemen voor de performance berekening }
  Indicator.RequiredBars := 100000;

{ maak een array met de kleur per maand }
  Colors[1] := clWhite;
  Colors[2] := clLtGray;
  Colors[3] := clYellow;
  Colors[4] := clNavy;
  Colors[5] := clDkGray;
  Colors[6] := RGB(255,128,0);
  Colors[7] := RGB(255,0,255);
  Colors[8] := RGB(255,200,120);
  Colors[9] := clRed;
  Colors[10] := clAqua;
  Colors[11] := clBlue;
  Colors[12] := clLime;

  for i:=0 to BarCount-1 do
  begin
    DecodeDate(DateTime[i], Year, Month, Day);
    SetParentBarColor(i, Colors[Month]);
  end;
  
  for i:=1 to 12 do
  begin
    sPerf := MonthPerf(i);
    with CreateLine(sPerf) do
    begin
      Name := 'Maand '+IntToStr(i);
      Color := Colors[i];
    end;
  end;
end.




Code: Selecteer alles

{- Filename: Volume colors -}

var
  i: integer;
begin
  for i:=0 to BarCount-1 do
  begin
    if Close[i] > Open[i] then
      SetBarColor(0, i, clLime)
    else if Close[i] < Open[i] then
      SetBarColor(0, i, clRed);
  end;
  
  with CreateLine(Volume) do
  begin
    Name := 'Volume';
    Color := clWhite;
    LineType := ltBar;
  end;
end.
Eric
Berichten: 3332
Lid geworden op: za sep 10, 2005 2:41 am
Locatie: Den Haag

Bericht door Eric »

Het Market Key System door Paul Menzing en Ed Kiers

Een artikel naar aanleiding van het boek: How to Trade In Stocks

Let op: dit script werkt alleen in Wall Street build 221 of hoger, en kan in AlexPro pas gebruikt worden in de komende versie (najaar 2007).
Kies een witte achtergrond in de grafiek, anders vallen er dingen weg.

Code: Selecteer alles

{- Filename: PM Livermore -}
 
procedure CreateNewText(DT: TDateTime; Price: real; sString: string; txVertPosition: TVertPosition; fFontSize:integer);
begin
 
    with CreateText(DT, Price, sString) do
      begin
        color         := clBlack;
        HorzPosition  := hpCenter;
        VertPosition  := txVertPosition;
        BkColor       := clBlack;
        UseBkColor    := false;
        Font.Name     := 'Verdana';
        Font.Size     := fFontSize;
        Font.Style    := [fsBold,fsItalic];
      end;
end;
procedure CreateNewTextPivot(DT: TDateTime; Price: real; sString: string; txVertPosition: TVertPosition;clColor:TColor);
begin
 
    with CreateText(DT, Price, sString) do
      begin
        color         := clColor;
        HorzPosition  := hpCenter;
        VertPosition  := txVertPosition;
        BkColor       := clWhite;
        UseBkColor    := false;
        Font.Name     := 'Times New Roman';
        Font.Size     := 28;
        Font.Style    := [fsBold];
      end;
end;
type
  TLivermoreState = (ds0,ds1, ds2, ds3, ds4, ds5);
var
  i,PtsPctATR,FontSize                                      : integer;
  ShowText,ShowPivotLines,ShowPivotDots,ShowPivotText       : boolean;
  UpTrendState,DnTrendState,NatRallyPath,NatReactPath       : boolean;
  TradeTrends                                               : boolean;
  Thresh , threshold, HalfThresh                            : real;
  NaturalReaction, NaturalRallyBL ,NatRallyDnTrBL           : real;
  NaturalReactionRL, UpTrendRL,NatReactionUpTrRL            : real;
  UpTrend, DnTrendBL,TextOffSet                             : real;
  SecondaryRally, NaturalRally                              : real;
  SecondaryReaction, DnTrend                                : real;
  MA10_10, MA10_Now ,ATR,CloseAgo,vState                    : TSeries;
  DnTrendPivot,UpTrendPivot,NatReactionPivot,NatRallyPivot  : TSeries;
  Color                                                     : TColor;
  State                                                     : TLivermoreState;
 
begin
  threshold       :=  CreateParameterReal('threshold pts/% or atr', 0, 10000, 5, true);
  TextOffSet      :=  CreateParameterReal('TextOffSet', 0, 1000, 25, true);
  FontSize        :=  CreateParameterInteger('FontSize', 1, 40, 8, true);
  PtsPctATR       :=  CreateParameterInteger('PtsPctATR', 0, 2, 1, true);{0=Points, 1=Percent, 2=ATR}
  ShowText        :=  CreateParameterBoolean('ShowText', true, false);
  ShowPivotText   :=  CreateParameterBoolean('ShowPivotText', false, false);
  ShowPivotLines  :=  CreateParameterBoolean('PivotLines', false, false);
  ShowPivotDots   :=  CreateParameterBoolean('PivotDots', false, false);
  TradeTrends     :=  CreateParameterBoolean('TradeTrends', false, false);
    {State = 0 Uptrend }
    {State = 1 Dntrend }
    {State = 2 NatRally}
    {State = 3 SecRally}
    {State = 4 NatReact}
    {State = 5 SecReact}
    with Indicator do
  begin
    ShortName            :='Wall Street PM Livermore';
    RequiredBars         := 200;
    Indicator.NewBand    := false;
    Indicator.ScaleRange := srCommon;
    SignalView           := svShowInMain;
  end;
 
   ATR              := MA(TrueRange(High, Low, Close), maSimple, 14);
   vState           := CreateSeries(BarCount);
   CloseAgo         := ShiftSeries(Close,1);
   UpTrendPivot     := CreateSeries(Barcount);
   DnTrendPivot     := CreateSeries(Barcount);
   NatReactionPivot := CreateSeries(Barcount);
   NatRallyPivot    := CreateSeries(Barcount);
 
  if (PtsPctATR = 0) then
   begin
     Thresh     := threshold;
     HalfThresh := thresh/2;
   end;
 
for i := 1 to BarCount - 1 do
  begin
 
  if (i = 1) then
   begin
 
     CreateNewText(BarPosition[i], High[i], 'Init', vpTop,FontSize);
     SecondaryRally    := Close[i];
     NaturalRally      := Close[i];
     UpTrend           := Close[i];
     SecondaryReaction := Close[i];
     NaturalReaction   := Close[i];
     DnTrend           := Close[i];
     vState[i]         := -1;
   end;
 

  if (i <= 21 ) then begin
    MA10_Now  :=  MA(Close, maSimple, 10);
    MA10_10   := ShiftSeries(MA10_Now, 10);
    vState[i] := -1;
 

   if (i = 21) then begin {2}
 
    if MA10_Now[i] > MA10_10[i] then
     begin
      if (vState[i-1] <> 0) and ShowText then CreateNewText(BarPosition[i], High[i],'UpTrend', vpTop,FontSize);
      State     := ds0;
      vState[i] := 0;
      UpTrend   := Close[i];
      Color     := clBlue;
     end
     else
     begin
      if (vState[i-1] <> 1) and ShowText then CreateNewText(BarPosition[i], Low[i],'Dntrend', vpBottom,FontSize);
      DnTrend   := Close[i];
      State     := ds1;
      vState[i] := 1;
      Color     := clRed;
     end;
     SetParentBarColor(i, Color);
   end;
  end;
 

 if (i >= 22) then begin
 
  if (PtsPctATR = 1) then
   begin
     Thresh     := threshold * (CloseAgo[i]/100);
     HalfThresh := Thresh/2;
   end
   else if (PtsPctATR = 2) then
   begin
     Thresh     := threshold * ATR[i];
     HalfThresh := Thresh/2;
   end;
 
    { UPTREND STATE}
    case State of
    ds0:
      begin
       UpTrendState := true;
       DnTrendState := false;
       NatRallyDnTrBL :=   0;
 
       if (Close[i] > (NaturalReaction + Thresh)) then NaturalReactionRL   := NaturalReaction; {Rule 4b}
 
            if (Close[i] < (UpTrend - Thresh)) then {start NaturalReaction}
             begin {Rules 6a}
              if (NatReactPath = true) and (close[i] > NatReactionUpTrRL)  then begin
               {start secondaryreaction}
               State := ds5; {InSecReaction}
               SecondaryReaction := Close[i];
               UpTrendRL       := UpTrend; {Pivot Pt, 4a}
               if  ShowPivotLines then CreateNewTextPivot(BarPosition[i],UpTrendRL,'=',vpCenter,clRed);
               if  ShowPivotText then CreateNewText(BarPosition[i],UpTrendRL + TextOffSet,'UpPivot',vpTop,FontSize);
               UpTrendPivot[i] := UpTrendRL;
              end
               else begin
               State             := ds4; {InNatReact}
               UpTrendRL         := UpTrend;  {pivot point, 4a}
               UpTrendPivot[i] := UpTrendRL;
               if  ShowPivotLines then CreateNewTextPivot(BarPosition[i],UpTrendRL,'=',vpCenter,clRed);
                if  ShowPivotText then CreateNewText(BarPosition[i],UpTrendRL + TextOffSet,'UpPivot',vpTop,FontSize);
               NaturalReaction   := Close[i];
              end;
             end
             else if (Close[i] > UpTrend) then {remain in uptrend higher high price}  {rule 6a}
                UpTrend         := Close[i];
 
         end;  {END UPTREND STATE}
 
       {NATURAL RALLY STATE}
       ds2:
         begin
             NatReactionUpTrRL  := 999999;
             NatReactPath := false;
 
           if (DnTrendState = true) and (Close[i] > UpTrend) then  {UpTrend}
          begin    {Rules 6f}
            State          := ds0; {InUpTrend}
            UpTrend        := Close[i];
          end
        else
          if (DnTrendState = true) and (Close[i] > (NaturalRallyBL + HalfThresh)) then   {Rules 5a}
                begin {start Uptrend}
                 State          := ds0; {InUpTrend}
                 UpTrend        := Close[i];
                end
               else if (DnTrendState = true) and (Close[i] < DnTrend) then {Start DnTrend}
                begin {Rule 6b}
                 State := ds1; {InDnTrend}
                 DnTrend := Close[i];
                 NaturalRallyBL := Close[i]; {rule 4D}
                 NaturalRallyBL  :=  NaturalRally; {rule 4D} {Pivot pt}
                 NatRallyDnTrBL :=  NaturalRally;
                 if  ShowPivotLines then CreateNewTextPivot(BarPosition[i],NaturalRallyBL,'=',vpCenter,clBlack);
                 if  ShowPivotText then CreateNewText(BarPosition[i],NaturalRallyBL + TextOffSet,'RallyPivot',vpTop,FontSize);
                 NatRallyPath := true;
                 NatRallyPivot[i] := NaturalRallyBL;
                end
                else if (DnTrendState = true) and (Close[i] < (NaturalRally - Thresh)) then {Rule 6b}
                 begin  {start NaturalReaction}
                      State := ds4; {NaturalReaction}
                      NaturalReaction := Close[i];
                      NaturalRallyBL  :=  NaturalRally; {rule 4D} {Pivot pt, Rule 9b}
                       if  ShowPivotLines then CreateNewTextPivot(BarPosition[i],NaturalRallyBL,'=',vpCenter,clBlack);
                       if  ShowPivotText then CreateNewText(BarPosition[i],NaturalRallyBL + TextOffSet,'RallyPivot',vpTop,FontSize);
                      NatRallyPivot[i] := NaturalRallyBL;
                    end
                    else
     {3}               if (UptrendState = true) and (Close[i] > UpTrend) then {resume UpTrend}
               begin
                State           := ds0; {InUpTrend}
                UpTrend         := Close[i];
 
               end
      {4}              else if (UpTrendState = true)and (Close[i] < (NaturalRally - Thresh)) and  (close[i] > NaturalReactionRL) then
                 begin  {start secondaryreaction}
                      State := ds5; {InSecReact}
                      SecondaryReaction := Close[i];
                    end
       {1}            else if (UpTrendState = true)and (Close[i] > (NaturalReactionRL - Thresh)) and  (close[i] < NaturalReactionRL) then
                 begin  {start NaturalReaction }
                      State := ds4; {NatReact}
                      NaturalReaction   := Close[i];
                    end
       {2}             else if (UpTrendState = true)and (Close[i] < (NaturalReactionRL - Thresh))  then
                 begin  {start DnTrend }
                     State         := ds1; {InDnTrend}
                     DnTrend       := Close[i];
                    end
               else
                  if (Close[i] > NaturalRally) then
                    NaturalRally     := Close[i]; { rules 6c}
 
              end; {END NATURAL RALLY STATE}
 
            {SECONDARY RALLY STATE}
            ds3:
               begin
                     if (NatRallyPath = true) then NaturalReaction := DnTrendBL;
                     NatRallyPath := false;
                     {*** When in UpTrend***}
        if (UpTrendState = true) and (Close[i] < SecondaryRally - Threshold) and (Close[i] > NaturalReaction) then  {start SecondaryReaction }
          begin
            State := ds5; {InSecReact}
            SecondaryReaction := Close[i];
          end else
    if (UpTrendState = true)  and (Close[i] > NaturalRally) then  {start NaturalRally }
          begin
            State := ds2; {InNatRally}
            NaturalRally := Close[i];
          end
         else
        if (UpTrendState = true) and (Close[i] < NaturalReactionRL) then  {DnTrend}
          begin
            State := ds4; {InNatReact}
            NaturalReaction := Close[i];
          end
       else
       if (UpTrendState = true) and (Close[i] > UpTrendRL) then  {UpTrend}
          begin   {Rules 6d, 6f}
            State := ds0; {InUpTrend}
            UpTrend := Close[i];
          end
       else
       {***When in DownTrend***}
        if (DnTrendState = true) and (Close[i] < (SecondaryRally - Threshold)) and (Close[i] > NaturalReaction)and (DnTrend <> NaturalReaction) then  {start SecondaryReaction }
          begin
            State := ds5;
            SecondaryReaction := Close[i];
          end
        else
      {2} if (DnTrendState = true) and(Close[i] > (NaturalRallyBL + HalfThresh)) then  {resume UpTrend}
          begin    {Rules 5a}
            State := ds0;
            UpTrend := Close[i];
          end
   {1}     else if (DnTrendState = true) and (Close[i] > NaturalRallyBL) and  (Close[i] < (NaturalRallyBL + HalfThresh))then  {start NaturalRally}
          begin    {Rule 6g}
            State := ds2;
            NaturalRally := Close[i];
          end
 {3}  else if (DnTrendState = true) and (Close[i] < NaturalReaction ) and (DnTrend <> NaturalReaction) then
             begin {rule 6g}
               State := ds4;
               NaturalReaction  := Close[i];
          end
        else if (DnTrendState = true) and (Close[i] < DnTrend) then {start DnTrend}
          begin   {Rule 6b}
            State := ds1;
            DnTrend := Close[i];
          end
        else if (Close[i] > SecondaryRally) then SecondaryRally := Close[i]; {record higher high} {rule 3, 6g}
 
                  end; {END SECONDARY RALLY STATE}
 
             {DOWN TREND STATE}
              ds1:
                begin {9}
                  UpTrendState := false;
                  DnTrendState := true;
                  NatReactionUpTrRL  := 999999;
 
                  if (Close[i] < (NaturalRally - Thresh)) then NaturalRallyBL     := NaturalRally; {rule 4d}
 
                     if (Close[i] > (DnTrend + Thresh))  then  {Start NaturalRally}  { rules 6c}
                      begin
                      if (NatRallyPath = true) and(close[i] < NatRallyDnTrBL) then begin
                              {start secondaryrally}
                              State := ds3; {InSecRally}
                              SecondaryRally := Close[i];
                              DnTrendBL       := DnTrend; {Pivot Pt, 4c}
                              if  ShowPivotLines then CreateNewTextPivot(BarPosition[i],DnTrendBL,'=',vpCenter,clBlack);
                              if  ShowPivotText then CreateNewText(BarPosition[i],DnTrendBL - TextOffSet,'DnPivot',vpBottom,FontSize);
                              DnTrendPivot[i] := DnTrendBL;
                              end
                                else  begin
                        State           := ds2; {InNatRally}
                        NaturalRally    := Close[i];
                        DnTrendBL       := DnTrend; {Pivot Pt, 4c}
                        if  ShowPivotLines then CreateNewTextPivot(BarPosition[i],DnTrendBL,'=',vpCenter,clBlack);
                        if  ShowPivotText then CreateNewText(BarPosition[i],DnTrendBL - TextOffSet,'DnPivot',vpBottom,FontSize);
                        DnTrendPivot[i] := DnTrendBL;
                        end;
                      end
                       else if (Close[i] < DnTrend)  then {remain in down trend, record lower lows}
                         DnTrend := Close[i]; {rule 6c}
 
                  end;  {END DOWN TREND STATE}
 
                {NATURAL REACTION STATE}
                ds4:
 
                   begin   {Nat Reaction State}
                   NatRallyDnTrBL :=   0;
                   NatRallyPath := false;
 
                      if (UptrendState = true) and(Close[i] < (NaturalReactionRL - halfthresh )) then {rule 5b}
                        {start DnTrend}
                         begin
                           State        := ds1; {InDnTrend}
                           DnTrend      := Close[i];
 
                         end
                         else if (UptrendState = true) and (Close[i] > UpTrend)  then {start UpTrend}  {rule 6d}
                          begin
                           State             := ds0; {InUpTrend}
                           UpTrend           := Close[i];
                           NaturalReactionRL := NaturalReaction; {rule 4b, pvt point}
                           NatReactionUpTrRL :=  NaturalReaction;
                           if  ShowPivotLines then CreateNewTextPivot(BarPosition[i],NaturalReactionRL,'=',vpCenter,clRed);
                           if  ShowPivotText then CreateNewText(BarPosition[i],NaturalReactionRL - TextOffSet,'ReactionPivot',vpBottom,FontSize);
                           NatReactPath := true;
                           NatReactionPivot[i] :=  NaturalReactionRL;
 
                          end
 
                            else if (UptrendState = true) and (Close[i] > NaturalReaction + Thresh) then  {rule 6d}
                             begin  {start NaturalRally}
                                 State          := ds2; {NaturalRally}
                                 NaturalRally := Close[i];
                                 NaturalReactionRL := NaturalReaction; {rule 4b, pvt point}
                                 if  ShowPivotLines then CreateNewTextPivot(BarPosition[i],NaturalReactionRL,'=',vpCenter,clRed);
                                 if  ShowPivotText then CreateNewText(BarPosition[i],NaturalReactionRL - TextOffSet,'ReactionPivot',vpBottom,FontSize);
                                 NatReactionPivot[i] :=  NaturalReactionRL;
                              end
           else if (DnTrendState = true) and (Close[i] < DnTrend) then  {resume DnTrend}
          begin   {Rule  6b, 6e}
            State          := ds1;
            DnTrend := Close[i];
          end
     {4}   else if (DnTrendState = true) and (Close[i] > (NaturalReaction + Thresh)) and (Close[i] < NaturalRallyBL) then
          begin   {Rule 6g}
            State          := ds3; {start SecondaryRally}
            SecondaryRally := Close[i];
    end
 {1} else if (DnTrendState = true)  and (Close[i] > NaturalRallyBL) and (Close[i] < (NaturalRallyBL + HalfThresh))then
          begin   {Rule 6g}
            State          := ds2;
            NaturalRally := Close[i];
    end
 {2} else if (DnTrendState = true)  and (Close[i] > NaturalRallyBL+ HalfThresh) then
          begin   {Rule 6g}
            State          := ds0;
            UpTrend := Close[i];
    end
                        else
                             if (Close[i] < NaturalReaction) then {remain in NaturalReaction , record lower lows} {rule 6a}
                              NaturalReaction := Close[i];
 
                       end; {END NATURAL REACTION STATE}
 
                   {SECONDARY REACTION STATE}
                   ds5:
                     begin
                     if (NatReactPath = true) then NaturalRally := UpTrendRL;
                         NatReactPath := false;
                         {***When in DownTrend***}
   if (DnTrendState = true) and (Close[i] > SecondaryReaction + Threshold) and (Close[i] < NaturalRally) then  {start SecondaryRally }
          begin
            State          := ds3;
            SecondaryRally := Close[i];
          end else
    if (DnTrendState = true)  and (Close[i] < NaturalReaction) then  {start NaturalReaction }
          begin
            State          := ds4;
            NaturalReaction := Close[i];
          end
         else
        if (DnTrendState = true) and (Close[i] > NaturalRallyBL) then
          begin
            State          := ds2;
            NaturalRally := Close[i];
          end
       else
       if (DnTrendState = true) and (Close[i] < DnTrendBL) then  {DnTrend}
          begin
            State          := ds1;
            DnTrend := Close[i];
          end
       else
 
  {***When in UpTrend***}
        if (UpTrendState = true) and (Close[i] > (SecondaryReaction + Threshold)) and (Close[i] < NaturalRally)and (UpTrend <> NaturalRally) then  {start SecondaryRally }
          begin   {Rules  6b, 6e}
            State          := ds3;
            SecondaryRally := Close[i];
          end
   {2}     else if (UpTrendState = true) and(Close[i] < (NaturalReactionRL - HalfThresh)) then  {DnTrend}
          begin    {Rules 5b}
            State          := ds1;
            DnTrend := Close[i];
               end
  {3}    else if (UpTrendState = true) and (Close[i] > NaturalRally ) and (UpTrend <> NaturalRally) then
            begin {rule 6g}
            State          := ds2;
            NaturalRally := Close[i];
    end
        else if  (UpTrendState = true) and (Close[i] > UpTrend) then {start UpTrend}
          begin   {Rule 6d}
            State          := ds0;
            UpTrend := Close[i];
    end
   {1}     else if (UpTrendState = true) and (Close[i] < NaturalReactionRL) and (Close[i] > (NaturalReactionRL - HalfThresh)) then  {start NaturalReaction}
          begin    {Rule 6h}
            State          := ds4;
            NaturalReaction := Close[i];
          end
                          else if (Close[i] < SecondaryReaction) then {record lower lows}
                              SecondaryReaction := Close[i];  {rule 6h}
                      end; {END SECONDARY REACTION STATE}
                 else
                   begin
                      CreateNewText(BarPosition[i], High[i],'Never get here! ', vpTop,FontSize);
                   end;
                 end;
 

 {PAINT IT}
   case State of
    ds0:
     begin
      Color     := clBlue;
      vState[i] := 0;
      if (vState[i-1] <> 0) and ShowText then CreateNewText(BarPosition[i], High[i] + TextOffSet,'UpTrend', vpTop,FontSize);
     end;
 
    ds1:
     begin
       Color     := clRed;
       vState[i] := 1;
       if (vState[i-1] <> 1) and ShowText then CreateNewText(BarPosition[i], Low[i] - TextOffSet,'Dntrend', vpBottom,FontSize);
     end;
 
    ds2:
     begin
       Color     := clBlack;
       vState[i] := 2;
       if (vState[i-1] <> 2) and ShowText then CreateNewText(BarPosition[i], High[i] + TextOffSet,'NatRally', vpTop,FontSize);
     end;
 
    ds3:
     begin
       Color     := clGreen;
       vState[i] := 3;
       if (vState[i-1] <> 3) and ShowText then CreateNewText(BarPosition[i], High[i] + TextOffSet,'SecRally', vpTop,FontSize);
     end;
 
    ds4:
     begin
       Color     := clYellow;
       vState[i] := 4;
       if (vState[i-1] <> 4) and ShowText then CreateNewText(BarPosition[i], Low[i] - TextOffSet,'NatReaction', vpBottom,FontSize);
     end;
 
    ds5:
     begin
     Color       := clPurple;
     vState[i]   := 5;
     if (vState[i-1] <> 5) and ShowText then CreateNewText(BarPosition[i], Low[i] - TextOffSet,'SecReaction', vpBottom,FontSize);
     end;
  end;
   SetParentBarColor(i, Color);
 end;
 
if (TradeTrends) then
 { Trend Rules }
  begin
   case State of
    ds0:
     begin
      vState[i] := 0;
      if isValid(vState[i-1]) and (marketposition(i) = 0) and (vState[i-1] <> 0) then
          begin
            Enterlong(i);
          end;
      if marketposition(i) = -1 then
         ExitShort(i);
    end;
 
    ds1:  {downtrend}
      begin
       if isValid(vState[i-1]) and(marketposition(i) = 0) and (vState[i-1] <> 1) then
         begin
          vState[i] := 1;
           EnterShort(i);
         end;
       if marketposition(i) = 1 then
         ExitLong(i);
      end;
      end;
 
      if marketposition(i) = 1 then begin
        case State of ds2:
        begin
         ExitLong(i);
        end;
        ds3:
        begin
         ExitLong(i);
        end;
        ds4:
        begin
         ExitLong(i);
        end;
        ds5:
        begin
         ExitLong(i);
        end;
      end;
      end else
      if marketposition(i) = -1 then begin
        case State of ds2:
        begin
         ExitShort(i);
        end;
        ds3:
        begin
         ExitShort(i);
        end;
        ds4:
        begin
         ExitShort(i);
        end;
        ds5:
        begin
         ExitShort(i);
        end;
        end;
     end;
   end;
end;
 
if ShowPivotDots then begin
with CreateLine(UpTrendPivot) do
  begin
    Name                                                               :='UpTrendPivot';
    Color                                                              := clRed;
    linetype                                                           := ltDot;
    width                                                              := 3;
  end;
  with CreateLine(DnTrendPivot) do
  begin
    Name                                                               :='DnTrendPivot';
    Color                                                              := clBlack;
    linetype                                                           := ltDot;
    width                                                              := 3;
  end;
  with CreateLine(NatReactionPivot) do
  begin
    Name                                                               :='NatReactionPivot';
    Color                                                              := clRed;
    linetype                                                           := ltDot;
    width                                                              := 3;
  end;
   with CreateLine(NatRallyPivot) do
  begin
    Name                                                               :='NatRallyPivot';
    Color                                                              := clBlack;
    linetype                                                           := ltDot;
    width                                                              := 3;
  end;
end;
END.
Laatst gewijzigd door Eric op do okt 11, 2007 8:55 pm, 2 keer totaal gewijzigd.
Eric
Berichten: 3332
Lid geworden op: za sep 10, 2005 2:41 am
Locatie: Den Haag

Bericht door Eric »

Handelssystemen en technische analyse door Rombout Kerstens

Code: Selecteer alles

{- Filename: Three White Soldiers Trendfilter -}

const
  sHelpText = 'Three white soldiers + MA Trend)';

var
  i, TP, TradePeriode, Trendma: integer;
  TMA: Tseries;
begin
  // Indicator definitie
  with Indicator do
  begin
    ShortName := 'Three white soldiers + MA Trend';
    NewBand := false;
    SignalView := svShowInMain;
    HelpText := sHelpText;
  end;
  TradePeriode :=  CreateParameterInteger('Aantal Bars Exit', 1, 100, 2, true);
  Trendma :=  CreateParameterInteger('MA Trendfilter', 1, 250, 60, true);
  Indicator.RequiredBars := Trendma;
  TMA := CreateSeries(Barcount);
  TMA := MA(Close, maSimple, Trendma);
  for i:=MaxInt(2, FirstValidIndex(TMA)+1) to BarCount-1 do
  begin
    if (close[i]> open[i]) and (close[i-1]>open[i-1]) and (close[i-2]>open[i-2])
    and (close[i]>close[i-1]) and (close[i-1]> close[i-2])
    and (TMA[i]>TMA[i-1]) // check voor stijgende trend
    then
      begin
        EnterLong(i); TP :=0;
      end
    else
    TP:= TP+1;
    if TP=TradePeriode then ExitLong(i);
  end;
end.




Code: Selecteer alles

{- Filename: Bollinger Bandit -} 

var 
  BBPeriode, ROCPeriode, LiqPeriode, i, MP, liqDays: integer; 
  sUpperBand, sLowerBand, sROC, sMA: TSeries; 
  upBandCrossings, dnBandCrossings: TLineCrossings; 
begin 
{ Indicator parameters } 
  BBPeriode := CreateParameterInteger('Bollinger Band periode', 1, 999, 50, true); 
  LiqPeriode := CreateParameterInteger('LiqDays periode', 1, 999, 50, true); 
  ROCPeriode := CreateParameterInteger('ROC periode', 1, 999, 30, true); 

{ Indicator eigenschappen } 
  with Indicator do 
  begin 
{ Aantal benodigde koersen om eerste indicatorwaarde te berekenen } 
    RequiredBars := BBPeriode+50; 
    SignalView := svShowInMain; 
    NewBand := false; 
    ScaleRange := srCommon; 
  end; 

{ Indicator berekening } 
  sUpperBand := BollingerBand(Close, BBPeriode, maSimple, 1.25); 
  sLowerBand := BollingerBand(Close, BBPeriode, maSimple, -1.25); 
  sROC := ROC(Close, ROCPeriode); 

  upBandCrossings := Crossings(High, sUpperBand); 
  dnBandCrossings := Crossings(Low, sLowerBand); 

  MP := 0; 
  liqDays := 50; 
  for i:=FirstValidIndex(sUpperBand) to BarCount-1 do 
  begin 
    MP := MarketPosition(i); 
    if (MP <> 1) and (sROC[i] > 0) and (upBandCrossings[i] = lc1Over2) then 
    begin 
      EnterLong(i); 
    end else 
    if (MP <> -1) and (sROC[i] < 0) and (dnBandCrossings[i] = lc2Over1) then 
    begin 
      EnterShort(i); 
    end; 

    if MP = 0 then 
      liqDays := 50 
    else 
    begin 
      liqDays := MaxInt(liqDays-1, 10); 
      sMA := MA(Close, maSimple, liqDays); 
      if IsValid(sMA[i]) then 
      begin 
        if (MP = 1) and (sMA[i] < sUpperBand[i]) and (Close[i] < sMA[i]) then ExitLong(i); 
        if (MP = -1) and (sMA[i] > sLowerBand[i]) and (Close[i] > sMA[i]) then ExitShort(i); 
      end; 
    end; 
  end; 

  with CreateLine(sUpperBand) do 
  begin 
    Name := 'Upper Band'; 
    Color := clGray; 
  end; 
  with CreateLine(sLowerBand) do 
  begin 
    Name := 'Lower Band'; 
    Color := clGray; 
  end; 
end.
Eric
Berichten: 3332
Lid geworden op: za sep 10, 2005 2:41 am
Locatie: Den Haag

Bericht door Eric »

Update 15/10: de Double Stochastic van Michael Ahrens is hierboven vervangen door de Double Stochastics (dual), waarmee twee Double Stochastics (5-bar en 10-bar) in dezelfde sectie worden getekend. De afbeeldingen bij het artikel van Ahrens laten dit ook zo zien.
Plaats reactie