buon giorno,
ieri ho provato a far girare questo nuovo sistema che sfrutta l’indicatore perfect trend v2 di nicolas, tuttavia una volta montato rigettava gli ordini dicendo che era impostato un numero massimo delle posizioni =0 e quindi stoppava il sistema.
allego il sistema se qualcuno riuscisse a capire l’errore ne sarei grato.
stefano
//dax 5 minuti
DEFPARAM CUMULATEORDERS =FALSE
DEFPARAM FLATBEFORE=060000
DEFPARAM FLATAFTER=220000
once contratto=1
ONCE signal=0
ONCE START=0
//indicatori e variabili
//perfect trend v2 by @nicolas
myfastline, myslowline, mytrend = CALL "PRC_PerfectTrendLine 2"[7, 3]
//indicatori
ema200=ExponentialAverage[200](close)
iadx=ADX[20]
myadx=ADXR[20]
adxtrend= iadx>iadx[1] and myadx>myadx[1]
adxnontrend= iadx<iadx[1]and myadx<myadx[1]
STOK= Stochastic[20,3](close)
STOKLONG=STOK<75
STOKSHORT=STOK>15
MYSTOK= Average[10](STOK)
MYSTOKLONG= MYSTOK<60
MYSTOKSHORT=MYSTOK>30
MYSTOKKELONG= STOK>MYSTOK
MYSTOKKESHORT=STOK<MYSTOK
//condizioni dell'indicatore perfect trend ingresso
if close>myslowline and close> myfastline then
START=1
elsif close<myfastline and close <myslowline then
START=2
ENDIF
// 4 condizioni di entry
if close> ema200 and START=1 THEN
IF close >DonchianChannelUp[10]and adxtrend AND MYSTOKLONG AND STOKLONG AND MYSTOKKELONG then
signal=1
ELSe
SIGNAL=0
endif
ENDIF
if close< ema200 and START =2 THEN
IF close<DonchianChannelDown[10] and adxtrend AND MYSTOKSHORT AND STOKSHORT AND MYSTOKKESHORT then
signal=-1
ELSE
SIGNAL=0
endif
ENDIF
if close> ema200 and start=2 then
IF close<DonchianChannelDown[10] and adxnontrend AND MYSTOKSHORT AND STOKSHORT AND MYSTOKKESHORT then
signal=-2
ELSE
SIGNAL=0
endif
ENDIF
if close< ema200 and start=1 then
IF close >DonchianChannelUp[10]and adxnontrend AND MYSTOKLONG AND STOKLONG AND MYSTOKKELONG then
signal=2
ELSe
SIGNAL=0
endif
ENDIF
//apertura delle posizioni
IF NOT ONMARKET AND SIGNAL=1 THEN
TRADE=1
ENTRY=CLOSE
MINIMO= (DonchianChannelDown[10])
STOPPE= ABS(ENTRY-MINIMO)*pipsize
TARGETTE= STOPPE
BUY contratto CONTRACT AT MARKET
ENDIF
IF NOT ONMARKET AND SIGNAL=2 THEN
TRADE=2
ENTRY=CLOSE
MINIMO= ROUND (DonchianChannelDown[10])
STOPPE= ABS(ENTRY-MINIMO)*pipsize
TARGETTE= STOPPE
BUY contratto CONTRACT AT MARKET
ENDIF
IF NOT ONMARKET AND SIGNAL=-1 THEN
TRADE=-1
ENTRY=CLOSE
MASSIMO= ROUND (DonchianChannelUP[10])
STOPPE= ABS(ENTRY- MASSIMO)*pipsize
TARGETTE= STOPPE
SELLSHORT contratto CONTRACT AT MARKET
ENDIF
IF NOT ONMARKET AND SIGNAL=-2 THEN
TRADE=-2
ENTRYS=CLOSE
MASSIMO= ROUND (DonchianChannelUP[10])
STOPPE= ABS(entrys-massimo)*pipsize
TARGETTE= STOPPE
SELLSHORT contratto CONTRACT AT MARKET
ENDIF
SET STOP LOSS STOPPE
SET TARGET PROFIT TARGETTE
// nicolas MFE trailing stop
trailingstop = 20
//resetting variables when no trades are on market
if not onmarket then
MAXPRICE = 0
MINPRICE = close
priceexit = 0
endif
//case SHORT order
if shortonmarket then
MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
endif
endif
//case LONG order
if longonmarket then
MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
endif
endif
//exit on trailing stop price levels
if onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
endif
Il backtest funziona; l’ho messo in demo, ma ormai occorre attendere la riapertura dei mercati per vedere cosa succede quando entrerà in esecuzione.
Appena saprò qualcosa ti avviserò.
grazie mille come al solito roberto 😀
L’ho meso in demo, sia come l’hai scritto tu, sia senza CALL (integrando l’indicatore nella strategia stessa). Mi ha aperto varie posizioni, nei due giorni in demo, senza nessun errore.
Non saprei darti una spiegazione.
Succede anche a me, tutti i giorni, da circa 6-8 mesi. Non sono riuscito a capire perché.