Ciao a tutti,
vorrei realizzare un TS che sfrutti il Donchian Channel per generare delle entrate a mercato.
L’idea è: guarda le ultime 10 barre (time frame: 4h oppure daily), se la barra attuale supera il canale superiore (inferiore) del Donchian Channel entra nella successiva Long (Short).
Stop loss a 1 ATR e profit target a 5 ATR (ATR a 10 giorni).
Qualcuno mi può aiutare?
Grazie mille!
Ho scritto questo codice, provalo:
DEFPARAM CumulateOrders = false
ONCE Periodi = 10
DonchianSUP = highest[Periodi](high[1])
DonchianINF = lowest[Periodi](low[1])
StopLoss = AverageTrueRange[Periodi](close)
TargetProfit = StopLoss * 5
// LONG
IF high > DonchianSUP THEN
BUY 1 CONTRACT AT MARKET
SET TARGET PROFIT TargetProfit
SET STOP LOSS StopLoss
ENDIF
// SHORT
IF low < DonchianINF THEN
SELLSHORT 1 CONTRACT AT MARKET
SET TARGET PROFIT TargetProfit
SET STOP LOSS StopLoss
ENDIF
iodi](high[1]) DonchianINF = lowest[Periodi](low[1])
Grazie mille, lo provo e ti dico! 🙂
Ciao,
invece di entrare “AT MARKET” alla barra successiva vorrei inserire un ordine di acquisto “STOP” sulla barra in corso, come posso fare?
Grazie mille
Prova questa versione
DEFPARAM CumulateOrders = true
ONCE Periodi = 10 //10 periodi per il calcolo del canale
// Gli ordini pendenti durano solo UNA barra, per cui vanno reimmessi ogni volta, se siamo a mercato
IF LongOnMarket THEN
SELL AT DonchianSUP + TargetProfit LIMIT //Target Profit
SELL AT DonchianSUP - StopLoss STOP //Stop Loss
ELSIF ShortOnMarket THEN
EXITSHORT AT DonchianINF - TargetProfit LIMIT //Target Profit
EXITSHORT AT DonchianINF + StopLoss STOP //Stop Loss
ELSE
// Determinare i bordi del canale DONCHIAN (quando non siamo a mercato)
DonchianSUP = highest[Periodi](high[1])
DonchianINF = lowest[Periodi](low[1])
// Definire Stop Loss & Target Profit
StopLoss = AverageTrueRange[Periodi](close)
TargetProfit = StopLoss * 5
ENDIF
// Entrare a mercato, se non lo siamo già, con ordini pendenti
IF Not OnMarket THEN
// LONG
BUY 1 CONTRACT AT DonchianSUP STOP //Entrata
SELL AT DonchianSUP + TargetProfit LIMIT //Target Profit
SELL AT DonchianSUP - StopLoss STOP //Stop Loss
// SHORT
SELLSHORT 1 CONTRACT AT DonchianINF STOP //Entrata
EXITSHORT AT DonchianINF - TargetProfit LIMIT //Target Profit
EXITSHORT AT DonchianINF + StopLoss STOP //Stop Loss
ENDIF
(io non l’ho testata)