vorrei creare un codice che
entra short quando il prezzo incrocia a rialzo pivot resistenza 1 e lo stesso resistenza 2 e 3
entra long quando il prezzo incrocia a ribasso supporto 1 2 e 3
stop loss 10 punti (da ottimizzare)
profit dopo 5 punti
grazie
Ho codificato la strategia per te, ti preghiamo di trovarla qui sotto:
defparam cumulateorders=false
//Pivot calculation method
Once mode = 1
Once dailyPivot = undefined
Once dailyR1 = undefined
Once dailyS1 = undefined
Once dailyR2 = undefined
Once dailyS2 = undefined
Once dailyR3 = undefined
Once dailyS3 = undefined
If Day>Day[1] then
If mode = 0 then
dailyPivot = (DHigh(1) + DLow(1) + Close[1]) / 3
Elsif mode = 1 then
dailyPivot = (Open + DHigh(1) + DLow(1) + Close[1]) / 4
Elsif mode = 2 then
dailyPivot = (DHigh(1) + DLow(1) + Close[1]*2) / 4
Else
dailyPivot = (Open*2 + DHigh(1) + DLow(1)) / 4
Endif
dailyR1 = 2*dailyPivot - DLow(1)
dailyS1 = 2*dailyPivot - DHigh(1)
dailyR2 = dailyPivot + (DHigh(1) - DLow(1))
dailyS2 = dailyPivot - (DHigh(1) - DLow(1))
dailyR3 = dailyR1 + (DHigh(1) - DLow(1))
dailyS3 = dailyS1 - (DHigh(1) - DLow(1))
Endif
if close crosses over dailyr1 or close crosses over dailyr2 or close crosses over dailyr3 then
buy 1 contract at market
endif
if close crosses under dailys1 or close crosses under dailys2 or close crosses under dailys3 then
sellshort 1 contract at market
endif
set target pprofit 5
set stop ploss 10
ciao Nicolas
ma dal backtest vedo che il codice non entra quando il prezzo incrocia a rialzo o a ribasso il pivot o non sempre
Non ero ancora sicuro del livello del perno, ecco il codice modificato di conseguenza:
defparam cumulateorders=false
//Pivot calculation method
Once mode = 1
Once dailyPivot = undefined
Once dailyR1 = undefined
Once dailyS1 = undefined
Once dailyR2 = undefined
Once dailyS2 = undefined
Once dailyR3 = undefined
Once dailyS3 = undefined
If Day>Day[1] then
If mode = 0 then
dailyPivot = (DHigh(1) + DLow(1) + Close[1]) / 3
Elsif mode = 1 then
dailyPivot = (Open + DHigh(1) + DLow(1) + Close[1]) / 4
Elsif mode = 2 then
dailyPivot = (DHigh(1) + DLow(1) + Close[1]*2) / 4
Else
dailyPivot = (Open*2 + DHigh(1) + DLow(1)) / 4
Endif
dailyR1 = 2*dailyPivot - DLow(1)
dailyS1 = 2*dailyPivot - DHigh(1)
dailyR2 = dailyPivot + (DHigh(1) - DLow(1))
dailyS2 = dailyPivot - (DHigh(1) - DLow(1))
dailyR3 = dailyR1 + (DHigh(1) - DLow(1))
dailyS3 = dailyS1 - (DHigh(1) - DLow(1))
Endif
if close crosses over dailyr1 or close crosses over dailyr2 or close crosses over dailyr3 or close crosses over dailypivot then
buy 1 contract at market
endif
if close crosses under dailys1 or close crosses under dailys2 or close crosses under dailys3 or close crosses under dailypivot then
sellshort 1 contract at market
endif
set target pprofit 5
set stop ploss 10
ciao Nicolas
scusami ma io sono alle prime armi
non esitite un comando che fa entrate appena il prezzo tocca il pivot e non alla chiusura della barra?
Dovrebbe essere possibile con questo codice:
defparam cumulateorders=false
//Pivot calculation method
Once mode = 1
Once dailyPivot = undefined
Once dailyR1 = undefined
Once dailyS1 = undefined
Once dailyR2 = undefined
Once dailyS2 = undefined
Once dailyR3 = undefined
Once dailyS3 = undefined
If Day>Day[1] then
If mode = 0 then
dailyPivot = (DHigh(1) + DLow(1) + Close[1]) / 3
Elsif mode = 1 then
dailyPivot = (Open + DHigh(1) + DLow(1) + Close[1]) / 4
Elsif mode = 2 then
dailyPivot = (DHigh(1) + DLow(1) + Close[1]*2) / 4
Else
dailyPivot = (Open*2 + DHigh(1) + DLow(1)) / 4
Endif
dailyR1 = 2*dailyPivot - DLow(1)
dailyS1 = 2*dailyPivot - DHigh(1)
dailyR2 = dailyPivot + (DHigh(1) - DLow(1))
dailyS2 = dailyPivot - (DHigh(1) - DLow(1))
dailyR3 = dailyR1 + (DHigh(1) - DLow(1))
dailyS3 = dailyS1 - (DHigh(1) - DLow(1))
Endif
if close>dailyr3 then
sellshort 1 contract at dailyr3 stop
elsif close<dailyr3 and close>dailyr2 then
sellshort 1 contract at dailyr2 stop
buy 1 contract at dailyr3 stop
elsif close<dailyr2 and close>dailyr1 then
sellshort 1 contract at dailyr1 stop
buy 1 contract at dailyr2 stop
elsif close<dailyr1 and close>dailypivot then
sellshort 1 contract at dailypivot stop
buy 1 contract at dailyr1 stop
elsif close<dailypivot and close>dailys1 then
sellshort 1 contract at dailys1 stop
buy 1 contract at dailypivot stop
elsif close<dailys1 and close>dailys2 then
sellshort 1 contract at dailys2 stop
buy 1 contract at dailys1 stop
elsif close<dailys2 and close>dailys3 then
sellshort 1 contract at dailys3 stop
buy 1 contract at dailys2 stop
elsif close<dailys3 then
buy 1 contract at dailys3 stop
endif
set target pprofit 5
set stop ploss 10
Questo codice utilizza ordini in sospeso, è consapevole che per utilizzare questo tipo di ordini, il prezzo effettivo deve essere conforme alle limitazioni del broker per metterle sul mercato (almeno X pips dal prezzo)
Non l’ho provata, per favore le tue simulazioni e le tue prove e per ricevere feedback….