I found the baseline of this long only code online and did a few small changes to it.
It works as follow:
Entry rules:
Exit rule:
When the first entry rule is no longer true; exit.
DEFPARAM CumulateOrders = False
DEFPARAM PreloadBars = 200
//Position size
positionsize = 10
//Indicators
ma1 = average [2](close)
ma2 = average [7](close)
// Entry condition
// b1 = moving average at close of one day ago is greater than the moving average of today
// b2 = moving average at close 10 days ago is greater than the moving average of the close 11 days ago
b1 = ma1[1]>ma1[0]
b1 = b1 and ma1[10]>ma1[11]
b1 = b1 and close > ma2
// Entry
if b1 then
buy positionsize contracts at market
endif
// Exit
e1 = ma1[1]<=ma1[0]
if e1 then
sell at market
endif
// Stoploss
set stop ploss 100