Nel codice trovato in libreria (allego) ho aggiunto un loss e profit, ma essendo il TF giornaliero , gli stessi operano a fine giornata e il drawdown è veramente alto. Vorrei limitarlo agendo sul loss e profit che dovrebbero agire dentro la candela, ma non so se è possibile.
Grazie a chi mi può aiutare.
//Universal XBody STrategy
// instrument: DAX
// timeframe : Daily
// Spread: 4
// created and coded by davidelaferla
//————————————————————————-
//————————————————————————-
defparam cumulateorders=false
//***********************************************************************************************************
N = 1
//—————— SYSTEM VARIABLES—————————————
//CAC40 Values: ——————————————– Ottimization info
period=per// Optimize best value for each Symbol, range=1-1000, with step=1
mode=md// Optimize the best trading mode , range=1-4, with step=1
invertsignal=inv// 1=positive signal, -1=negative signal, range=-1-1, with step=2
//***********************************************************************************************
//—————— SYSTEM FILTER—————————————
filter1=fl1// to set after the variable optimization, range=1-100, with step=1
filter2=fl2// to set after the variable optimization, range=0-100, with step=1
//—————— INDICATOR —————————————
body=close-open
var=(body-body[1])
sumvar=summation[period](var)
if sumvar>filter1*pipsize then
green=(sumvar)
endif
if sumvar<-filter2*pipsize then
red=(sumvar)
endif
if mode=1 then
c1=red<red[1]
c2=green>green[1]
endif
if mode=2 then
c1=red>red[1]
c2=green<green[1]
endif
if mode=3 then
c1=red<red[1]
c2=green<green[1]
endif
if mode=4 then
c1=red>red[1]
c2=green>green[1]
endif
if c1 then
signal=1*invertsignal
elsif c2 then
signal=-1*invertsignal
endif
// Conditions for entering long positions and exit short positions
IF signal>0 then
BUY n contract AT market
ENDIF
// Conditions for entering short positions and exit long positions
IF signal<0 THEN
SELLSHORT n CONTRACTs AT market
SET STOP LOSS l*AverageTrueRange[10](close)
SET TARGET PROFIT p*AverageTrueRange[12](close)
ENDIF
secondo me l’unico modo è inserire un TF diverso sulla parte di esecuzione e inserire un timeframe giornaliero sull’indicatore, per esempio:
//Universal XBody STrategy
// instrument: DAX
// timeframe : Daily
// Spread: 4
// created and coded by davidelaferla
//————————————————————————-
//————————————————————————-
defparam cumulateorders=false
Timeframe ( 1 day, updateonclose)
//***********************************************************************************************************
N = 1
//—————— SYSTEM VARIABLES—————————————
//CAC40 Values: ——————————————– Ottimization info
period=per// Optimize best value for each Symbol, range=1-1000, with step=1
mode=md// Optimize the best trading mode , range=1-4, with step=1
invertsignal=inv// 1=positive signal, -1=negative signal, range=-1-1, with step=2
//***********************************************************************************************
//—————— SYSTEM FILTER—————————————
filter1=fl1// to set after the variable optimization, range=1-100, with step=1
filter2=fl2// to set after the variable optimization, range=0-100, with step=1
//—————— INDICATOR —————————————
body=close-open
var=(body-body[1])
sumvar=summation[period](var)
if sumvar>filter1*pipsize then
green=(sumvar)
endif
if sumvar<-filter2*pipsize then
red=(sumvar)
endif
if mode=1 then
c1=red<red[1]
c2=green>green[1]
endif
if mode=2 then
c1=red>red[1]
c2=green<green[1]
endif
if mode=3 then
c1=red<red[1]
c2=green<green[1]
endif
if mode=4 then
c1=red>red[1]
c2=green>green[1]
endif
if c1 then
signal=1*invertsignal
elsif c2 then
signal=-1*invertsignal
endif
Timeframe ( 1 hour, default)
// Conditions for entering long positions and exit short positions
IF signal>0 then
BUY n contract AT market
ENDIF
// Conditions for entering short positions and exit long positions
IF signal<0 THEN
SELLSHORT n CONTRACTs AT market
SET STOP LOSS l*AverageTrueRange[10](close)
SET TARGET PROFIT p*AverageTrueRange[12](close)
ENDIF
da adattare i valori di AverageTrueRange, perchè lavoranso ull’orario, quidni da moltiplicare per 24 presumo
Lo sto provando, ma mi da l’errore che allego
Devi usare un TF di 1 ora o minore (però se minore, bisogna che 60, che sono i minuti di un’ora ne siano multipli).