ProRealCode - Trading & Coding with ProRealTime™
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 .
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?
Nachtrag Screenshot1
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
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?
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?
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..
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
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.
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
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.
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
Screenshots
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).
Ich hänge ein Bild an.
Nochmal Divergenzen, mehrere
This topic contains 16 replies,
has 4 voices, and was last updated by
robertogozzi
3 years ago.
| Forum: | ProOrder: Automatischer Handel & Backtesting |
| Language: | German |
| Started: | 10/25/2022 |
| Status: | Active |
| Attachments: | 15 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.