salve, qualcuno mi saprebbe dire perchè il prorealtime mi apre le posizionio in orari totalmente differenti da quelli da me indicati? grazie a tutti per il supporto
il codice è il seguente
defparam cumulateorders=false
time1=120000
time2=010000
time3=160000
time4=070000
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0 OR OpenDayOfWeek = 1 OR OpenDayOfWeek = 2
IF NOT LongOnMarket and time1 AND dayofweek=3 or dayofweek=4 or dayofweek=5 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
IF longonmarket and time2 THEN
SELL 1 CONTRACT AT MARKET
ENDIF
IF not longonmarket and time2 and dayofweek=5 THEN
SELL 1 CONTRACT AT MARKEt
ENDIF
//ribassista
if not shortonmarket and dayofweek=1 or dayofweek=5 and time2 then
sellshort 1 CONTRACT at market
endif
if shortonmarket and dayofweek=1 or dayofweek=5 and time1 then
exitshort at market
endif
if not shortonmarket and dayofweek=2 or dayofweek=4 and time4 then
sellshort 1 CONTRACT at market
endif
if shortonmarket and dayofweek=2 or dayofweek=4 and time4 then
exitshort at market
endif
la stringa daysforbiddenentry andava inibita, ho sbagliato a copiare, non tenetene conto
Perché alle righe 2-5 assegni un valore semplicemente, per cui sono SEMPRE vere.
Trasformale in:
time1 = time = 120000 //OpenTime
time2 = time = 010000 //OpenTime
time3 = time = 160000 //OpenTime
time4 = time = 070000 //OpenTime
ciao, intanto grazie per la delucidazione tuttavia nonostante abbia fatto la modifica descritta il prt continua ad aprire e chiudere posizioni quando vuole, allego schermata posizioni chiuse su crude oil ad 1 ora
il programma utilizzato è il seguente
defparam cumulateorders=false
time1=time=120000
time2=time=010000
time3=time=160000
time4=time=070000
IF NOT LongOnMarket and time1 AND dayofweek=3 or dayofweek=4 or dayofweek=5 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
IF longonmarket and time2 THEN
SELL 1 CONTRACT AT MARKET
ENDIF
IF not longonmarket and time2 and dayofweek=5 THEN
SELL 1 CONTRACT AT MARKEt
ENDIF
//ribassista
if not shortonmarket and dayofweek=1 or dayofweek=5 and time2 then
sellshort 1 CONTRACT at market
endif
if shortonmarket and dayofweek=1 or dayofweek=5 and time1 then
exitshort at market
endif
if not shortonmarket and dayofweek=2 or dayofweek=4 and time4 then
sellshort 1 CONTRACT at market
endif
if shortonmarket and dayofweek=2 or dayofweek=4 and time4 then
exitshort at market
endif
C’era anche un errore nelle precedenze degli operatori logici; è sempre meglio mettere le parentesi per indicare quale deve essere la precedenza tra gli operatori, specialmente quando ce ne sono vari su una stessa riga:
defparam cumulateorders=false
time1=time=120000
time2=time=010000
time3=time=160000
time4=time=070000
IF (NOT LongOnMarket) and time1 AND (dayofweek=3 or dayofweek=4 or dayofweek=5) THEN
BUY 1 CONTRACT AT MARKET
ENDIF
IF longonmarket and time2 THEN
SELL 1 CONTRACT AT MARKET
ENDIF
IF (not longonmarket) and time2 and dayofweek=5 THEN
SELL 1 CONTRACT AT MARKEt
ENDIF
//ribassista
if (not shortonmarket) and (dayofweek=1 or dayofweek=5) and time2 then
sellshort 1 CONTRACT at market
endif
if shortonmarket and (dayofweek=1 or dayofweek=5) and time1 then
exitshort at market
endif
if (not shortonmarket) and (dayofweek=2 or dayofweek=4) and time4 then
sellshort 1 CONTRACT at market
endif
if shortonmarket and (dayofweek=2 or dayofweek=4) and time4 then
exitshort at market
endif
ok, quindi la priorità è la seguente operazioni fuori dalla parentesi
operazioni dentro
e se volessi aggiungere anche una limitazione dell’operatività legata ai mesi? scrivo dentro la parentesi dei giorni oppure a parte? grazie
No, è l’opposto, come in qualunque espressione.
Le parentesi servono per cambiare l’ordine di precedenza, assegnandogli la priorità.
In 3 + 1 * 4 la moltiplicazione ha la precedenza, se vuoi darla all’addizione devi metterla tra parentesi (3 + 1) * 4, nel primo caso il risultato è 7, nel secondo è 16.
Per i mesi, se non devi legarli ad altro mettili al di fuori. Meglio se li metti all’interno di proprie parentesi.
devo comunque aggiungerli anche ai giorni della settimana, quindi suppongo che if (not longonmarket) and time1 and (dayofweek=3 or dayofweek=5) and (months=1 or months=6) then………… ho scritto months ma in realtà non so il comando giusto, ho cercato in giro ma trovo sempre riferimento ai giorni
salve, dopo aver modificato (spero correttamente il programma) funziona ma comunque con qualche errore
mi spiego meglio
il giorno 04/10/2016 entra short ed esce il giorno 5/10/2016 alle 16, questo orario è usato solo per le operazioni long e comunque solo per il venerdi…dayofweek=5, come mai questo errore? secondo me ce ne sono anche altri , cosa è scritto male? posto sia il codice che la lista di posizioni. grazie
defparam cumulateorders=false
time1=time=120000
time2=time=010000
time3=time=160000
time4=time=070000
//daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0 OR OpenDayOfWeek = 1 OR OpenDayOfWeek = 2
IF (NOT LongOnMarket) and (month>=1 and month<=4) and time1 AND (dayofweek=3 or dayofweek=4 or dayofweek=5) THEN
BUY 1 CONTRACT AT MARKET
ENDIF
IF longonmarket and time2 THEN
SELL 1 CONTRACT AT MARKET
ENDIF
IF longonmarket and time3 and dayofweek=5 THEN
SELL 1 CONTRACT AT MARKEt
ENDIF
//ribassista
if (not shortonmarket) and (month>=7 and month<=12) and (dayofweek=1 or dayofweek=5) and time2 then
sellshort 1 CONTRACT at market
endif
if shortonmarket and (dayofweek=1 or dayofweek=5) and time1 then
exitshort at market
endif
if (not shortonmarket) and (month>=10 and month<=11) and (dayofweek=2 or dayofweek=4) and time4 then
sellshort 1 CONTRACT at market
endif
if shortonmarket and (dayofweek=2 or dayofweek=4) and time4 then
exitshort at market
endif
set stop loss 127
ecco uno degli errori(presunti)
Per fare una prova occorre sapere su quale strumento e TF l’hai usato.
Ad ogni modo aggiungi queste righe alla fine del codice e guarda nella finestra delle variabili, alla fine del backtest, quali valori hanno candela per candela che ti risulti errata:
graph time1
graph time2
graph time3
graph time4
graph dayofweek
graph month
grazie per le info, una delucidazione: come si traduce questa stringa(tradestation) per calcolare lo stop loss con il prorealtime? grazie
if mp=0 then value1=c*bigpointvalue*0.03;
setstoploss(value1);