//————————————————————————-
// Main code : SAF40 Mini 1H
//————————————————————————-
// indicators and parameters
defparam cumulateorders = false
possize = 2
// Förklaring vad fastma / slowma [8,1] innebär.
//0 = Simple,
//1 = Exponential,
//2 = Weighted,
//3 = Wilder’s Smoothed,
//4 = Triangular,
//5 = End Point, and
//6 = Time Series.
fastma = average[8,1](close)
slowma = average[38,6](close)
longma = average[40,6](close)
bbw = bollingerbandwidth[240](close)
price = close
notradetime = (dayofweek = 5 and time > 230000) or (dayofweek = 1 and time < 013000)
once buyswitch = 0
once sellswitch = 0
if fastma crosses over slowma then
tlevel = high
buyswitch = 1
sellswitch = 0
endif
if fastma crosses under slowma then
tlevel = low
sellswitch = 1
buyswitch = 0
endif
// long entries and short exits
if buyswitch = 1 and price > tlevel and fastma > slowma and bbw > 0.0359 and price > longma and not notradetime then
buy possize contract at market
exitshort at market
endif
// short entries and long exits
if sellswitch = 1 and price < tlevel and fastma < slowma and bbw > 0.0359 and price < longma and not notradetime then
sellshort possize contract at market
sell at market
endif
// stops and targets
set stop ploss 3400 // Org 3400
set target pprofit 1340 // Org 1340
// exit strategy
once tradeext = 0
if countofposition < countofposition[1] then
tradeext = 0
endif
if countoflongshares = possize and high > (positionprice + 910) then
tradeext = 910
endif
if tradeext = 910 then
sell at positionprice + 465 stop
endif
if countofshortshares = possize and low < (positionprice – 910) then
tradeext = -910
endif
if tradeext = -910 then
exitshort at positionprice – 465 stop
endif