defparam cumulateorders = false
REM Money Management
Capital = 10000
Risk = 0.01
StopLoss = 10 // Could be our variable X
REM Calculate contracts
equity = Capital + StrategyProfit
maxrisk = round(equity*Risk)
PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
bsize = 20 //renko size in points
mmperiod = 20 //moving average period
orderstime = 300 //minimum seconds between 2 orders
boxsize = bsize*pipsize
once topprice = close
once bottomprice = close - boxsize*pipsize*2
if(close > topprice + boxsize*2) THEN
topprice = close
bottomprice = topprice - boxsize*2
barclose=topprice
ELSIF (close < bottomprice - boxsize*2) THEN
bottomprice = close
topprice = bottomprice + boxsize*2
barclose = bottomprice
ELSE
topprice = topprice
bottomprice = bottomprice
ENDIF
mm = average[mmperiod](barclose)
if barclose=barclose[1] then
mmRENKO = mmRENKO[1]
else
mmRENKO = mm
endif
if barclose crosses over mmRENKO AND ABS(time-lasttime)>orderstime then
BUY PositionSize SHARES AT MARKET
EXITSHORT AT MARKET
lasttime=time
endif
if barclose crosses under mmRENKO AND ABS(time-lasttime)>orderstime then
SELLSHORT PositionSize SHARES AT MARKET
SELL AT MARKET
lasttime=time
endif