Pivot Points (Intraday)

Stel hier uw vragen over TA-script, of help anderen met het oplossen van hun probleem
Eric
Berichten: 3678
Lid geworden op: za sep 10, 2005 2:41 am
Locatie: Den Haag

Re: Pivot Points (Intraday)

Bericht door Eric »

Code: Selecteer alles

{- Filename: Pivot Points Month - Day Signals -}

function DTtoWeek(DT: TDateTime): integer;
begin
  while DayOfWeek(DT) <> 2 do DT := DT-1;  // bepaal laatste maandag
  Result := trunc(DT);
end;

function DTtoMonth(DT: TDateTime): integer;
var
  Y, M, D: integer;
begin
  DecodeDate(DT, Y, M, D);
  Result := Y*12+M;
end;

var
  i, LastPeriod, NewPeriod, StartPeriod, PeriodType, SignalMode: integer;
  PivotPP, PivotR1, PivotR2, PivotR3, PivotS1, PivotS2, PivotS3: TSeries;
  PivotMR1, PivotMR2, PivotMR3, PivotMS1, PivotMS2, PivotMS3, sCheck: TSeries;
  LastHigh, LastLow, LastClose, Avg: real;
  ShowMidline: boolean;
begin
  PeriodType := CreateParameterSelect('Type', 'Week'#9'Maand', 1, false);
  SignalMode := CreateParameterSelect('Signaal bij raken',
    'Geen signalen'#9'R3'#9'R2'#9'R1'#9'PP'#9'S1'#9'S2'#9'S3', 0, false);
  ShowMidLine := CreateParameterBoolean ('Show MidLines', true, false);

{ Indicator eigenschappen }
  with Indicator do
  begin
    RequiredBars := 100;
    NewBand := false;
    ScaleRange := srCommon;
    SignalView := svShowInMain;
    HiddenParams := true;
  end;

  LastPeriod := -1;
  PivotPP := CreateSeries(BarCount);
  PivotR1 := CreateSeries(BarCount);
  PivotR2 := CreateSeries(BarCount);
  PivotR3 := CreateSeries(BarCount);
  PivotS1 := CreateSeries(BarCount);
  PivotS2 := CreateSeries(BarCount);
  PivotS3 := CreateSeries(BarCount);
  PivotMR1 := CreateSeries(BarCount);
  PivotMR2 := CreateSeries(BarCount);
  PivotMR3 := CreateSeries(BarCount);
  PivotMS1 := CreateSeries(BarCount);
  PivotMS2 := CreateSeries(BarCount);
  PivotMS3 := CreateSeries(BarCount);

  if BarCount > 0 then
  begin
    case PeriodType of
      0: NewPeriod := DTtoWeek(DateTime[BarCount-1]);
      else NewPeriod := DTtoMonth(DateTime[BarCount-1]);
    end;

    StartPeriod := NewPeriod - 14;

    for i:=0 to BarCount-1 do
    begin
      if i > 0 then
      begin
        PivotPP[i] := PivotPP[i-1];
        PivotR1[i] := PivotR1[i-1];
        PivotR2[i] := PivotR2[i-1];
        PivotR3[i] := PivotR3[i-1];
        PivotS1[i] := PivotS1[i-1];
        PivotS2[i] := PivotS2[i-1];
        PivotS3[i] := PivotS3[i-1];
        PivotMR1[i] := PivotMR1[i-1];
        PivotMR2[i] := PivotMR2[i-1];
        PivotMR3[i] := PivotMR3[i-1];
        PivotMS1[i] := PivotMS1[i-1];
        PivotMS2[i] := PivotMS2[i-1];
        PivotMS3[i] := PivotMS3[i-1];
      end;

      case PeriodType of
        0: NewPeriod := DTtoWeek(DateTime[i]);
        else NewPeriod := DTtoMonth(DateTime[i]);
      end;
      if NewPeriod <> LastPeriod then
      begin
        if LastPeriod > 0 then
        begin
          Avg := (LastHigh + LastLow + LastClose) / 3;

          PivotPP[i] := Avg;
          PivotR1[i] := 2*Avg - LastLow;
          PivotR2[i] := Avg + LastHigh - LastLow;
          PivotR3[i] := LastHigh + 2*(Avg - LastLow);
          PivotS1[i] := 2*Avg - LastHigh;
          PivotS2[i] := Avg - LastHigh + LastLow;
          PivotS3[i] := LastLow - 2*(LastHigh - Avg);
          if ShowMidline then
          begin
            PivotMR1[i] := (PivotPP[i]+PivotR1[i])/2;
            PivotMR2[i] := (PivotR1[i]+PivotR2[i])/2;
            PivotMR3[i] := (PivotR2[i]+PivotR3[i])/2;
            PivotMS1[i] := (PivotPP[i]+PivotS1[i])/2;
            PivotMS2[i] := (PivotS1[i]+PivotS2[i])/2;
            PivotMS3[i] := (PivotS2[i]+PivotS3[i])/2;
          end;
        end;
        LastPeriod := NewPeriod;
        LastHigh := High[i];
        LastLow := Low[i];
        LastClose := Close[i];
      end else
      begin
        LastHigh := Max(LastHigh, High[i]);
        LastLow := Min(LastLow, Low[i]);
        LastClose := Close[i];
      end;
    end;
  end;

  case SignalMode of
    1: sCheck := PivotR3;
    2: sCheck := PivotR2;
    3: sCheck := PivotR1;
    4: sCheck := PivotPP;
    5: sCheck := PivotS1;
    6: sCheck := PivotS2;
    7: sCheck := PivotS3;
    else sCheck := CreateSeries(BarCount);
  end;
  for i:=FirstValidIndex(sCheck) to BarCount-1 do
  begin
    if (sCheck[i] >= Low[i]) and (sCheck[i] <= High[i]) then Mark(i);
  end;

  with CreateLine(PivotPP) do
  begin
    Name := 'PP';
    Color := clAqua;
    Width := 2;
  end;
  with CreateLine(PivotR1) do
  begin
    Name := 'R1';
    Color := clRed;
  end;
  with CreateLine(PivotS1) do
  begin
    Name := 'S1';
    Color := clLime;
  end;
  with CreateLine(PivotR2) do
  begin
    Name := 'R2';
    Color := clRed;
  end;
  with CreateLine(PivotS2) do
  begin
    Name := 'S2';
    Color := clLime;
  end;
  with CreateLine(PivotR3) do
  begin
    Name := 'R3';
    Color := clRed;
  end;
  with CreateLine(PivotS3) do
  begin
    Name := 'S3';
    Color := clLime;
  end;
  with CreateLine(PivotMR1) do
  begin
    Name := 'MR1';
    Color := clSilver;
  end;
  with CreateLine(PivotMS1) do
  begin
    Name := 'MS1';
    Color := clSilver;
  end;
  with CreateLine(PivotMR2) do
  begin
    Name := 'MR2';
    Color := clSilver;
  end;
  with CreateLine(PivotMS2) do
  begin
    Name := 'MS2';
    Color := clSilver;
  end;
  with CreateLine(PivotMR3) do
  begin
    Name := 'MR3';
    Color := clSilver;
  end;
  with CreateLine(PivotMS3) do
  begin
    Name := 'MS3';
    Color := clSilver;
  end;
end.
Lijnen onzichtbaar maken kan natuurlijk ook altijd door op de lijn te dubbelklikken en zichtbaar uit te vinken.

help.png

Te hoge verwachtingen zijn vaak de oorzaak van een teleurstelling, maar ik geef de voorkeur aan het vermelden van wensen bij het verzoek boven het bijhouden van een lijstje met standaardwensen. :)

---
Eric
Optiontrader
Berichten: 396
Lid geworden op: ma jan 01, 2007 8:41 pm

Re: Pivot Points (Intraday)

Bericht door Optiontrader »

Hi Eric, natuurlijk en begrijpelijk, dank wederom, groet OT
Plaats reactie