tesjoeva macd systeem

Stel hier uw vragen over TA-script, of help anderen met het oplossen van hun probleem
Plaats reactie
tesjoeva
Berichten: 148
Lid geworden op: vr jul 07, 2017 3:10 pm

tesjoeva macd systeem

Bericht door tesjoeva » za apr 06, 2019 6:07 pm

[{- Filename: Tesjoeva's MACD system -}]

function HullMA(Prices: TSeries; Period: integer): TSeries;
begin
// Integer (Square Root (Period)) WMA [2 x Integer (Period/2) WMA (Price) - Period WMA (Price)]
// waverage(2 * waverage(close, period/2) - waverage(close,period), SquareRoot(Period))
Result := MA(SubtractSeries(MultiplySeriesBy(MA(Prices, maWeighted, Period div 2), 2),
MA(Prices, maWeighted, Period)),
maWeighted, trunc(sqrt(Period)));
end;

var
nHullMA1, nHullMA2, nMA1, nMA2, i, iFirst, Period, Displace, Trigger, MP: integer;
TPLevel, TP: real;
sHullMACD, sMACD, sHullDiff, sDiff, sZero: TSeries;
sLR, sLRSlope, sForecast, sMAFc: TSeries;
begin
nHullMA1 := CreateParameterInteger('Hull''s MA periode 1', 1, 999, 13, true);
nHullMA2 := CreateParameterInteger('Hull''s MA periode 2', 1, 999, 26, true);
nMA1 := CreateParameterInteger('MA periode 1', 1, 999, 13, true);
nMA2 := CreateParameterInteger('MA periode 2', 1, 999, 26, true);
Period := CreateParameterInteger('T3 Period', 1, 999, 20, true);
Displace := CreateParameterInteger('T3 Displace LRF', 0, 999, 0, false);
Trigger := CreateParameterInteger('T3 EMA over LRF', 1, 999, 5, true);
TP := CreateParameterReal('Take profit (pt)', 0, 9999, 10, true);

with Indicator do
begin
RequiredBars := MaxInt(MaxInt(5*(nMA1+nMA2), nHullMA1+nHullMA2), 5*Period);
end;

sHullMACD := SubtractSeries(HullMA(Close, nHullMA1), HullMA(Close, nHullMA2));
sHullDiff := Momentum(sHullMACD, 1);

sMACD := MACD(Close, nMA1, nMA2);
sDiff := Momentum(sMACD, 1);
sZero := FillSeries(CreateSeries(BarCount), 0);

sLR := MovingRegression(Close,Period);
sLRSlope := MovingRegressionSlope(Close,Period);
sForecast := ShiftSeries(AddSeries(sLR,sLRSlope),Displace);
sMAFc := MA(sForecast,MaExponential,Trigger);

iFirst := MaxInt(MaxInt(FirstvalidIndex(sHullDiff), FirstValidIndex(sDiff)), FirstValidIndex(sMAFc));
for i:=iFirst+1 to BarCount-1 do
begin
if (MP > 0) and (Close >= TPLevel) then
begin
ExitLong(i);
MP := 0;
end else
if (MP < 0) and (Close <= TPLevel) then
begin
ExitShort(i);
MP := 0;
end else
if (sHullDiff > 0) and (sDiff > 0) and (sDiff > sDiff[i-1]) and (sMAFc < sForecast) then
begin
if EnterLong(i) then
begin
MP := 1;
TPLevel := Close + TP;
end;
end else
if (sHullDiff < 0) and (sDiff < 0) and (sDiff[i] < sDiff[i-1]) and (sMAFc[i] >= sForecast[i]) then
begin
if EnterShort(i) then
begin
MP := -1;
TPLevel := Close[i] - TP;
end;
end else
if (sMAFc[i] >= sForecast[i]) then
begin
ExitLong(i);
MP := 0;
end else
if (sMAFc[i] < sForecast[i]) then
begin
ExitShort(i);
MP := 0;
end;
end;

with CreateLine(sDiff) do
begin
Color := clLime;
end;
with CreateLine(sHullDiff) do
begin
Color := clYellow;
end;
with CreateLine(sZero) do
begin
Color := clSilver;
LineContent := lcConstant;
end;
end. [code\]

Hallo Eric,

Zou je deze indicator willen uitbreiden met'

CCI HAMI met MA%


Entry long: koopsignaal uit beide indicatoren
Exit long : PT of éé'rste contrasignaal uit de indicatoren,dus ongeacht welke.
Dit kan uit de macd indicator de PT zijn of de reguliere exit of uit de CCI met MA% het exit level of de reguliere exit.

Short en exit short is je natuurlijk duidelijk.

Dank bij voorbaat, ik hoop dat het lukt, vriendelijke groet

tesjoeva
Berichten: 148
Lid geworden op: vr jul 07, 2017 3:10 pm

Re: tesjoeva macd systeem

Bericht door tesjoeva » vr apr 12, 2019 12:19 pm

Hallo Eric,

Excuses als het ongeduldig overkomt, maar misschien is deze aan je aandacht ontsnapt.

Wil je zo vriendelijk zijn hier nog even een blik op te werpen?

bij voorbaat hartelijk bedankt, groet,

Eric
Berichten: 3026
Lid geworden op: za sep 10, 2005 2:41 am
Locatie: Den Haag

Re: tesjoeva macd systeem

Bericht door Eric » vr apr 12, 2019 8:52 pm

Niet ontsnapt maar nog geen tijd voor gevonden. Het is niet altijd even basaal om twee scripts in elkaar te schuiven.

---
Eric

Eric
Berichten: 3026
Lid geworden op: za sep 10, 2005 2:41 am
Locatie: Den Haag

Re: tesjoeva macd systeem

Bericht door Eric » ma apr 15, 2019 10:17 am

Code: Selecteer alles

{- Filename: Tesjoeva's MACD-CCI Hami system -}

function HullMA(Prices: TSeries; Period: integer): TSeries;
begin
// Integer (Square Root (Period)) WMA [2 x Integer (Period/2) WMA (Price) - Period WMA (Price)]
//  waverage(2 * waverage(close, period/2) - waverage(close,period), SquareRoot(Period))
  Result := MA(SubtractSeries(MultiplySeriesBy(MA(Prices, maWeighted, Period div 2), 2),
                              MA(Prices, maWeighted, Period)),
               maWeighted, trunc(sqrt(Period)));
end;

var
  nHullMA1, nHullMA2, nMA1, nMA2, i, iFirst, Period, Displace, Trigger, MP: integer;
  TPLevel, TP: real;
  sHullMACD, sMACD, sHullDiff, sDiff, sZero: TSeries;
  sPos, sLR, sLRSlope, sForecast, sMAFc: TSeries;

  nMAFilter, MAPeriode, MDPeriode, nEntryLevel, nExitLevel: integer;
  nMABand: real;
  sCCI, sEnterLong, sEnterShort, sMA, sMAHi, sMALo: TSeries;
  xLong, xShort: TLineCrossings;
begin
  nHullMA1 := CreateParameterInteger('Hull''s MA periode 1', 1, 999, 13, true);
  nHullMA2 := CreateParameterInteger('Hull''s MA periode 2', 1, 999, 26, true);
  nMA1 := CreateParameterInteger('MA periode 1', 1, 999, 13, true);
  nMA2 := CreateParameterInteger('MA periode 2', 1, 999, 26, true);
  Period   := CreateParameterInteger('T3 Period', 1, 999, 20, true);
  Displace := CreateParameterInteger('T3 Displace LRF', 0, 999, 0, false);
  Trigger  := CreateParameterInteger('T3 EMA over LRF', 1, 999, 5, true);

  MAPeriode := CreateParameterInteger('MA periode', 1, 999, 14, true);
  MDPeriode := CreateParameterInteger('MD periode', 1, 999, 14, true);
  nEntryLevel := CreateParameterInteger('Entry level', 1, 999, 50, true);
  nExitLevel := CreateParameterInteger('Exit level', 1, 999, 150, true);
  nMAFilter := CreateParameterInteger('MA filter periode', 1, 999, 30, true);
  nMABand := CreateParameterReal('MA filter band %', 0, 99, 1, true);

  TP  := CreateParameterReal('Take profit (pt)', 0, 9999, 10, true);

  with Indicator do
  begin
    RequiredBars := MaxInt(MaxInt(MaxInt(5*(nMA1+nMA2), nHullMA1+nHullMA2), 5*Period),
                           MaxInt(MAPeriode, MDPeriode) + nMAFilter);
  end;

  sPos := CreateSeries(BarCount);
  
  sHullMACD := SubtractSeries(HullMA(Close, nHullMA1), HullMA(Close, nHullMA2));
  sHullDiff := Momentum(sHullMACD, 1);

  sMACD := MACD(Close, nMA1, nMA2);
  sDiff := Momentum(sMACD, 1);
  sZero := FillSeries(CreateSeries(BarCount), 0);

  sLR       := MovingRegression(Close,Period);
  sLRSlope  := MovingRegressionSlope(Close,Period);
  sForecast := ShiftSeries(AddSeries(sLR,sLRSlope),Displace);
  sMAFc     := MA(sForecast,MaExponential,Trigger);

{ CCI HAMI }
  sCCI := CCI(High, Low, Close, MAPeriode, MDPeriode);
  sEnterLong := FillSeries(CreateSeries(BarCount), nEntryLevel);
  sEnterShort := FillSeries(CreateSeries(BarCount), -nEntryLevel);
  xLong := Crossings(sCCI, sEnterLong);
  xShort := Crossings(sCCI, sEnterShort);
  sMA := MA(Close, maSimple, nMAFilter);
  sMAHi := MultiplySeriesBy(sMA, (100+nMABand)/100);
  sMALo := MultiplySeriesBy(sMA, (100-nMABand)/100);

  iFirst := MaxInt(MaxInt(MaxInt(FirstvalidIndex(sHullDiff), FirstValidIndex(sDiff)), FirstValidIndex(sMAFc)),
                   MaxInt(FirstValidIndex(sMA), FirstValidIndex(sCCI)));
  for i:=iFirst+1 to BarCount-1 do
  begin
    if (MP > 0) and (High[i] >= TPLevel) then
    begin
      ExitLongLimit(i, TPLevel);
      MP := 0;
    end else
    if (MP < 0) and (Low[i] <= TPLevel) then
    begin
      ExitShortLimit(i, TPLevel);
      MP := 0;
    end else
    if (MP <= 0) and (sHullDiff[i] > 0) and (sDiff[i] > 0) and (sDiff[i] > sDiff[i-1]) and (sMAFc[i] < sForecast[i]) and
       (sCCI[i] > nEntryLevel) then
    begin
      if Close[i] > sMAHi[i] then
      begin
        EnterLong(i);
        MP := 1;
        TPLevel := Close[i] + TP;
      end else
      begin
        ExitShort(i);
        MP := 0;
      end;
    end else
    if (MP >= 0) and (sHullDiff[i] < 0) and (sDiff[i] < 0) and (sDiff[i] < sDiff[i-1]) and (sMAFc[i] >= sForecast[i]) and
       (sCCI[i] < -nEntryLevel) then
    begin
      if Close[i] < sMALo[i] then
      begin
        EnterShort(i);
        MP := -1;
        TPLevel := Close[i] - TP;
      end else
      begin
        ExitLong(i);
        MP := 0;
      end;
    end else
    if (MP > 0) and ((sMAFc[i] >= sForecast[i]) or (sCCI[i] > nExitLevel) or ((sCCI[i] < -nEntryLevel) and (Close[i] >= sMALo[i]))) then
    begin
      ExitLong(i);
      MP := 0;
    end else
    if (MP < 0) and ((sMAFc[i] < sForecast[i]) or (sCCI[i] < -nExitLevel) or ((sCCI[i] > nEntryLevel) and (Close[i] <= sMAHi[i]))) then
    begin
      ExitShort(i);
      MP := 0;
    end;
    sPos[i] := MP;
  end;

  with CreateLine(sDiff) do
  begin
    Color := clLime;
  end;
  with CreateLine(sHullDiff) do
  begin
    Color := clYellow;
  end;
  with CreateLine(sZero) do
  begin
    Color := clSilver;
    LineContent := lcConstant;
  end;
  with CreateLine(sCCI) do
  begin
    Name := 'CCI';
    Color := clLime;
  end;
  with CreateLine(sEnterLong) do
  begin
    Name := 'Entry long';
    Color := clLime;
  end;
  with CreateLine(sEnterShort) do
  begin
    Name := 'Entry short';
    Color := clLime;
  end;
  with CreateLine(FillSeries(CreateSeries(BarCount), nExitLevel)) do
  begin
    Name := 'Exit Long';
    Color := clRed;
  end;
  with CreateLine(FillSeries(CreateSeries(BarCount), -nExitLevel)) do
  begin
    Name := 'Exit Short';
    Color := clRed;
  end;
end.
---
Eric

tesjoeva
Berichten: 148
Lid geworden op: vr jul 07, 2017 3:10 pm

Re: tesjoeva macd systeem

Bericht door tesjoeva » ma apr 15, 2019 10:50 am

Hallo Eric,

Ziet er prachtig uit, hartelijk dank en nogmaals mijn excuses...................

vriendelijke groet,

Plaats reactie