Ciao ragazzi, premetto che non sono molto pratico con le programmazioni perchè il mio stile è discrezionale.
Detto ciò vorrei chiedere se qualche buon anima mi può dare una mano a modificare la scrittura della strategia supertrend di default per fare dei backtest
Quello che vorrei è:
- Sul settimanale se il Supertrend è verde cerca solo posizioni LONG
- Sul settimanale se il Supertrend è rosso cerca solo posizioni SHORT
TF OPERATIVO
- Giornaliero: Entra long quando c’è il cambio da rosso a verde / esci quando diventa rosso
- Giornaliero: Entra short quando c’è il cambio da verde a rosso / esci quando diventa verde
Ecco il codice che stai cercando. Prendiamo ordini su intervalli di tempo giornalieri Supertend che cambiano colore e con un filtro Supertrend dello stesso colore su base settimanale.
timeframe(weekly, updateonclose)
wst = Supertrend[3,10]
wlong = close>wst
wshort = close<wst
timeframe(daily,updateonclose)
dst = Supertrend[3,10]
if not longonmarket and close crosses over dst and wlong then
buy 1 contract at market
endif
if not shortonmarket and close crosses under dst and wshort then
sellshort 1 contract at market
endif
Grazie della risposta intanto..
L’ho appena provato ma noto che nel tf operativo, cioè il giornaliero, non chiude le operazioni quando c’è il cambio colore..
Sì, penso che sia correlato al modo in cui apro l'ordine solo in base al filtro settimanale. Nella versione modificata di seguito, gli ordini vengono chiusi solo in base al cambio colore giornaliero Supertrend, anche se una nuova condizione di ordine contrarian non è ancora soddisfatta:
timeframe(weekly, updateonclose)
wst = Supertrend[3,10]
wlong = close>wst
wshort = close<wst
timeframe(daily,updateonclose)
dst = Supertrend[3,10]
if longonmarket and close crosses under dst then
sell at market
endif
if shortonmarket and close crosses over dst then
exitshort at market
endif
if not longonmarket and close crosses over dst and wlong then
buy 1 contract at market
endif
if not shortonmarket and close crosses under dst and wshort then
sellshort 1 contract at market
endif
Ottimo così va benissimo.. grazie mille