Prova questo dovrebbe andare:
defParam cumulateOrders = false
timeframe (4 Hours, updateOnClose)
xOpenH4 = open
xCloseH4 = (open + close + high + low) / 4
if barindex > 0 then
xOpenH4 = (xOpenH4[1] + xCloseH4[1]) / 2
endif
xLowH4 = min(low,min(xCloseH4,xOpenH4))
xHighH4 = max(high,max(xCloseH4,xOpenH4))
candelaVerdeH4 = xCloseH4 > xOpenH4
candelaRossaH4 = xCloseH4 < xOpenH4
//———————————————————————–
timeframe (5 minutes, updateOnClose)
xOpen = open
xClose = (open + close + high + low) / 4
if barindex > 0 then
xOpen = (xOpen[1] + xClose[1]) / 2
endif
xLow = min(low,min(xClose,xOpen))
xHigh = max(high,max(xClose,xOpen))
candelaVerde = xClose > xOpen
candelaRossa = xClose < xOpen
ema20 = average[20,1](xClose)
ema50 = average[50,1](xCLose)
//————————————————-
entrataLong = ema20 crosses over ema50
uscitaLong = ema20 crosses under ema50
entrataShort = ema20 crosses under ema50
uscitaShort = ema20 crosses over ema50
//——————————————————–
if not onMarket and candelaVerdeH4 and entrataLong then
buy 1 contract at market
endif
if longOnMarket and uscitaLong then
sell 1 contract at market
endif
if not onMarket and candelaRossaH4 and entrataShort then
sellShort 1 contract at market
endif
if shortOnMarket and uscitaShort then
exitShort 1 contract at market
endif