TA script voor Bullish engulfing candlestick

Stel hier uw vragen over TA-script, of help anderen met het oplossen van hun probleem
Plaats reactie
TA Snarf
Berichten: 20
Lid geworden op: ma jan 29, 2024 3:40 pm

TA script voor Bullish engulfing candlestick

Bericht door TA Snarf »

Hallo Eric,
Louis verwees me door naar het forum om onderstaande vraag te stellen.

Ik zou graag de Bullish engulfing candlestick aan een TA report toe voegen. De TAR waarde moet als advies geven waar of niet waar. Waar heeft dan bijv. waarde = 1 en niet waar = 0. Op het moment dat er nu een geel bolletje op de candlestick wordt geplaatst is het waar. In de andere gevallen niet waar.
Bestaat hier een script voor dat ik kan toevoegen aan de TA reporter?

Met vriendelijke groeten,
Frans
Eric
Berichten: 3575
Lid geworden op: za sep 10, 2005 2:41 am
Locatie: Den Haag

Re: TA script voor Bullish engulfing candlestick

Bericht door Eric »

Hierbij de code voor deze indicator.

Code: Selecteer alles

{- Filename: Bullish Engulfing -}
  
var
  MinPriceChange,
  SmallBodyMaximum,
  LargeBodyMinimum: real;

procedure SetMinPriceChange(Chg: real);
begin
  MinPriceChange := Chg;
  SmallBodyMaximum := Chg / 10;
  LargeBodyMinimum := Chg / 2;
end;

(* BODY COLORS *)

function WhiteBody(BarNr: integer): boolean;
begin
  Result := Close[BarNr] >= Open[BarNr];
end;
  
function BlackBody(BarNr: integer): boolean;
begin
  Result := Close[BarNr] <= Open[BarNr];
end;

(* BODY SIZES *)

function SmallBody(BarNr: integer): boolean;
begin
  Result := ((Open[BarNr] >= Close[BarNr]*(1-smallBodyMaximum)) and (Close[BarNr] >= Open[BarNr])) or
            ((Close[BarNr] >= Open[BarNr]*(1-smallBodyMaximum)) and (Close[BarNr] <= Open[BarNr]));
end;

function LargeBody(BarNr: integer): boolean;
begin
  Result := ((Close[BarNr] >= Open[BarNr]*(1+largeBodyMinimum)) and (Close[BarNr] >= Open[BarNr])) or
            ((Close[BarNr] <= Open[BarNr]*(1-largeBodyMinimum)) and (Close[BarNr] <= Open[BarNr]));
end;

function IdenticalBodies(BarNr: integer): boolean;
begin
  if BarNr > 0 then
    Result := Abs(Abs(Open[BarNr-1] - Close[BarNr-1]) - Abs(Open[BarNr] - Close[BarNr]))
              < Abs(Open[BarNr] - Close[BarNr])*smallBodyMaximum
  else
    Result := false;
end;

function RealBodySize(BarNr: integer): real;
begin
  Result := Abs(Open[BarNr] - Close[BarNr]);
end;

(* SHADOWS *)

function SmallUpperShadow(BarNr: integer): boolean;
begin
  Result := (WhiteBody(BarNr) and (High[BarNr] <= Close[BarNr] *(1+smallBodyMaximum))) or
            (BlackBody(BarNr) and (High[BarNr] <= Open[BarNr] *(1+smallBodyMaximum)));
end;

function SmallLowerShadow(BarNr: integer): boolean;
begin
  Result := (WhiteBody(BarNr) and (Low[BarNr] >= Open[BarNr] *(1-smallBodyMaximum))) or
            (BlackBody(BarNr) and (Low[BarNr] >= Close[BarNr] *(1-smallBodyMaximum)));
end;

function LargeUpperShadow(BarNr: integer): boolean;
begin
  Result := (WhiteBody(BarNr) and (High[BarNr] >= Close[BarNr] *(1+largeBodyMinimum))) or
            (BlackBody(BarNr) and (High[BarNr] <= Open[BarNr] *(1+largeBodyMinimum)));
end;

function LargeLowerShadow(BarNr: integer): boolean;
begin
  Result := (WhiteBody(BarNr) and (Low[BarNr] <= Open[BarNr] *(1-largeBodyMinimum))) or
            (BlackBody(BarNr) and (Low[BarNr] <= Close[BarNr] *(1-largeBodyMinimum)));
end;

(* GAPS *)

function GapUp(BarNr: integer): boolean;
begin
  if BarNr > 0 then
    Result :=
      (BlackBody(BarNr-1) and WhiteBody(BarNr) and (Open[BarNr] > Open[BarNr-1])) or
      (Blackbody(BarNr-1) and BlackBody(BarNr) and (Close[BarNr] > Open[BarNr-1])) or
      (WhiteBody(BarNr-1) and WhiteBody(BarNr) and (Open[BarNr] > Close[BarNr-1])) or
      (WhiteBody(BarNr-1) and BlackBody(BarNr) and (Close[BarNr] > Close[BarNr-1]))
  else
    Result := false;
end;

function GapDown(BarNr: integer): boolean;
begin
  if BarNr > 0 then
    Result :=
      (BlackBody(BarNr-1) and WhiteBody(BarNr) and (Close[BarNr] < Close[BarNr-1])) or
      (Blackbody(BarNr-1) and BlackBody(BarNr) and (Open[BarNr] < Close[BarNr-1])) or
      (WhiteBody(BarNr-1) and WhiteBody(BarNr) and (Close[BarNr] < Open[BarNr-1])) or
      (WhiteBody(BarNr-1) and BlackBody(BarNr) and (Open[BarNr] < Open[BarNr-1]))
  else
    Result := false;
end;

function Harami(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and
            ((BlackBody(BarNr) and BlackBody(BarNr-1) and
             ( Open[BarNr] < Open[BarNr-1] ) and
             (Close[BarNr] > Close[BarNr-1])) or
            (BlackBody(BarNr) and WhiteBody(BarNr-1) and
             (Close[BarNr] > Open[BarNr-1] ) and
             ( Open[BarNr] < Close[BarNr-1])) or
            (WhiteBody(BarNr) and WhiteBody(BarNr-1) and
             (Close[BarNr] < Close[BarNr-1]) and
             ( Open[BarNr] > Open[BarNr-1] )) or
            (WhiteBody(BarNr) and BlackBody(BarNr-1) and
             ( Open[BarNr] > Close[BarNr-1]) and
             (Close[BarNr] < Open[BarNr-1] )));
end;

function Engulfing(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and
            ((BlackBody(BarNr) and Blackbody(BarNr-1) and
              (Close[BarNr] < Close[BarNr-1]) and
              ( Open[BarNr] > Open[BarNr-1] )) or
             (BlackBody(BarNr) and WhiteBody(BarNr-1) and
              ( Open[BarNr] > Close[BarNr-1]) and
              (Close[BarNr] < Open[BarNr-1] )) or
             (Whitebody(BarNr) and Whitebody(BarNr-1) and
              (Close[BarNr] > Close[BarNr-1]) and
              ( Open[BarNr] < Open[BarNr-1] )) or
             (WhiteBody(BarNr) and BlackBody(BarNr-1) and
              (Close[BarNr] > Open[BarNr-1] ) and
              ( Open[BarNr] < Close[BarNr-1])));
end;

(* Min / Max functions *)

function MaxHigh5(BarNr: integer): boolean;
begin
  Result := HighestIndex(High, BarNr-4, BarNr) = BarNr;
end;

function MinLow5(BarNr: integer): boolean;
begin
  Result := LowestIndex(Low, BarNr-4, BarNr) = BarNr;
end;

(* CANDLE FUNCTIONS *)

function BearishEngulfing(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and
             BlackBody(BarNr) and WhiteBody(BarNr-1) and
             (Close[BarNr] < Open[BarNr-1] ) and
             ( Open[BarNr] > Close[BarNr-1]);
end;

function BullishEngulfing(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and
             WhiteBody(BarNr) and BlackBody(BarNr-1) and
             (Close[BarNr] > Open[BarNr-1] ) and
             ( Open[BarNr] < Close[BarNr-1]);
end;

function Doji(BarNr: integer): boolean;
begin
  Result := Abs(Close[BarNr] - Open[BarNr]) <=
            Max(Close[BarNr]*SmallBodyMaximum, (High[BarNr] - Low[BarNr])*0.1);
end;

function DragonflyDoji(BarNr: integer): boolean;
begin
  Result := Doji(BarNr) and
            ((High[BarNr]-Open[BarNr]) < Close[BarNr]*SmallBodyMaximum);
end;

function GravestoneDoji(BarNr: integer): boolean;
begin
  Result := Doji(BarNr) and
            ((Open[BarNr]-Low[BarNr]) < Close[BarNr]*SmallBodyMaximum);
end;

function DojiStar(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and
            Doji(BarNr) and
            LargeBody(BarNr-1) and
            (GapUp(BarNr) or GapDown(BarNr));
end;

function DojiStarBearish(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and
            ((DojiStar(BarNr) and (MaxHigh5(BarNr) or MaxHigh5(BarNr-1))) or
             (Doji(BarNr) and
              ((Close[BarNr] > Close[BarNr-1]) or (Open[BarNr] > Close[BarNr-1])) and
              WhiteBody(BarNr-1) and
              LargeBody(BarNr-1)));
end;

function MaruBozu(BarNr: integer): boolean;
begin
  Result := LargeBody(BarNr) and smallUpperShadow(BarNr) and smallLowerShadow(BarNr);
end;

function DarkCloudCover(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and WhiteBody(BarNr-1) and
            BlackBody(BarNr) and
            (Close[BarNr] <= (Open[BarNr-1]+Close[BarNr-1])/2) and
            (Close[BarNr] > Open[BarNr-1]) and
            (Open[BarNr] > Close[BarNr-1]);
end;

function PiercingLine(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and BlackBody(BarNr-1) and
    WhiteBody(BarNr) and
    (Close[BarNr] >= ((Open[BarNr-1]+Close[BarNr-1])/2)) and
    (Close[BarNr] < Open[BarNr-1]) and
    (Open[BarNr] < Close[BarNr-1]);
end;

{ Shooting Star and Hammer are inverted patterns }

function ShootingStar(BarNr: integer): boolean;
begin
  Result := SmallLowerShadow(BarNr) and not Doji(BarNr) and
            ((BlackBody(BarNr) and (Abs(Open[BarNr]-High[BarNr]) > 2*RealBodySize(BarNr))) or
             (WhiteBody(BarNr) and (Abs(High[BarNr]-Close[BarNr]) > 2*RealBodySize(BarNr))));
end;

function Hammer(BarNr: integer): boolean;
begin
  Result := SmallUpperShadow(BarNr) and not Doji(BarNr) and
            ((BlackBody(BarNr) and (Abs(Close[BarNr]-Low[BarNr]) > 2*RealBodySize(BarNr))) or
             (WhiteBody(BarNr) and (Abs(Low[BarNr]-Open[BarNr]) > 2*RealBodySize(BarNr))));
end;

{ Morning Star and Evening Star are inverted patterns }

function MorningStar(BarNr: integer): boolean;
begin
  Result := (BarNr > 1) and
            BlackBody(BarNr-2) and LargeBody(BarNr-2) and
            GapDown(BarNr-1) and
            MinLow5(BarNr-1) and
            WhiteBody(BarNr) and LargeBody(BarNr) and
            (Close[BarNr] > (Open[BarNr-2] + Close[BarNr-2])/2);
end;

function EveningStar(BarNr: integer): boolean;
begin
  Result := (BarNr > 1) and
            WhiteBody(BarNr-2) and LargeBody(BarNr-2) and
            GapUp(BarNr-1) and
            MaxHigh5(BarNr-1) and
            BlackBody(BarNr) and LargeBody(BarNr) and
            (Close[BarNr] < (Open[BarNr-2] + Close[BarNr-2])/2);
end;

function ThreeBlackCrows(BarNr: integer): boolean;
begin
  Result := (BarNr > 2) and
            BlackBody(BarNr-2) and not SmallBody(BarNr-2) and
            BlackBody(BarNr-1) and not SmallBody(BarNr-1) and
            BlackBody(BarNr) and not SmallBody(BarNr) and
            (Close[BarNr] < Close[BarNr-1]) and
            (Close[BarNr-1] < Close[BarNr-2]) and
            (Open[BarNr-1] < Open[BarNr-2]) and
            (Open[BarNr] < Open[BarNr-1]) and
            (Open[BarNr-1] > Close[BarNr-2]) and
            (Open[BarNr] > Close[BarNr-1]) and
            SmallLowerShadow(BarNr-2) and
            SmallLowerShadow(BarNr-1) and
            SmallLowerShadow(BarNr);
end;

function ThreeWhiteSoldiers(BarNr: integer): boolean;
begin
  Result := (BarNr > 2) and
            WhiteBody(BarNr-2) and not SmallBody(BarNr-2) and
            WhiteBody(BarNr-1) and not SmallBody(BarNr-1) and
            WhiteBody(BarNr) and not SmallBody(BarNr) and
            (Close[BarNr] > Close[BarNr-1]) and
            (Close[BarNr-1] > Close[BarNr-2]) and
            (Open[BarNr-1] > Open[BarNr-2]) and
            (Open[BarNr] > Open[BarNr-1]) and
            (Open[BarNr-1] < Close[BarNr-2]) and
            (Open[BarNr] < Close[BarNr-1]) and
            SmallUpperShadow(BarNr-2) and
            SmallUpperShadow(BarNr-1) and
            SmallUpperShadow(BarNr);
end;

var
  i: integer;
  Values: TSeries;
begin
  SetMinPriceChange(0.01);
  
  with Indicator do
  begin 
    NewBand := false;
    SignalView := svShowInMain; 
  end;

  Values := FillSeries(CreateSeries(BarCount), 0);
  for i:=0 to BarCount-1 do
  begin
    if BullishEngulfing(i) then
    begin
      Mark(i);
      Values[i] := 1;
    end;
  end;
  
  with CreateLine(Values) do
  begin
    Visible := false;
    LineContent := lcTAR;
    Name := 'TAR';
  end;
end.
---
Eric
TA Snarf
Berichten: 20
Lid geworden op: ma jan 29, 2024 3:40 pm

TA script voor Bearish engulfing candlestick

Bericht door TA Snarf »

Bedankt Eric voor de snelle reactie m.b.t. het script voor de Bullish engulfing candlestick.
Heb je het TA script voor de Bearish engulfing candlestick ook?
TA Snarf
Berichten: 20
Lid geworden op: ma jan 29, 2024 3:40 pm

Re: TA script voor Bullish engulfing candlestick

Bericht door TA Snarf »

Bedankt voor de snelle reactie Eric.
Eric
Berichten: 3575
Lid geworden op: za sep 10, 2005 2:41 am
Locatie: Den Haag

Re: TA script voor Bullish engulfing candlestick

Bericht door Eric »

En de Bearish:

Code: Selecteer alles

{- Filename: Bearish Engulfing -}
  
var
  MinPriceChange,
  SmallBodyMaximum,
  LargeBodyMinimum: real;

procedure SetMinPriceChange(Chg: real);
begin
  MinPriceChange := Chg;
  SmallBodyMaximum := Chg / 10;
  LargeBodyMinimum := Chg / 2;
end;

(* BODY COLORS *)

function WhiteBody(BarNr: integer): boolean;
begin
  Result := Close[BarNr] >= Open[BarNr];
end;
  
function BlackBody(BarNr: integer): boolean;
begin
  Result := Close[BarNr] <= Open[BarNr];
end;

(* BODY SIZES *)

function SmallBody(BarNr: integer): boolean;
begin
  Result := ((Open[BarNr] >= Close[BarNr]*(1-smallBodyMaximum)) and (Close[BarNr] >= Open[BarNr])) or
            ((Close[BarNr] >= Open[BarNr]*(1-smallBodyMaximum)) and (Close[BarNr] <= Open[BarNr]));
end;

function LargeBody(BarNr: integer): boolean;
begin
  Result := ((Close[BarNr] >= Open[BarNr]*(1+largeBodyMinimum)) and (Close[BarNr] >= Open[BarNr])) or
            ((Close[BarNr] <= Open[BarNr]*(1-largeBodyMinimum)) and (Close[BarNr] <= Open[BarNr]));
end;

function IdenticalBodies(BarNr: integer): boolean;
begin
  if BarNr > 0 then
    Result := Abs(Abs(Open[BarNr-1] - Close[BarNr-1]) - Abs(Open[BarNr] - Close[BarNr]))
              < Abs(Open[BarNr] - Close[BarNr])*smallBodyMaximum
  else
    Result := false;
end;

function RealBodySize(BarNr: integer): real;
begin
  Result := Abs(Open[BarNr] - Close[BarNr]);
end;

(* SHADOWS *)

function SmallUpperShadow(BarNr: integer): boolean;
begin
  Result := (WhiteBody(BarNr) and (High[BarNr] <= Close[BarNr] *(1+smallBodyMaximum))) or
            (BlackBody(BarNr) and (High[BarNr] <= Open[BarNr] *(1+smallBodyMaximum)));
end;

function SmallLowerShadow(BarNr: integer): boolean;
begin
  Result := (WhiteBody(BarNr) and (Low[BarNr] >= Open[BarNr] *(1-smallBodyMaximum))) or
            (BlackBody(BarNr) and (Low[BarNr] >= Close[BarNr] *(1-smallBodyMaximum)));
end;

function LargeUpperShadow(BarNr: integer): boolean;
begin
  Result := (WhiteBody(BarNr) and (High[BarNr] >= Close[BarNr] *(1+largeBodyMinimum))) or
            (BlackBody(BarNr) and (High[BarNr] <= Open[BarNr] *(1+largeBodyMinimum)));
end;

function LargeLowerShadow(BarNr: integer): boolean;
begin
  Result := (WhiteBody(BarNr) and (Low[BarNr] <= Open[BarNr] *(1-largeBodyMinimum))) or
            (BlackBody(BarNr) and (Low[BarNr] <= Close[BarNr] *(1-largeBodyMinimum)));
end;

(* GAPS *)

function GapUp(BarNr: integer): boolean;
begin
  if BarNr > 0 then
    Result :=
      (BlackBody(BarNr-1) and WhiteBody(BarNr) and (Open[BarNr] > Open[BarNr-1])) or
      (Blackbody(BarNr-1) and BlackBody(BarNr) and (Close[BarNr] > Open[BarNr-1])) or
      (WhiteBody(BarNr-1) and WhiteBody(BarNr) and (Open[BarNr] > Close[BarNr-1])) or
      (WhiteBody(BarNr-1) and BlackBody(BarNr) and (Close[BarNr] > Close[BarNr-1]))
  else
    Result := false;
end;

function GapDown(BarNr: integer): boolean;
begin
  if BarNr > 0 then
    Result :=
      (BlackBody(BarNr-1) and WhiteBody(BarNr) and (Close[BarNr] < Close[BarNr-1])) or
      (Blackbody(BarNr-1) and BlackBody(BarNr) and (Open[BarNr] < Close[BarNr-1])) or
      (WhiteBody(BarNr-1) and WhiteBody(BarNr) and (Close[BarNr] < Open[BarNr-1])) or
      (WhiteBody(BarNr-1) and BlackBody(BarNr) and (Open[BarNr] < Open[BarNr-1]))
  else
    Result := false;
end;

function Harami(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and
            ((BlackBody(BarNr) and BlackBody(BarNr-1) and
             ( Open[BarNr] < Open[BarNr-1] ) and
             (Close[BarNr] > Close[BarNr-1])) or
            (BlackBody(BarNr) and WhiteBody(BarNr-1) and
             (Close[BarNr] > Open[BarNr-1] ) and
             ( Open[BarNr] < Close[BarNr-1])) or
            (WhiteBody(BarNr) and WhiteBody(BarNr-1) and
             (Close[BarNr] < Close[BarNr-1]) and
             ( Open[BarNr] > Open[BarNr-1] )) or
            (WhiteBody(BarNr) and BlackBody(BarNr-1) and
             ( Open[BarNr] > Close[BarNr-1]) and
             (Close[BarNr] < Open[BarNr-1] )));
end;

function Engulfing(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and
            ((BlackBody(BarNr) and Blackbody(BarNr-1) and
              (Close[BarNr] < Close[BarNr-1]) and
              ( Open[BarNr] > Open[BarNr-1] )) or
             (BlackBody(BarNr) and WhiteBody(BarNr-1) and
              ( Open[BarNr] > Close[BarNr-1]) and
              (Close[BarNr] < Open[BarNr-1] )) or
             (Whitebody(BarNr) and Whitebody(BarNr-1) and
              (Close[BarNr] > Close[BarNr-1]) and
              ( Open[BarNr] < Open[BarNr-1] )) or
             (WhiteBody(BarNr) and BlackBody(BarNr-1) and
              (Close[BarNr] > Open[BarNr-1] ) and
              ( Open[BarNr] < Close[BarNr-1])));
end;

(* Min / Max functions *)

function MaxHigh5(BarNr: integer): boolean;
begin
  Result := HighestIndex(High, BarNr-4, BarNr) = BarNr;
end;

function MinLow5(BarNr: integer): boolean;
begin
  Result := LowestIndex(Low, BarNr-4, BarNr) = BarNr;
end;

(* CANDLE FUNCTIONS *)

function BearishEngulfing(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and
             BlackBody(BarNr) and WhiteBody(BarNr-1) and
             (Close[BarNr] < Open[BarNr-1] ) and
             ( Open[BarNr] > Close[BarNr-1]);
end;

function BullishEngulfing(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and
             WhiteBody(BarNr) and BlackBody(BarNr-1) and
             (Close[BarNr] > Open[BarNr-1] ) and
             ( Open[BarNr] < Close[BarNr-1]);
end;

function Doji(BarNr: integer): boolean;
begin
  Result := Abs(Close[BarNr] - Open[BarNr]) <=
            Max(Close[BarNr]*SmallBodyMaximum, (High[BarNr] - Low[BarNr])*0.1);
end;

function DragonflyDoji(BarNr: integer): boolean;
begin
  Result := Doji(BarNr) and
            ((High[BarNr]-Open[BarNr]) < Close[BarNr]*SmallBodyMaximum);
end;

function GravestoneDoji(BarNr: integer): boolean;
begin
  Result := Doji(BarNr) and
            ((Open[BarNr]-Low[BarNr]) < Close[BarNr]*SmallBodyMaximum);
end;

function DojiStar(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and
            Doji(BarNr) and
            LargeBody(BarNr-1) and
            (GapUp(BarNr) or GapDown(BarNr));
end;

function DojiStarBearish(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and
            ((DojiStar(BarNr) and (MaxHigh5(BarNr) or MaxHigh5(BarNr-1))) or
             (Doji(BarNr) and
              ((Close[BarNr] > Close[BarNr-1]) or (Open[BarNr] > Close[BarNr-1])) and
              WhiteBody(BarNr-1) and
              LargeBody(BarNr-1)));
end;

function MaruBozu(BarNr: integer): boolean;
begin
  Result := LargeBody(BarNr) and smallUpperShadow(BarNr) and smallLowerShadow(BarNr);
end;

function DarkCloudCover(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and WhiteBody(BarNr-1) and
            BlackBody(BarNr) and
            (Close[BarNr] <= (Open[BarNr-1]+Close[BarNr-1])/2) and
            (Close[BarNr] > Open[BarNr-1]) and
            (Open[BarNr] > Close[BarNr-1]);
end;

function PiercingLine(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and BlackBody(BarNr-1) and
    WhiteBody(BarNr) and
    (Close[BarNr] >= ((Open[BarNr-1]+Close[BarNr-1])/2)) and
    (Close[BarNr] < Open[BarNr-1]) and
    (Open[BarNr] < Close[BarNr-1]);
end;

{ Shooting Star and Hammer are inverted patterns }

function ShootingStar(BarNr: integer): boolean;
begin
  Result := SmallLowerShadow(BarNr) and not Doji(BarNr) and
            ((BlackBody(BarNr) and (Abs(Open[BarNr]-High[BarNr]) > 2*RealBodySize(BarNr))) or
             (WhiteBody(BarNr) and (Abs(High[BarNr]-Close[BarNr]) > 2*RealBodySize(BarNr))));
end;

function Hammer(BarNr: integer): boolean;
begin
  Result := SmallUpperShadow(BarNr) and not Doji(BarNr) and
            ((BlackBody(BarNr) and (Abs(Close[BarNr]-Low[BarNr]) > 2*RealBodySize(BarNr))) or
             (WhiteBody(BarNr) and (Abs(Low[BarNr]-Open[BarNr]) > 2*RealBodySize(BarNr))));
end;

{ Morning Star and Evening Star are inverted patterns }

function MorningStar(BarNr: integer): boolean;
begin
  Result := (BarNr > 1) and
            BlackBody(BarNr-2) and LargeBody(BarNr-2) and
            GapDown(BarNr-1) and
            MinLow5(BarNr-1) and
            WhiteBody(BarNr) and LargeBody(BarNr) and
            (Close[BarNr] > (Open[BarNr-2] + Close[BarNr-2])/2);
end;

function EveningStar(BarNr: integer): boolean;
begin
  Result := (BarNr > 1) and
            WhiteBody(BarNr-2) and LargeBody(BarNr-2) and
            GapUp(BarNr-1) and
            MaxHigh5(BarNr-1) and
            BlackBody(BarNr) and LargeBody(BarNr) and
            (Close[BarNr] < (Open[BarNr-2] + Close[BarNr-2])/2);
end;

function ThreeBlackCrows(BarNr: integer): boolean;
begin
  Result := (BarNr > 2) and
            BlackBody(BarNr-2) and not SmallBody(BarNr-2) and
            BlackBody(BarNr-1) and not SmallBody(BarNr-1) and
            BlackBody(BarNr) and not SmallBody(BarNr) and
            (Close[BarNr] < Close[BarNr-1]) and
            (Close[BarNr-1] < Close[BarNr-2]) and
            (Open[BarNr-1] < Open[BarNr-2]) and
            (Open[BarNr] < Open[BarNr-1]) and
            (Open[BarNr-1] > Close[BarNr-2]) and
            (Open[BarNr] > Close[BarNr-1]) and
            SmallLowerShadow(BarNr-2) and
            SmallLowerShadow(BarNr-1) and
            SmallLowerShadow(BarNr);
end;

function ThreeWhiteSoldiers(BarNr: integer): boolean;
begin
  Result := (BarNr > 2) and
            WhiteBody(BarNr-2) and not SmallBody(BarNr-2) and
            WhiteBody(BarNr-1) and not SmallBody(BarNr-1) and
            WhiteBody(BarNr) and not SmallBody(BarNr) and
            (Close[BarNr] > Close[BarNr-1]) and
            (Close[BarNr-1] > Close[BarNr-2]) and
            (Open[BarNr-1] > Open[BarNr-2]) and
            (Open[BarNr] > Open[BarNr-1]) and
            (Open[BarNr-1] < Close[BarNr-2]) and
            (Open[BarNr] < Close[BarNr-1]) and
            SmallUpperShadow(BarNr-2) and
            SmallUpperShadow(BarNr-1) and
            SmallUpperShadow(BarNr);
end;

var
  i: integer;
  Values: TSeries;
begin
  SetMinPriceChange(0.01);
  
  with Indicator do
  begin 
    NewBand := false;
    SignalView := svShowInMain; 
  end;

  Values := FillSeries(CreateSeries(BarCount), 0);
  for i:=0 to BarCount-1 do
  begin
    if BearishEngulfing(i) then
    begin
      Mark(i);
      Values[i] := 1;
    end;
  end;
  
  with CreateLine(Values) do
  begin
    Visible := false;
    LineContent := lcTAR;
    Name := 'TAR';
  end;
end.
---
Eric
Bakstenen
Berichten: 884
Lid geworden op: zo jul 19, 2015 7:51 pm

Re: TA script voor Bullish engulfing candlestick

Bericht door Bakstenen »

Eric, kan je ook zo iets maken van de Hammer, en de koers mag boven de bovenkant van de hammer uitkomen
Knipsel.JPG
Knipsel.JPG (15.6 KiB) 1514 keer bekeken
Eric
Berichten: 3575
Lid geworden op: za sep 10, 2005 2:41 am
Locatie: Den Haag

Re: TA script voor Bullish engulfing candlestick

Bericht door Eric »

Bakstenen schreef: do feb 01, 2024 6:39 pm Eric, kan je ook zo iets maken van de Hammer, en de koers mag boven de bovenkant van de hammer uitkomen
Knipsel.JPG
Wat heb je precies voor ogen? De specificaties voor bovenstaande indicatoren zijn:
"De TAR waarde moet als advies geven waar of niet waar. Waar heeft dan bijv. waarde = 1 en niet waar = 0. Op het moment dat er nu een geel bolletje op de candlestick wordt geplaatst is het waar. In de andere gevallen niet waar."

Ik kan zoiets ook voor de Hammer maken maar dan krijg je dus een TAR-waarde=1 als er een Hammer is. Wat je bedoelt met "de koers mag boven de bovenkant van de hammer uitkomen" snap ik in dat verband niet.

---
Eric
Bakstenen
Berichten: 884
Lid geworden op: zo jul 19, 2015 7:51 pm

Re: TA script voor Bullish engulfing candlestick

Bericht door Bakstenen »

Officieel mag de koers niet boven het lichaam komen, in normale taal, de koers mag niet terug gaan nadat er een high is , koers high is 100 van mij mag de koers ook sluiten op 95
Mijn gedachten zijn, de koers maakt een low en dan komen er weer kopers
Hier en plaatje wat ik bedoel, waar een pijl bij staat dat zie ik als hammer
Knipsel.JPG
Eric
Berichten: 3575
Lid geworden op: za sep 10, 2005 2:41 am
Locatie: Den Haag

Re: TA script voor Bullish engulfing candlestick

Bericht door Eric »

De condities voor een Hammer in onderstaande indicator zijn:
- de body (open-slot) moet kleiner zijn dan de helft van de onderste shadow (dit is een algemeen gehanteerde voorwaarde voor de Hammer volgens mij);
- de body moet dichtbij de hoog liggen (ik hanteer hiervoor dat de bovenste shadow kleiner dan 1/10 van hoog-laag moet zijn).

Code: Selecteer alles

{- Filename: Hammer -}
  
var
  MinPriceChange,
  SmallBodyMaximum,
  LargeBodyMinimum: real;

procedure SetMinPriceChange(Chg: real);
begin
  MinPriceChange := Chg;
  SmallBodyMaximum := Chg / 10;
  LargeBodyMinimum := Chg / 2;
end;

(* BODY COLORS *)

function WhiteBody(BarNr: integer): boolean;
begin
  Result := Close[BarNr] >= Open[BarNr];
end;
  
function BlackBody(BarNr: integer): boolean;
begin
  Result := Close[BarNr] <= Open[BarNr];
end;

(* BODY SIZES *)

function SmallBody(BarNr: integer): boolean;
begin
  Result := ((Open[BarNr] >= Close[BarNr]*(1-smallBodyMaximum)) and (Close[BarNr] >= Open[BarNr])) or
            ((Close[BarNr] >= Open[BarNr]*(1-smallBodyMaximum)) and (Close[BarNr] <= Open[BarNr]));
end;

function LargeBody(BarNr: integer): boolean;
begin
  Result := ((Close[BarNr] >= Open[BarNr]*(1+largeBodyMinimum)) and (Close[BarNr] >= Open[BarNr])) or
            ((Close[BarNr] <= Open[BarNr]*(1-largeBodyMinimum)) and (Close[BarNr] <= Open[BarNr]));
end;

function IdenticalBodies(BarNr: integer): boolean;
begin
  if BarNr > 0 then
    Result := Abs(Abs(Open[BarNr-1] - Close[BarNr-1]) - Abs(Open[BarNr] - Close[BarNr]))
              < Abs(Open[BarNr] - Close[BarNr])*smallBodyMaximum
  else
    Result := false;
end;

function RealBodySize(BarNr: integer): real;
begin
  Result := Abs(Open[BarNr] - Close[BarNr]);
end;

(* SHADOWS *)

function SmallUpperShadow(BarNr: integer): boolean;
var
  dy: real;
begin
  dy := abs(High[BarNr]-Low[BarNr])/10;
  Result := (WhiteBody(BarNr) and (High[BarNr] <= Close[BarNr] + dy)) or
            (BlackBody(BarNr) and (High[BarNr] <= Open[BarNr] + dy));
end;

function SmallLowerShadow(BarNr: integer): boolean;
begin
  Result := (WhiteBody(BarNr) and (Low[BarNr] >= Open[BarNr] *(1-smallBodyMaximum))) or
            (BlackBody(BarNr) and (Low[BarNr] >= Close[BarNr] *(1-smallBodyMaximum)));
end;

function LargeUpperShadow(BarNr: integer): boolean;
begin
  Result := (WhiteBody(BarNr) and (High[BarNr] >= Close[BarNr] *(1+largeBodyMinimum))) or
            (BlackBody(BarNr) and (High[BarNr] <= Open[BarNr] *(1+largeBodyMinimum)));
end;

function LargeLowerShadow(BarNr: integer): boolean;
begin
  Result := (WhiteBody(BarNr) and (Low[BarNr] <= Open[BarNr] *(1-largeBodyMinimum))) or
            (BlackBody(BarNr) and (Low[BarNr] <= Close[BarNr] *(1-largeBodyMinimum)));
end;

(* GAPS *)

function GapUp(BarNr: integer): boolean;
begin
  if BarNr > 0 then
    Result :=
      (BlackBody(BarNr-1) and WhiteBody(BarNr) and (Open[BarNr] > Open[BarNr-1])) or
      (Blackbody(BarNr-1) and BlackBody(BarNr) and (Close[BarNr] > Open[BarNr-1])) or
      (WhiteBody(BarNr-1) and WhiteBody(BarNr) and (Open[BarNr] > Close[BarNr-1])) or
      (WhiteBody(BarNr-1) and BlackBody(BarNr) and (Close[BarNr] > Close[BarNr-1]))
  else
    Result := false;
end;

function GapDown(BarNr: integer): boolean;
begin
  if BarNr > 0 then
    Result :=
      (BlackBody(BarNr-1) and WhiteBody(BarNr) and (Close[BarNr] < Close[BarNr-1])) or
      (Blackbody(BarNr-1) and BlackBody(BarNr) and (Open[BarNr] < Close[BarNr-1])) or
      (WhiteBody(BarNr-1) and WhiteBody(BarNr) and (Close[BarNr] < Open[BarNr-1])) or
      (WhiteBody(BarNr-1) and BlackBody(BarNr) and (Open[BarNr] < Open[BarNr-1]))
  else
    Result := false;
end;

function Harami(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and
            ((BlackBody(BarNr) and BlackBody(BarNr-1) and
             ( Open[BarNr] < Open[BarNr-1] ) and
             (Close[BarNr] > Close[BarNr-1])) or
            (BlackBody(BarNr) and WhiteBody(BarNr-1) and
             (Close[BarNr] > Open[BarNr-1] ) and
             ( Open[BarNr] < Close[BarNr-1])) or
            (WhiteBody(BarNr) and WhiteBody(BarNr-1) and
             (Close[BarNr] < Close[BarNr-1]) and
             ( Open[BarNr] > Open[BarNr-1] )) or
            (WhiteBody(BarNr) and BlackBody(BarNr-1) and
             ( Open[BarNr] > Close[BarNr-1]) and
             (Close[BarNr] < Open[BarNr-1] )));
end;

function Engulfing(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and
            ((BlackBody(BarNr) and Blackbody(BarNr-1) and
              (Close[BarNr] < Close[BarNr-1]) and
              ( Open[BarNr] > Open[BarNr-1] )) or
             (BlackBody(BarNr) and WhiteBody(BarNr-1) and
              ( Open[BarNr] > Close[BarNr-1]) and
              (Close[BarNr] < Open[BarNr-1] )) or
             (Whitebody(BarNr) and Whitebody(BarNr-1) and
              (Close[BarNr] > Close[BarNr-1]) and
              ( Open[BarNr] < Open[BarNr-1] )) or
             (WhiteBody(BarNr) and BlackBody(BarNr-1) and
              (Close[BarNr] > Open[BarNr-1] ) and
              ( Open[BarNr] < Close[BarNr-1])));
end;

(* Min / Max functions *)

function MaxHigh5(BarNr: integer): boolean;
begin
  Result := HighestIndex(High, BarNr-4, BarNr) = BarNr;
end;

function MinLow5(BarNr: integer): boolean;
begin
  Result := LowestIndex(Low, BarNr-4, BarNr) = BarNr;
end;

(* CANDLE FUNCTIONS *)

function BearishEngulfing(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and
             BlackBody(BarNr) and WhiteBody(BarNr-1) and
             (Close[BarNr] < Open[BarNr-1] ) and
             ( Open[BarNr] > Close[BarNr-1]);
end;

function BullishEngulfing(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and
             WhiteBody(BarNr) and BlackBody(BarNr-1) and
             (Close[BarNr] > Open[BarNr-1] ) and
             ( Open[BarNr] < Close[BarNr-1]);
end;

function Doji(BarNr: integer): boolean;
begin
  Result := Abs(Close[BarNr] - Open[BarNr]) <=
            Max(Close[BarNr]*SmallBodyMaximum, (High[BarNr] - Low[BarNr])*0.1);
end;

function DragonflyDoji(BarNr: integer): boolean;
begin
  Result := Doji(BarNr) and
            ((High[BarNr]-Open[BarNr]) < Close[BarNr]*SmallBodyMaximum);
end;

function GravestoneDoji(BarNr: integer): boolean;
begin
  Result := Doji(BarNr) and
            ((Open[BarNr]-Low[BarNr]) < Close[BarNr]*SmallBodyMaximum);
end;

function DojiStar(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and
            Doji(BarNr) and
            LargeBody(BarNr-1) and
            (GapUp(BarNr) or GapDown(BarNr));
end;

function DojiStarBearish(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and
            ((DojiStar(BarNr) and (MaxHigh5(BarNr) or MaxHigh5(BarNr-1))) or
             (Doji(BarNr) and
              ((Close[BarNr] > Close[BarNr-1]) or (Open[BarNr] > Close[BarNr-1])) and
              WhiteBody(BarNr-1) and
              LargeBody(BarNr-1)));
end;

function MaruBozu(BarNr: integer): boolean;
begin
  Result := LargeBody(BarNr) and smallUpperShadow(BarNr) and smallLowerShadow(BarNr);
end;

function DarkCloudCover(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and WhiteBody(BarNr-1) and
            BlackBody(BarNr) and
            (Close[BarNr] <= (Open[BarNr-1]+Close[BarNr-1])/2) and
            (Close[BarNr] > Open[BarNr-1]) and
            (Open[BarNr] > Close[BarNr-1]);
end;

function PiercingLine(BarNr: integer): boolean;
begin
  Result := (BarNr > 0) and BlackBody(BarNr-1) and
    WhiteBody(BarNr) and
    (Close[BarNr] >= ((Open[BarNr-1]+Close[BarNr-1])/2)) and
    (Close[BarNr] < Open[BarNr-1]) and
    (Open[BarNr] < Close[BarNr-1]);
end;

{ Shooting Star and Hammer are inverted patterns }

function ShootingStar(BarNr: integer): boolean;
begin
  Result := SmallLowerShadow(BarNr) and not Doji(BarNr) and
            ((BlackBody(BarNr) and (Abs(Open[BarNr]-High[BarNr]) > 2*RealBodySize(BarNr))) or
             (WhiteBody(BarNr) and (Abs(High[BarNr]-Close[BarNr]) > 2*RealBodySize(BarNr))));
end;

function Hammer(BarNr: integer): boolean;
begin
  Result := SmallUpperShadow(BarNr) and
            ((BlackBody(BarNr) and (Abs(Close[BarNr]-Low[BarNr]) > 2*RealBodySize(BarNr))) or
             (WhiteBody(BarNr) and (Abs(Low[BarNr]-Open[BarNr]) > 2*RealBodySize(BarNr))));
end;

{ Morning Star and Evening Star are inverted patterns }

function MorningStar(BarNr: integer): boolean;
begin
  Result := (BarNr > 1) and
            BlackBody(BarNr-2) and LargeBody(BarNr-2) and
            GapDown(BarNr-1) and
            MinLow5(BarNr-1) and
            WhiteBody(BarNr) and LargeBody(BarNr) and
            (Close[BarNr] > (Open[BarNr-2] + Close[BarNr-2])/2);
end;

function EveningStar(BarNr: integer): boolean;
begin
  Result := (BarNr > 1) and
            WhiteBody(BarNr-2) and LargeBody(BarNr-2) and
            GapUp(BarNr-1) and
            MaxHigh5(BarNr-1) and
            BlackBody(BarNr) and LargeBody(BarNr) and
            (Close[BarNr] < (Open[BarNr-2] + Close[BarNr-2])/2);
end;

function ThreeBlackCrows(BarNr: integer): boolean;
begin
  Result := (BarNr > 2) and
            BlackBody(BarNr-2) and not SmallBody(BarNr-2) and
            BlackBody(BarNr-1) and not SmallBody(BarNr-1) and
            BlackBody(BarNr) and not SmallBody(BarNr) and
            (Close[BarNr] < Close[BarNr-1]) and
            (Close[BarNr-1] < Close[BarNr-2]) and
            (Open[BarNr-1] < Open[BarNr-2]) and
            (Open[BarNr] < Open[BarNr-1]) and
            (Open[BarNr-1] > Close[BarNr-2]) and
            (Open[BarNr] > Close[BarNr-1]) and
            SmallLowerShadow(BarNr-2) and
            SmallLowerShadow(BarNr-1) and
            SmallLowerShadow(BarNr);
end;

function ThreeWhiteSoldiers(BarNr: integer): boolean;
begin
  Result := (BarNr > 2) and
            WhiteBody(BarNr-2) and not SmallBody(BarNr-2) and
            WhiteBody(BarNr-1) and not SmallBody(BarNr-1) and
            WhiteBody(BarNr) and not SmallBody(BarNr) and
            (Close[BarNr] > Close[BarNr-1]) and
            (Close[BarNr-1] > Close[BarNr-2]) and
            (Open[BarNr-1] > Open[BarNr-2]) and
            (Open[BarNr] > Open[BarNr-1]) and
            (Open[BarNr-1] < Close[BarNr-2]) and
            (Open[BarNr] < Close[BarNr-1]) and
            SmallUpperShadow(BarNr-2) and
            SmallUpperShadow(BarNr-1) and
            SmallUpperShadow(BarNr);
end;

var
  i: integer;
  Values: TSeries;
begin
  SetMinPriceChange(0.01);
  
  with Indicator do
  begin 
    NewBand := false;
    SignalView := svShowInMain; 
  end;

  Values := FillSeries(CreateSeries(BarCount), 0);
  for i:=0 to BarCount-1 do
  begin
    if Hammer(i) then
    begin
      Mark(i);
      Values[i] := 1;
    end;
  end;
  
  with CreateLine(Values) do
  begin
    Visible := false;
    LineContent := lcTAR;
    Name := 'TAR';
  end;
end.
---
Eric
Bakstenen
Berichten: 884
Lid geworden op: zo jul 19, 2015 7:51 pm

Re: TA script voor Bullish engulfing candlestick

Bericht door Bakstenen »

Bedankt alvast,ik ga er mee aan de slag
Bakstenen
Berichten: 884
Lid geworden op: zo jul 19, 2015 7:51 pm

Re: TA script voor Bullish engulfing candlestick

Bericht door Bakstenen »

Eric, het werkt goed
Plaats reactie