Nochmal Divergenzen, mehrere

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #203062 quote
    f1_maik
    Participant
    Junior

    Na hi Leute.

    (Wenn die Darstellung das Codes nicht richtig klappt, bitte habt ein Nachsehen. Es finde keine Voransicht meines Beitrages.)

    Es wird kompliziert.

     

    Ich habe diesen Indikator von hier genommen .

    RSI classical and hidden Divergences Indicator

    stark eingekürzt und etwas umgeschrieben.

    RsiOverSold = 40 
    RsiOverBought = 60
    MinBarRange = 3 
    
    MyRSI = RSI[14](close) // rsi[RsiPeriod](Close)
    
    Once Rge1 = 5*pipsize 
    Once Rge2 = 8*pipsize
    
    RsiMax = MyRSI < MyRSI[1] and MyRSI[1] > MyRSI[2] and MyRSI[1] > RsiOverBought
    RsiMin = MyRSI > MyRSI[1] and MyRSI[1] < MyRSI[2] and MyRSI[1] < RsiOverSold
    
    if RsiMax then
    RSIMax1 = MyRSI[1]
    High1 = High[1]
    
    for I = MinBarRange to  80
    if RsiMax[I] then
    RSIMax2 = MyRSI[I + 1]
    High2 = High[I + 1]
    If High1 > High2 and RSIMax1 < RSIMax2 then
    DRAWARROWDOWN(barindex, High + Rge1) coloured(255,192,203,255)
    DRAWTEXT("RSI", barindex, High + Rge2, SansSerif,Italic,10)coloured(0,0,255,255)
    //elsif High1 < High2 and RSIMax1 > RSIMax2 then
    //DRAWARROWDOWN(barindex, High + Rge1) coloured(255,192,203,255)
    //DRAWTEXT("hd_rsi", barindex, High + Rge2, SansSerif,Italic,10)coloured(0,0,255,255)
    endif
    break
    endif
    next
    endif
    
    return
    
    
    
    

    Wir haben also die Short-Signale mit “DrawArrowDown” beim RSI

    Diesen eingekürzten Indikator kann man nun sehr leicht in andere Divergenz-Indikatoren umschreiben, z.B. mit dem MFI

    RsiOverSold = 30 
    RsiOverBought = 70 
    MinBarRange = 3 
    
    MyRSI = MoneyFlowIndex[14] // aha
    
    Once Rge1 = 15*pipsize 
    Once Rge2 = 17*pipsize
    
    
    RsiMax = MyRSI < MyRSI[1] and MyRSI[1] > MyRSI[2] and MyRSI[1] > RsiOverBought
    RsiMin = MyRSI > MyRSI[1] and MyRSI[1] < MyRSI[2] and MyRSI[1] < RsiOverSold
    
    if RsiMax then
    RSIMax1 = MyRSI[1]
    High1 = High[1]
    
    for I = MinBarRange to  80
    if RsiMax[I] then
    RSIMax2 = MyRSI[I + 1]
    High2 = High[I + 1]
    If High1 > High2 and RSIMax1 < RSIMax2 then
    DRAWARROWDOWN(barindex, High + Rge1) coloured(255,192,203,255)
    DRAWTEXT("MFI", barindex, High + Rge2, SansSerif,Italic,10)coloured(0,0,255,255) //aha
    //elsif High1 < High2 and RSIMax1 > RSIMax2 then
    //DRAWARROWDOWN(barindex, High + Rge1) coloured(255,192,203,255)
    //DRAWTEXT("MFI", barindex, High + Rge2, SansSerif,Italic,10)coloured(0,0,255,255)
    endif
    break
    endif
    next
    endif
    
    return
    

    Wir haben nun also die Short-Signale mit “DrawArrowDown” dem MFI

    Das kann man fortsetzen für andere (gute) Divergenzindikatoren wie Momentum, PVT, SMI, …
    Soweit so gut.

    …………………………………..

    Ersetze ich jetzt das “DrawArrowDown” mit Sellshort, füge SL und TP und schreibe den Indikator etwas um, erhalte ich eine Strategie, die sieht dann so aus

    RsiOverSold = 40 
    RsiOverBought = 60 
    MinBarRange = 3 
    
    MyRSI = RSI[14](close) 
    
    
    RsiMax = MyRSI < MyRSI[1] and MyRSI[1] > MyRSI[2] and MyRSI[1] > RsiOverBought
    RsiMin = MyRSI > MyRSI[1] and MyRSI[1] < MyRSI[2] and MyRSI[1] < RsiOverSold
    
    
    if RsiMax then
    RSIMax1 = MyRSI[1]
    High1 = High[1]
    
    for I = MinBarRange to  80
    if RsiMax[I] then
    RSIMax2 = MyRSI[I + 1]
    High2 = High[I + 1]
    If High1 > High2 and RSIMax1 < RSIMax2 then
    sellshort at market
    endif
    break
    endif
    next
    endif
    
    set stop ploss 15
    set target pprofit 15
    

    Das gleiche kann ich mit den anderen Indikatoren Momentum, PVT, SMI, … machen.

    …………………………………..

    Nun kommt meine eigentliche Frage.

    Es können 1,2,3,4… “DrawArrowDown” gleichzeitg über einer Kerze oder auch über mehrere Kerzen hintereinander auftreten. So entstehen dann 1,2,3,4… Shortsignale.

    Ich möchte nun 1.
    einen Short eröffnen, wenn z.B. 3 von 4 Shortsignalen über die letzten n-Kerzen aufgetreten sind, es können auch die gleichen Shortsignale sein, siehe Screenshot1

    und ich möchte alternativ 2.
    Longs eröffnen wenn z.B. 3 von 4 shortsignale über die letzten n-Kerzen aufgetreten sind, es können auch wieder die gleichen Shortsignale sein, siehe Screenshot2

    Wie würde dafür der der Code aussehen…?

    ……………………………….

    Habe ich es gut erklären können? Habt Ihr Fragen?

    #203065 quote
    f1_maik
    Participant
    Junior

    Nachtrag Screenshot1

    #203296 quote
    Nicolas
    Keymaster
    Master

    Da Sie vom vorherigen Balken 3 bis 80 in die Vergangenheit schauen, gehen Sie jedes Mal, wenn Sie eine Divergenz entdecken, zum Markt, selbst wenn dieses Divergenzsignal bereits in der Vergangenheit gehandelt wurde. Ich schlage vor, dass Sie den BARINDEX dieses Signals testen, damit die nächste Bestellung nicht startet, wenn das Signal vom selben BARINDEX kommt (Code unten nicht getestet):

    RsiOverSold = 40 
    RsiOverBought = 60 
    MinBarRange = 3 
    
    MyRSI = RSI[14](close) 
    
    
    RsiMax = MyRSI < MyRSI[1] and MyRSI[1] > MyRSI[2] and MyRSI[1] > RsiOverBought
    RsiMin = MyRSI > MyRSI[1] and MyRSI[1] < MyRSI[2] and MyRSI[1] < RsiOverSold
    
    
    if RsiMax then
     RSIMax1 = MyRSI[1]
     High1 = High[1]
    
     for I = MinBarRange to  80
      if RsiMax[I] then
       RSIMax2 = MyRSI[I + 1]
       High2 = High[I + 1]
       If High1 > High2 and RSIMax1 < RSIMax2 then 
        divbar=barindex
        break
       endif
      endif
     next
    endif
    
    if divbar<>lastdivbar then  
        sellshort at market
        lastdivbar=divbar
    endif
    
    set stop ploss 15
    set target pprofit 15
    f1_maik thanked this post
    #203636 quote
    f1_maik
    Participant
    Junior

    Vielen Dank. Das passt so.

    Ich habe deinen Code mit defparam cumulateorders = false ergänzt, es sieht im 1 Min-chart 100K so aus, Screenshot1.

    Aber es geht noch weiter.

     

    Ich möchte nicht nur die RSI-Divergenzen verwenden sondern auch vom MFI, SMI, PVT. Momentum. Wir hätten dann genau 5 Divergenzen.

    Wie kann der Code aussehen, dass ich einen Short eröffne, wenn mindestens 3 der 5 Divergenzen vorliegen? – und das a. in einer Kerze oder b. innerhalb der letzten n-Kerzen?

    #203741 quote
    Nicolas
    Keymaster
    Master

    Na ja, es würde sicher länger aussehen 🙂

    f1_maik thanked this post
    #203746 quote
    f1_maik
    Participant
    Junior

    Das stimmt. Wir können es verkürzen indem wir einfache Bedingungen verwenden. c1, c2, c3, c4, c5 für das sinngemäße Programmieren reichen. Weißt du wie ich es meine?

    #205222 quote
    f1_maik
    Participant
    Junior

    Nochmal bitte wegen den Divergenzen.

    Kannst mir helfen, so daß ich den nachfolgenden Code als Bedingung weiter verwenden kann?

     

    RsiOverSold = 40 
    RsiOverBought = 60
    MinBarRange = 3 
     
    MyRSI = RSI[14](close) // rsi[RsiPeriod](Close)
     
    Once Rge1 = 5*pipsize 
    Once Rge2 = 8*pipsize
     
    RsiMax = MyRSI < MyRSI[1] and MyRSI[1] > MyRSI[2] and MyRSI[1] > RsiOverBought
    RsiMin = MyRSI > MyRSI[1] and MyRSI[1] < MyRSI[2] and MyRSI[1] < RsiOverSold
     
    if RsiMax then
    RSIMax1 = MyRSI[1]
    High1 = High[1]
     
    for I = MinBarRange to  80
    if RsiMax[I] then
    RSIMax2 = MyRSI[I + 1]
    High2 = High[I + 1]
    If High1 > High2 and RSIMax1 < RSIMax2 then
    DRAWARROWDOWN(barindex, High + Rge1) coloured(255,192,203,255)
    DRAWTEXT("RSI", barindex, High + Rge2, SansSerif,Italic,10)coloured(0,0,255,255)
    //elsif High1 < High2 and RSIMax1 > RSIMax2 then
    //DRAWARROWDOWN(barindex, High + Rge1) coloured(255,192,203,255)
    //DRAWTEXT("hd_rsi", barindex, High + Rge2, SansSerif,Italic,10)coloured(0,0,255,255)
    endif
    break
    endif
    next
    endif
     
    return

    Also in dem Moment wo das der Pfeil im chart erscheint, soll die Bedingung z.B. “c1” als erfüllt gelten so dass ich mit dieser Bedingung weiterarbeiten kann etwa so
    if c1 then..

    #205239 quote
    JohnScher
    Participant
    Veteran

    Hallo Nikolas.

     

    Vielleicht kannst du nochmal helfen.

    Dass Thema mit den Divergenzen finde ich gar nicht so schlecht, und habe mich damit beschäftigt.

     

    So wie ich es verstanden habe, soll es beim Auftreten von mehreren Divergenzen, siehe Screenshort xy eine Shortposition eingenommen werden (Longpositionen werden der Vereinfachung wegen vernachlässigt).

    Ich habe es  mit meinen Fähigkeiten durchprogrammiert aber es tut nicht was es soll. Mir ist nicht klar, warum es den Handel nicht korrekt auslöst.  Nachfolgend der Code für die Divergenz und den Handel. Bitte kannst du helfen?

     

     

     

    /////////////////////////////////////////////
    // Stochastic divergences ON Stochastic
    // https://www.prorealcode.com/topic/obv-on-balance-volume-divergence/
    // based on:
    //
    //    MACD divergences on MACD
    //    by Jose Callao
    //    twitter @jose7674
    //
    // little changed by JohnScher
    
    mbr = 1
    n = 40
    
    DIVRSI  = RSI[10](close)
    
    IF (BarIndex > N) THEN
    
    IF (DIVRSI[1]>DIVRSI AND DIVRSI[1]>DIVRSI[2]) THEN
    extremumRSI2=DIVRSI[1]
    extremumRSI1=highest[N](DIVRSI)
    preciomaxRSI2=close[1]
    preciomaxRSI=Highest[N](close)
    IF(extremumRSI2<extremumRSI1 AND preciomaxRSI2>preciomaxRSI[1]) THEN
    for i= mbr to n
    if DIVRSI[i]=extremumRSI1 then
    DRAWARROWDOWN(barindex, High + 10) coloured(255,0,255)
    DRAWTEXT("RSI", barindex, High + 15, SansSerif,Italic,10)coloured(255,0,255)
    endif
    next
    endif
    endif
    endif
    
    return
    
    defparam cumulateorders = false
    
    once cDIVMFI = 0
    once cDIVRSI = 0
    once cDIVMOM = 0
    
    
    td = opendayofweek >=1 and opendayofweek <= 5
    tt = time >= 080000 and time <= 210000
    
    mbr = 1
    n = 40
    
    //.................................................................................................................
    
    DIVMFI  = MoneyFlowIndex[14]
    
    IF (BarIndex > n) THEN
    IF (DIVMFI[1]>DIVMFI AND DIVMFI[1]>DIVMFI[2]) THEN
    extremumMFI2=DIVMFI[1]
    extremumMFI1=highest[n](DIVMFI)
    preciomaxMFI2=close[1]
    preciomaxMFI=Highest[n](close)
    IF(extremumMFI2<extremumMFI1 AND preciomaxMFI2>preciomaxMFI[1]) THEN
    for i=mbr to n
    if DIVMFI[i]=extremumMFI1 then
    cDIVMFI = 1
    Endif
    next
    Endif
    Endif
    Endif
    
    //.................................................................................................................
    
    DIVRSI  = RSI[14](close)
    
    IF (BarIndex > n) THEN
    IF (DIVRSI[1]>DIVRSI AND DIVRSI[1]>DIVRSI[2]) THEN
    extremumRSI2=DIVRSI[1]
    extremumRSI1=highest[n](DIVRSI)
    preciomaxRSI2=close[1]
    preciomaxRSI=Highest[n](close)
    IF(extremumRSI2<extremumRSI1 AND preciomaxRSI2>preciomaxRSI[1]) THEN
    for i=mbr to n
    if DIVRSI[i]=extremumRSI1 then
    cDIVRSI = 1
    Endif
    next
    Endif
    Endif
    Endif
    
    //.................................................................................................................
    
    DIVMOM  = Momentum[12](close)
    
    If  (BarIndex > n) THEN
    If (DIVMOM[1]>DIVMOM AND DIVMOM[1]>DIVMOM[2]) THEN
    extremumMOM2=DIVMOM[1]
    extremumMOM1=highest[n](DIVMOM)
    preciomaxMOM2=close[1]
    preciomaxMOM=Highest[n](close)
    If(extremumMOM2<extremumMOM1 AND preciomaxMOM2>preciomaxMOM[1]) THEN
    for i=mbr to n
    If DIVMOM[i]=extremumMOM1 then
    cDIVMOM = 1
    Endif
    next
    Endif
    Endif
    Endif
    
    //.................................................................................................................
    
    
    
    
    IF td and tt then
    IF cDIVMFI = 1 and cDIVRSI = 1 and cDIVMOM = 1 then
    buy at market
    ENDIF
    ENDIF
    
    
    
    IF onmarket then
    cDIVMFI = 0
    cDIVRSI = 0
    cDIVMOM = 0
    ENDIF
    
    
    
    set stop ploss 20
    set target pprofit 25
    
    #205355 quote
    robertogozzi
    Moderator
    Master

    Wenn Sie sowohl in der Strategie als auch im Indikator die gleiche Anzahl von RSI-Perioden angeben, entsprechen die Einträge den Signalen des Indikators.

    JohnScher thanked this post
    #205433 quote
    JohnScher
    Participant
    Veteran

    Hallo Roberto.

    Vielen Dank das du mir hier hilfst.

    Ich habe die Einstellungen bei denIndikatoren mit den den Einstellungen in der Handelsanweisung synchronisiert. Es stimmt es gab Fehler, aber das Ergebnis blieb das gleiche. Es wurde ein Kaufauftrag ausgelöst, auch wenn nicht alle Pfeile der Indikatoren übereinander lagen.

    Ich habe daraufhin einen der Indikatoren komplett überarbeitet, siehe nachfolgend oder auch anbei den itf-file.

     

    Rge1 = 10
    Rge2 = 15
    
    
    mbr = 1
    n = 40
    
    DIVSMI = SMI[14,3,5](close)
    
    
    IF (BarIndex > n) THEN
    IF (DIVSMI[1]>DIVSMI AND DIVSMI[1]>DIVSMI[2]) THEN
    extremumSMI2=DIVSMI[1]
    extremumSMI1=highest[n](DIVSMI)
    preciomaxSMI2=close[1]
    preciomaxSMI=Highest[n](close)
    IF(extremumSMI2<extremumSMI1 AND preciomaxSMI2>preciomaxSMI[1]) THEN
    for i=mbr to n
    if DIVSMI[i]=extremumSMI1 then
    DRAWARROWDOWN(barindex, High + Rge1) coloured(255,0,255)
    DRAWTEXT("SMI", barindex, High + Rge2, SansSerif,Italic,10)coloured(255,0,255)
    Endif
    next
    Endif
    Endif
    ENDIF
    
    return
    

    Dann habe ich die Handelsanweisung überarbeitet und auf ledglich eine Divergenz heruntergebrochen siehe dafür nachfolgend bzw. den itf-file.

    defparam cumulateorders = false
    
    
    once cDIVSMI = 0
    
    mbr = 1
    n = 40
    
    
    DIVSMI = SMI[14,3,5](close)
    
    IF (BarIndex > n) THEN
    IF (DIVSMI[1]>DIVSMI AND DIVSMI[1]>DIVSMI[2]) THEN
    extremumSMI2=DIVSMI[1]
    extremumSMI1=highest[n](DIVSMI)
    preciomaxSMI2=close[1]
    preciomaxSMI=Highest[n](close)
    IF(extremumSMI2<extremumSMI1 AND preciomaxSMI2>preciomaxSMI[1]) THEN
    for i=mbr to n
    if DIVSMI[i]=extremumSMI1 then
    cDIVSMI = 1
    Endif
    next
    Endif
    Endif
    ENDIF
    
    
    If cDIVSMI = 1 then
    sellshort at market
    ENDIF
    
    
    IF onmarket then
    cDIVSMI = 0
    ENDIF
    
    
    set stop ploss 15
    set target pprofit 15
    

    Es sieht soweit alles in Ordnung aus und trotzem gibt es wieder Abweichungen, siehe dazu anbei den Screenshot und dort die senkrechten roten Linien.
    Der Handel wird nicht auf der “gleichen” Kerze ausgelöst.

    Kannst du erkennen welchen Fehler ich habe und mir zeigen wie ich den Fehler verbessern kann?

    Liebe Grüße
    JohnScher

    #205443 quote
    robertogozzi
    Moderator
    Master

    Wenn Sie den Zeitrahmen auf 1 Minute ändern, funktioniert es einwandfrei. Nicht zeitbasierte Charts können Strategien nur im Backtest-Modus ausführen, nicht im Live-Modus, aber sie sind möglicherweise nicht so genau.

    JohnScher thanked this post
    #205473 quote
    JohnScher
    Participant
    Veteran

    Hallo Roberto.
    Vielen lieben Dank.
    Das sieht schon sehr viel besser aus.

    Nun geht es noch um den Zusammenbau von mehreren Divergenzen zum Auslösen einer Handlung.
    Nachfolgend der Code. Die Indikatoren wurden auf die Standardeinstellungen gesetzt und sind synchronisiert.
    Anbei auch die itf-files.

    defparam cumulateorders = false
    
    once cDIVMFI = 0
    once cDIVRSI = 0
    once cDIVMOM = 0
    
    
    td = opendayofweek >=1 and opendayofweek <= 5
    tt = time >= 080000 and time <= 210000
    
    mbr = 1
    n = 40
    
    //.................................................................................................................
    
    DIVMFI = MoneyFlowIndex[14]
    
    IF (BarIndex > n) THEN
    IF (DIVMFI[1]>DIVMFI AND DIVMFI[1]>DIVMFI[2]) THEN
    extremumMFI2=DIVMFI[1]
    extremumMFI1=highest[n](DIVMFI)
    preciomaxMFI2=close[1]
    preciomaxMFI=Highest[n](close)
    IF(extremumMFI2<extremumMFI1 AND preciomaxMFI2>preciomaxMFI[1]) THEN
    for i=mbr to n
    if DIVMFI[i]=extremumMFI1 then
    cDIVMFI = 1
    Endif
    next
    Endif
    Endif
    Endif
    
    //.................................................................................................................
    
    DIVRSI = RSI[14](close)
    
    IF (BarIndex > n) THEN
    IF (DIVRSI[1]>DIVRSI AND DIVRSI[1]>DIVRSI[2]) THEN
    extremumRSI2=DIVRSI[1]
    extremumRSI1=highest[n](DIVRSI)
    preciomaxRSI2=close[1]
    preciomaxRSI=Highest[n](close)
    IF(extremumRSI2<extremumRSI1 AND preciomaxRSI2>preciomaxRSI[1]) THEN
    for i=mbr to n
    if DIVRSI[i]=extremumRSI1 then
    cDIVRSI = 1
    Endif
    next
    Endif
    Endif
    Endif
    
    //.................................................................................................................
    
    DIVMOM = Momentum[12](close)
    
    If (BarIndex > n) THEN
    If (DIVMOM[1]>DIVMOM AND DIVMOM[1]>DIVMOM[2]) THEN
    extremumMOM2=DIVMOM[1]
    extremumMOM1=highest[n](DIVMOM)
    preciomaxMOM2=close[1]
    preciomaxMOM=Highest[n](close)
    If(extremumMOM2<extremumMOM1 AND preciomaxMOM2>preciomaxMOM[1]) THEN
    for i=mbr to n
    If DIVMOM[i]=extremumMOM1 then
    cDIVMOM = 1
    Endif
    next
    Endif
    Endif
    Endif
    
    //.................................................................................................................
    
    
    
    IF td and tt then
    IF cDIVMFI = 1 and cDIVRSI = 1 and cDIVMOM = 1 then
    buy at market
    ENDIF
    ENDIF
    
    
    IF onmarket then
    cDIVMFI = 0
    cDIVRSI = 0
    cDIVMOM = 0
    ENDIF
    
    
    
    set stop ploss 40
    set target pprofit 40
    

    Im Anhang sind 2 Screenshots selbsterklärend. Man kann gut erkennen, dass das System nicht macht was es soll.
    Kannst du mir dabei helfen den Fehler zu finden und zu beheben?

    Liebe Grüße
    JohnScher

    #205478 quote
    JohnScher
    Participant
    Veteran

    Screenshots

    #205487 quote
    robertogozzi
    Moderator
    Master

    Eine Weile und richtig aussteigen, auf den DAX, 1 Minute. Geben Sie ein, wenn die 3 Bedingungen erfüllt sind (die zurückgesetzt werden, wenn es bereits auf dem Markt ist).

    JohnScher thanked this post
    #205489 quote
    robertogozzi
    Moderator
    Master

    Ich hänge ein Bild an.

Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.

Nochmal Divergenzen, mehrere


ProOrder: Automatischer Handel & Backtesting

New Reply
Author
author-avatar
f1_maik @f1_maik Participant
Summary

This topic contains 16 replies,
has 4 voices, and was last updated by robertogozzi
3 years ago.

Topic Details
Forum: ProOrder: Automatischer Handel & Backtesting
Language: German
Started: 10/25/2022
Status: Active
Attachments: 15 files
Logo Logo
Loading...