macd combo

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

Re: Re: macd combo

Bericht door Eric » vr sep 07, 2018 12:43 pm

Geen onbenul maar juist hierom is het handig dat vragen over dezelfde indicator in 1 topic blijven. Ik zal eens kijken of ik de verschillende topics kan samenvoegen.

---
Eric

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

Re: macd combo

Bericht door tesjoeva » vr sep 07, 2018 7:11 pm

Hallo Eric,

Even iets héééél anders, als dat (ook) mag:

Ik heb de laatste indicator geplaatst onder onderhoud/ limieten.
Ook moet er een mail worden gestuurd.

Op een aantal markten, bijv. CAC40,AEX en Bund.

Bij een signaal krijg ik soms wél en soms géén mail of pop-up venster.

Dan weer wel bij de opening maar niet bij de exit etc.

Er zit op het eerste oog geen logica in, waarom er dus NIET gestuurd wordt.

Heb jij enig idee wat dit kan zijn?

vriendelijke groet,

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

Re: macd combo

Bericht door Eric » za sep 08, 2018 8:53 am

Ik heb de laatste versie iets aangepast, mogelijk helpt dat.

---
Eric

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

Re: macd combo

Bericht door tesjoeva » wo sep 12, 2018 10:50 am

Dat helpt idd, hartelijk dank.

vriendelijke groet.

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

Re: macd combo

Bericht door tesjoeva » za sep 15, 2018 8:48 am

Hallo Eric,

Het wordt me in de praktijk steeds duidelijker hoe fantastisch je Tesjoeva Macd2 hebt gemaakt.

Nogmaals hartelijk dank.

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

Re: macd combo

Bericht door tesjoeva » za sep 15, 2018 6:53 pm

Eric,

Ik bedoelde Tesjoeva Binary system 2, een toch zeer complex geheel dat je uitstekend hebt geimplementeerd.

Macd2 is overigens óók méér dan uitstekend.

Voor beide nog erg bedankt.

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

Re: macd combo

Bericht door Eric » zo sep 16, 2018 9:16 pm

Mooi, fijn om te horen.

---
Eric

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

Re: macd combo

Bericht door tesjoeva » wo nov 28, 2018 9:44 pm

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

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;

type
TSigTrigger = (trNone, trLong, trShort, trExitLong, trExitShort);

var
SigTrigger: TSigTrigger;
nHullMA1, nHullMA2, nMA1, nMA2, i, iFirst, Period, Displace, Trigger, Mom1, Mom2, Mom3, MP: integer;
TPLevel, TP: real;
sHullMACD, sMACD, sHullDiff, sDiff, sZero, sMom1, sMom2, sMom3: 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);
Mom1 := CreateParameterInteger('Mom 1', 1, 999, 1, true);
Mom2 := CreateParameterInteger('Mom 2', 1, 999, 5, true);
Mom3 := CreateParameterInteger('Mom 3', 1, 999, 10, true);

with Indicator do
begin
RequiredBars := MaxInt(MaxInt(5*(nMA1+nMA2), nHullMA1+nHullMA2), 5*Period)+Mom1+Mom2+MOm3;
AdvancedTrades := true;
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);

sMom1 := Momentum(Close, Mom1);
sMom2 := Momentum(Close, Mom2);
sMom3 := Momentum(Close, Mom3);

iFirst := MaxInt(MaxInt(MaxInt(MaxInt(MaxInt(FirstvalidIndex(sHullDiff), FirstValidIndex(sDiff)),
FirstValidIndex(sMAFc)), FirstValidIndex(sMom1)), FirstValidIndex(sMom2)), FirstValidIndex(sMom3));
for i:=iFirst+1 to BarCount-1 do
begin
if SigTrigger = trLong then
begin
if EnterLongAtOpen(i) then
begin
MP := 1;
if i < Barcount-1 then TPLevel := Open + TP;
end;
SigTrigger := trNone;
end else
if SigTrigger = trShort then
begin
if EnterShortAtOpen(i) then
begin
MP := -1;
if i < Barcount-1 then TPLevel := Open - TP;
end;
SigTrigger := trNone;
end else
if SigTrigger = trExitLong then
begin
ExitLongAtOpen(i);
SigTrigger := trNone;
MP := 0;
end else
if SigTrigger = trExitShort then
begin
ExitShortAtOpen(i);
SigTrigger := trNone;
MP := 0;
end else
if (MP > 0) and (High >= TPLevel) then
begin
ExitLongLimit(i, TPLevel);
MP := 0;
end else
if (MP < 0) and (Low <= TPLevel) then
begin
ExitShortLimit(i, TPLevel);
MP := 0;
end else
if (MP < 1) and (sHullDiff > 0) and (sDiff > 0) and (sDiff > sDiff[i-1]) and (sMAFc < sForecast) and
(sMom1 > 0) and (sMom2[i] > 0) and (sMom3[i] > 0) then
begin
SigTrigger := trLong;
end else
if (MP > -1) and (sHullDiff[i] < 0) and (sDiff[i] < 0) and (sDiff[i] < sDiff[i-1]) and (sMAFc[i] >= sForecast[i]) and
(sMom1[i] < 0) and (sMom2[i] < 0) and (sMom3[i] < 0) then
begin
SigTrigger := trShort;
end else
if (MP > 0) and (sMAFc[i] >= sForecast[i]) then
begin
SigTrigger := trExitLong;
end else
if (MP < 0) and (sMAFc[i] < sForecast[i]) then
begin
SigTrigger := trExitShort;
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.\]

Hallo Eric,

Wil je zo vriendelijk zijn deze indicator uit te breiden met:

retracement vanaf de highest profit in procenten.
Je hebt dit eerder voor me gedaan ik meen in tesjoeva binary.

Ik wil dus een trigger inbrengen in punten, een tamelijk gewone PT dus en dan vervolgens
in een mogelijk (en hopelijk) verdere stijging de terugval ondergaan om mogelijk een langere
trend mee te lopen.

Wil je deze dan 3 noemen aub?

vr,gr.

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

Re: macd combo

Bericht door Eric » do nov 29, 2018 12:23 pm

Probeer dit eens:

Code: Selecteer alles

{- Filename: Tesjoeva's MACD system 4 -}

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;

type
  TSigTrigger = (trNone, trLong, trShort, trExitLong, trExitShort);
  TTPState = (stNeutral, stLong, stShort, stSetupExitLong, stSetupExitShort);

var
  TPState: TTPState;
  Top, Bottom, EntryPrice: real;
  SigTrigger: TSigTrigger;
  nHullMA1, nHullMA2, nMA1, nMA2, i, iFirst, Period, Displace, Trigger, Mom1, Mom2, Mom3, MP: integer;
//  TPLevel, TP: real;
  sHullMACD, sMACD, sHullDiff, sDiff, sZero, sMom1, sMom2, sMom3: TSeries;
  sLR, sLRSlope, sForecast, sMAFc: TSeries;
  nTPTrigger, nTPRetracement, TPLevel: real;
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);
  Mom1 := CreateParameterInteger('Mom 1', 1, 999, 1, true);
  Mom2 := CreateParameterInteger('Mom 2', 1, 999, 5, true);
  Mom3 := CreateParameterInteger('Mom 3', 1, 999, 10, true);
  nTPTrigger := CreateParameterReal('Take Profit activation (pt)', 0, 99, 10, true);
  nTPRetracement := CreateParameterReal('Take Profit retracement (%)', 0, 99, 10, true);

  with Indicator do
  begin
    RequiredBars := MaxInt(MaxInt(5*(nMA1+nMA2), nHullMA1+nHullMA2), 5*Period)+Mom1+Mom2+MOm3;
    AdvancedTrades := true;
  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);

  sMom1 := Momentum(Close, Mom1);
  sMom2 := Momentum(Close, Mom2);
  sMom3 := Momentum(Close, Mom3);

  iFirst := MaxInt(MaxInt(MaxInt(MaxInt(MaxInt(FirstvalidIndex(sHullDiff), FirstValidIndex(sDiff)),
    FirstValidIndex(sMAFc)), FirstValidIndex(sMom1)), FirstValidIndex(sMom2)), FirstValidIndex(sMom3));
  for i:=iFirst+1 to BarCount-1 do
  begin
    if SigTrigger = trLong then
    begin
      if EnterLongAtOpen(i) then
      begin
        EntryPrice := Open[i];
        Top := Open[i];
        MP := 1;
        TPState := stLong;
      end;
      SigTrigger := trNone;
    end else
    if SigTrigger = trShort then
    begin
      if EnterShortAtOpen(i) then
      begin
        EntryPrice := Open[i];
        Bottom := Open[i];
        MP := -1;
        TPState := stShort;
      end;
      SigTrigger := trNone;
    end else
    if SigTrigger = trExitLong then
    begin
      ExitLongAtOpen(i);
      SigTrigger := trNone;
      MP := 0;
    end else
    if SigTrigger = trExitShort then
    begin
      ExitShortAtOpen(i);
      SigTrigger := trNone;
      MP := 0;
    end;
    
    if (SigTrigger = trNone) and (MP > 0) then
    begin
      if TPState = stLong then
      begin
        if High[i] > EntryPrice + nTPTrigger then
        begin
          TPState := stSetupExitLong;
          Top := High[i];
          TPLevel := EntryPrice + (Top-EntryPrice)*(100-nTPRetracement)/100;
        end else
        begin
          Top := Max(Top, High[i]);
        end;
      end else
      if TPState = stSetupExitLong then
      begin
        if Low[i] < TPLevel then
        begin
          ExitLongStop(i, TPLevel);
          TPState := stNeutral;
          MP := 0;
        end else
        begin
          Top := Max(Top, High[i]);
          TPLevel := EntryPrice + (Top-EntryPrice)*(100-nTPRetracement)/100;
        end;
      end
    end else
    if (SigTrigger = trNone) and (MP < 0) then
    begin
      if TPState = stShort then
      begin
        if Low[i] < EntryPrice - nTPTrigger then
        begin
          TPState := stSetupExitShort;
          Bottom := Low[i];
          TPLevel := EntryPrice - (EntryPrice-Bottom)*(100-nTPRetracement)/100;
        end else
        begin
          Bottom := Min(Bottom, Low[i]);
        end;
      end else
      if (MP < 0) and (TPState = stSetupExitShort) then
      begin
        if High[i] > TPLevel then
        begin
          ExitShortStop(i, TPLevel);
          TPState := stNeutral;
          MP := 0;
        end else
        begin
          Bottom := Min(Bottom, Low[i]);
          TPLevel := EntryPrice - (EntryPrice-Bottom)*(100-nTPRetracement)/100;
        end
      end
    end;
    
    if (MP < 1) and (sHullDiff[i] > 0) and (sDiff[i] > 0) and (sDiff[i] > sDiff[i-1]) and (sMAFc[i] < sForecast[i]) and
       (sMom1[i] > 0) and (sMom2[i] > 0) and (sMom3[i] > 0) then
    begin
      SigTrigger := trLong;
    end else
    if (MP > -1) and (sHullDiff[i] < 0) and (sDiff[i] < 0) and (sDiff[i] < sDiff[i-1]) and (sMAFc[i] >= sForecast[i]) and
       (sMom1[i] < 0) and (sMom2[i] < 0) and (sMom3[i] < 0) then
    begin
      SigTrigger := trShort;
    end else
    if (MP > 0) and (sMAFc[i] >= sForecast[i]) then
    begin
      SigTrigger := trExitLong;
    end else
    if (MP < 0) and (sMAFc[i] < sForecast[i]) then
    begin
      SigTrigger := trExitShort;
    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.
---
Eric

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

Re: macd combo

Bericht door tesjoeva » do nov 29, 2018 2:17 pm

Hartelijk dank maar wederom....ziet er prima uit.

Nog een verzoek op no.4.

Ik wil graag de sets Hull Ma periode 1 en2 en ma periode 1 en 2 nog 2 keer erbij hebben.

Ik heb deze dan in drievoud waarbij ik een korte- middel-en langere optimalisatie kan uitvoeren.
Uiteraard dienen deze nieuwe 2 als trendindicator, en hoop zo nog wat ruis te vermijden.

De T3 indicator(en) mogen natuurlijk ook in drievoud om het compleet te maken, maar hoeft niet, en ik wil je ook niet met teveel werk en vragen opzadelen; dit is al een luxe welke ik nog nooit heb gekend.

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

Re: macd combo

Bericht door tesjoeva » ma dec 03, 2018 12:23 pm

Hallo Eric,

Bovenstaande is werkelijk too much.....een beetje paranoia risicomijdend, dus laat maar zitten.

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

Re: macd combo

Bericht door tesjoeva » ma dec 03, 2018 1:23 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.\]

Wil je we zo vriendelijk zijn deze uit te breiden met de Random Walk Index en Vortex?
Long bij entry in de Tesjoeva Macd als ook de RWI en Vortex dit ondersteunen.
Flat bij een profit target of als één van de indicatoren een exit geeft.
Short is natuurlijk duidelijk voor je.

vr.gr.

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

Re: macd combo

Bericht door tesjoeva » do jan 10, 2019 4:30 pm

Code: Selecteer alles

{- Filename: Tesjoeva's MACD system 2 -}

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;

type
  TSigTrigger = (trNone, trLong, trShort, trExitLong, trExitShort);

var
  SigTrigger: TSigTrigger;
  nHullMA1, nHullMA2, nMA1, nMA2, i, iFirst, Period, Displace, Trigger, Mom1, Mom2, Mom3, MP: integer;
  SLLevel, SL, TPLevel, TP: real;
  sHullMACD, sMACD, sHullDiff, sDiff, sZero, sMom1, sMom2, sMom3: 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);
  SL  := CreateParameterReal('Stoploss (pt)', 0, 9999, 10, true);
  Mom1 := CreateParameterInteger('Mom 1', 1, 999, 1, true);
  Mom2 := CreateParameterInteger('Mom 2', 1, 999, 5, true);
  Mom3 := CreateParameterInteger('Mom 3', 1, 999, 10, true);

  with Indicator do
  begin
    RequiredBars := MaxInt(MaxInt(5*(nMA1+nMA2), nHullMA1+nHullMA2), 5*Period)+Mom1+Mom2+MOm3+500;
    AdvancedTrades := true;
  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);

  sMom1 := Momentum(Close, Mom1);
  sMom2 := Momentum(Close, Mom2);
  sMom3 := Momentum(Close, Mom3);

  iFirst := MaxInt(MaxInt(MaxInt(MaxInt(MaxInt(FirstvalidIndex(sHullDiff), FirstValidIndex(sDiff)),
    FirstValidIndex(sMAFc)), FirstValidIndex(sMom1)), FirstValidIndex(sMom2)), FirstValidIndex(sMom3));
  for i:=iFirst+1 to BarCount-1 do
  begin
    if SigTrigger = trLong then
    begin
      SigTrigger := trNone;
      if EnterLongAtOpen(i) then
      begin
        MP := 1;
        if i < Barcount-1 then
        begin
          TPLevel := Open[i] + TP;
          SLLevel := Open[i] - SL;
        end;
        if High[i] >= TPLevel then SigTrigger := trExitLong; // exit next bar if TP level reached in opening bar
        if Low[i] <= SLLevel then SigTrigger := trExitLong; // exit next bar if SL level reached in opening bar
      end;
    end else
    if SigTrigger = trShort then
    begin
      SigTrigger := trNone;
      if EnterShortAtOpen(i) then
      begin
        MP := -1;
        if i < Barcount-1 then
        begin
          TPLevel := Open[i] - TP;
          SLLevel := Open[i] + SL;
        end;
        if Low[i] <= TPLevel then SigTrigger := trExitShort; // exit next bar if TP level reached in opening bar
        if High[i] >= SLLevel then SigTrigger := trExitShort; // exit next bar if SL level reached in opening bar
      end;
    end else
    if SigTrigger = trExitLong then
    begin
      ExitLongAtOpen(i);
      SigTrigger := trNone;
      MP := 0;
    end else
    if SigTrigger = trExitShort then
    begin
      ExitShortAtOpen(i);
      SigTrigger := trNone;
      MP := 0;
    end else
    if (MP > 0) and ((High[i] >= TPLevel) or (Low[i] <= SLLevel)) then
    begin
      ExitLongLimit(i, TPLevel);
      MP := 0;
    end else
    if (MP < 0) and ((Low[i] <= TPLevel) or (High[i] >= SLLevel)) then
    begin
      ExitShortLimit(i, TPLevel);
      MP := 0;
    end else
    if (MP < 1) and (sHullDiff[i] > 0) and (sDiff[i] > 0) and (sDiff[i] > sDiff[i-1]) and (sMAFc[i] < sForecast[i]) and
       (sMom1[i] > 0) and (sMom2[i] > 0) and (sMom3[i] > 0) then
    begin
      SigTrigger := trLong;
    end else
    if (MP > -1) and (sHullDiff[i] < 0) and (sDiff[i] < 0) and (sDiff[i] < sDiff[i-1]) and (sMAFc[i] >= sForecast[i]) and
       (sMom1[i] < 0) and (sMom2[i] < 0) and (sMom3[i] < 0) then
    begin
      SigTrigger := trShort;
    end else
    if (MP > 0) and (sMAFc[i] >= sForecast[i]) then
    begin
      SigTrigger := trExitLong;
    end else
    if (MP < 0) and (sMAFc[i] < sForecast[i]) then
    begin
      SigTrigger := trExitShort;
    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.      

Hallo Eric,

Wil j zo vriendelijk zijn bovenstaande indicator uit te breiden met de MA+%filter?

Entry obv indicator+koers >%filter
Exit Koers onder de MA ( de middellijn)
Re-entry indicator nog long + koers opnieuw >%filter.

Of uiteraard exit op profit target.

Short vice versa.

Om verwarring te voorkomen graag Tesjoeva+MA% noemen aub.

Alsnog de beste wensen en bvb vriendelijk dank.

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

Re: macd combo

Bericht door Eric » vr jan 11, 2019 11:45 am

Het wordt wel erg complex allemaal dus ik kan moeilijk nagaan of het allemaal goed gaat maar dit zou het kunnen zijn.

Code: Selecteer alles

{- Filename: Tesjoeva's MACD met MA filter -}

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;

type
  TSigTrigger = (trNone, trLong, trShort, trExitLong, trExitShort);

var
  SigTrigger: TSigTrigger;
  nHullMA1, nHullMA2, nMA1, nMA2, nMA3, i, iFirst, Period, Displace, Trigger, Mom1, Mom2, Mom3, MP: integer;
  SLLevel, SL, TPLevel, TP, nMA3Band: real;
  sHullMACD, sMACD, sHullDiff, sDiff, sZero, sMom1, sMom2, sMom3: TSeries;
  sLR, sLRSlope, sForecast, sMAFc, sMA, sMAHi, sMALo: TSeries;
  LongCond, ShortCond, ReEntryLongCond, ReEntryShortCond: boolean;
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('MACD periode 1', 1, 999, 13, true);
  nMA2 := CreateParameterInteger('MACD periode 2', 1, 999, 26, true);
  nMA3 := CreateParameterInteger('MA filter periode', 1, 999, 30, true);
  nMA3Band := CreateParameterReal('MA filter band %', 0, 99, 1, 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);
  SL  := CreateParameterReal('Stoploss (pt)', 0, 9999, 10, true);
  Mom1 := CreateParameterInteger('Mom 1', 1, 999, 1, true);
  Mom2 := CreateParameterInteger('Mom 2', 1, 999, 5, true);
  Mom3 := CreateParameterInteger('Mom 3', 1, 999, 10, true);

  with Indicator do
  begin
    RequiredBars := MaxInt(MaxInt(5*(nMA1+nMA2), nHullMA1+nHullMA2), 5*Period)+Mom1+Mom2+MOm3+500;
    AdvancedTrades := true;
  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);

  sMom1 := Momentum(Close, Mom1);
  sMom2 := Momentum(Close, Mom2);
  sMom3 := Momentum(Close, Mom3);

  sMA := MA(Close, maSimple, nMA3);
  sMAHi := MultiplySeriesBy(sMA, (100+nMA3Band)/100);
  sMALo := MultiplySeriesBy(sMA, (100-nMA3Band)/100);

  iFirst := MaxInt(MaxInt(MaxInt(MaxInt(MaxInt(MaxInt(FirstvalidIndex(sHullDiff), FirstValidIndex(sDiff)),
    FirstValidIndex(sMAFc)), FirstValidIndex(sMom1)), FirstValidIndex(sMom2)), FirstValidIndex(sMom3)),
    FirstValidIndex(sMA));
  for i:=iFirst+1 to BarCount-1 do
  begin
    LongCond := (sHullDiff[i] > 0) and (sDiff[i] > 0) and (sDiff[i] > sDiff[i-1]) and (sMAFc[i] < sForecast[i]) and
                (sMom1[i] > 0) and (sMom2[i] > 0) and (sMom3[i] > 0);
    ShortCond := (sHullDiff[i] < 0) and (sDiff[i] < 0) and (sDiff[i] < sDiff[i-1]) and (sMAFc[i] >= sForecast[i]) and
                (sMom1[i] < 0) and (sMom2[i] < 0) and (sMom3[i] < 0);
    if (MP = 0) and not LongCond then ReEntryLongCond := false;
    if (MP = 0) and not ShortCond then ReEntryShortCond := false;

    if SigTrigger = trLong then
    begin
      SigTrigger := trNone;
      if EnterLongAtOpen(i) then
      begin
        ReEntryLongCond := LongCond;
        MP := 1;
        if i < Barcount-1 then
        begin
          TPLevel := Open[i] + TP;
          SLLevel := Open[i] - SL;
        end;
        if High[i] >= TPLevel then SigTrigger := trExitLong; // exit next bar if TP level reached in opening bar
        if Low[i] <= SLLevel then SigTrigger := trExitLong; // exit next bar if SL level reached in opening bar
      end;
    end else
    if SigTrigger = trShort then
    begin
      SigTrigger := trNone;
      if EnterShortAtOpen(i) then
      begin
        ReEntryShortCond := ShortCond;
        MP := -1;
        if i < Barcount-1 then
        begin
          TPLevel := Open[i] - TP;
          SLLevel := Open[i] + SL;
        end;
        if Low[i] <= TPLevel then SigTrigger := trExitShort; // exit next bar if TP level reached in opening bar
        if High[i] >= SLLevel then SigTrigger := trExitShort; // exit next bar if SL level reached in opening bar
      end;
    end else
    if SigTrigger = trExitLong then
    begin
      ExitLongAtOpen(i);
      SigTrigger := trNone;
      MP := 0;
    end else
    if SigTrigger = trExitShort then
    begin
      ExitShortAtOpen(i);
      SigTrigger := trNone;
      MP := 0;
    end else
    if (MP > 0) and ((High[i] >= TPLevel) or (Low[i] <= SLLevel)) then
    begin
      ReEntryLongCond := false;
      ExitLongLimit(i, TPLevel);
      MP := 0;
    end else
    if (MP < 0) and ((Low[i] <= TPLevel) or (High[i] >= SLLevel)) then
    begin
      ReEntryShortCond := false;
      ExitShortLimit(i, TPLevel);
      MP := 0;
    end else
    if (MP < 1) and LongCond and (Close[i] > sMAHi[i]) then
    begin
      SigTrigger := trLong;
    end else
    if (MP > -1) and ShortCond and (Close[i] < sMALo[i]) then
    begin
      SigTrigger := trShort;
    end else
    if (MP > 0) and (sMAFc[i] >= sForecast[i]) then
    begin
      SigTrigger := trExitLong;
      ReEntryLongCond := false;
    end else
    if (MP < 0) and (sMAFc[i] < sForecast[i]) then
    begin
      SigTrigger := trExitShort;
      ReEntryShortCond := false;
    end else
    if (MP > 0) and (Close[i] < sMA[i]) then
    begin
      SigTrigger := trExitLong;
    end else
    if (MP < 0) and (Close[i] > sMA[i]) then
    begin
      SigTrigger := trExitShort;
    end else
    if (MP = 0) and (Close[i] > sMAHi[i]) and ReEntryLongCond then
    begin
      SigTrigger := trLong;
    end else
    if (MP = 0) and (Close[i] < sMAHi[i]) and ReEntryShortCond then
    begin
      SigTrigger := trShort;
    end;
//    if (Signals[i] = sgNeutral) and ReEntryLongCond then Signals[i] := sgMark;
  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.
---
Eric

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

Re: macd combo

Bericht door tesjoeva » za jan 12, 2019 12:22 pm

Hallo Eric,

Ontzettend bedankt alweer.....

Nog en kleine aanpassing:

Ik zou graag de MA%filter willen gebruiken ALLEEN op het moment van een entry uit het Tesjoeva systeem,
dus in feite als een trend indicator.
Het systeem zelf geeft voldoende veiligheid en re-entries en bovendien werk ik met korte profit stops dus bij een in gang zijnde trend ben ik vaak al snel weer weg............

Het zou dus betekenen dat de signalen op de MA (de middellijn) komen te vervallen en we dus signalen krijgen obv het Tesjoeva systeem met een bevestiging van de trend uit de MA%filter.

Ik hoop dat het lukt en dat dit het systeem ook iets eenvoudiger maakt.
vriendelijke groet,

Plaats reactie