Bollinger Bandit

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

Bollinger Bandit

Bericht door Eric » ma jun 19, 2006 11:19 am

Voor meer informatie zie o.a. http://www.trading-naked.com/library/Bo ... rategy.pdf

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.

Plaats reactie