DEFPARAM CumulateOrders = False // Acumulación de posiciones desactivada
DEFPARAM FLATBEFORE = 100000
// Cancel all pending orders and close all positions at the "FLATAFTER" time
DEFPARAM FLATAFTER = 173000
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
c70=not daysForbiddenEntry
if intradaybarindex = 0 then
p=0
m=0
pp=0
mm=0
equitycurve = 0
endif
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
//variables
//equitycurve = undefined
p=undefined
m=undefined
pp=undefined
mm=undefined
//indicators
i1 = average[p,m](close)
i2 = average[pp,mm](close)
//equitycurve = average[curveperiod](strategyprofit)
//trades conditions
long = i1 crosses over i2
short = i1 crosses under i2
//mydays variable incrementing to let the average curve build over time
//if date > olddate then
//mydays=mydays+1
//olddate = date
//endif
start=070000
end=100000
c69=(time>start and time<end)
//trades when the curve has built
if not onmarket then
mystrategyprofit=strategyprofit and c69
elsif long then
mystrategyprofit=strategyprofit+(close-tradeprice)/pointsize*pointvalue*countoflongshares
elsif short then
mystrategyprofit=strategyprofit+(tradeprice-close)/pointsize*pointvalue*countofshortshares
endif
//equitycurve = exponentialaverage[a](mystrategyprofit)
if strategyprofit>=equitycurve then
p=p
pp=pp
m=m
mm=mm
endif
GRAPH mystrategyprofit as "strategy profit"
GRAPH equitycurve coloured(255,0,0) as "profit curve"
IF long AND strategyprofit>=equitycurve and c70 THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
//exit positions
IF short THEN
SELL AT MARKET
ENDIF