Buenos dias.
Estoy intentando programar algo muy sencillo, y cuando corro el backtest, los resultados en cuanto al numero de operaciones son diferentes solo con cambiar el numero de contratos (marcar/desmarcar filas 23/24), lo cual no tiene mucho sentido.
Con el numero de contratos “fijo”, salen 35 operaciones. Con el numero de contratos “calculado”, salen 2 operaciones.
Instrumento LCO (Brent 1€), TF 5 minutos y 10k unidades.
Alguien sabe porque??? Porque no tiene ninguna logica.
DEFPARAM CumulateOrders = False
DEFPARAM FLATBEFORE = 000500
DEFPARAM FLATAFTER = 230000
//Variables
Capital=20000+STRATEGYPROFIT
Riesgo=0.005
//Incializar variables
If intradaybarindex = 0 then
Largo = 1
Corto = 1
AbrirLargos = 1
AbrirCortos = 1
operar = 1
endif
TIMEFRAME(daily, default)
c0=Close
ATR0=averagetruerange[1]
Contratos=(Capital*Riesgo)/(ATR0)*pointsize
//Contratos = 2
TIMEFRAME(default)
If longonmarket then
AbrirCortos = 0
endif
If shortonmarket then
AbrirLargos = 0
endif
If Operar and AbrirLargos then
BUY Contratos CONTRACTS AT c0+50 stop
endif
If Operar and AbrirCortos then
SELLSHORT Contratos CONTRACTS at c0-50 stop
endif
IF onmarket and time>225930 then
SELL AT MARKET
EXITSHORT AT MARKET
endif
Con el número de contratos “calculados”, salen 2 operaciones.
¿Será quizás que con el tamaño del contrato ‘calculado’, a veces el tamaño calculado es menor que el mínimo para Brent?
Intente usar a continuación en la Línea 23 …
Contratos=min(2, (Capital*Riesgo)/(ATR0))*pointsize
Se debe al uso de decimales en el número de contratos.
Reemplace la línea 23 con:
Contratos=ceil((Capital*Riesgo)/(ATR0)*pointsize)