//-------------------------------------------------------------------------
// Main code : Reversal/stochastic/heikni
//-------------------------------------------------------------------------
DEFPARAM CumulateOrders = False
sto = stochastic[8,3](close)
ATRValue = AverageTrueRange[14](close)
ema200 = ExponentialAverage[200](close)
c1 = close[1]<open[1] and close>open
c2 = close>open[1]
c3 = lowest[3](low)<lowest[50](low)[1] or lowest[3](low)<lowest[50](low)[2] or lowest[3](low)<lowest[50](low)[3]
c4 = sto<20 and close > ema200 // Tillagt krav om EMA200 för lång position
longCondition = c1 and c2 and c3 and c4
c5 = close[1]>open[1] and close<open
c6 = close<open[1]
c7 = highest[3](high)>highest[50](high)[1] or highest[3](high)>highest[50](high)[2] or highest[3](high)>highest[50](high)[3]
c8 = sto>80 and close < ema200 // Tillagt krav om EMA200 för kort position
shortCondition = c5 and c6 and c7 and c8
contractSize = 1
// Hantera Heikin Ashi
haClose = (open + high + low + close) / 4
haOpen = (open[1] + close[1]) / 2
haHigh = max(high, max(haClose, haOpen))
haLow = min(low, min(haClose, haOpen))
if barindex > 1 then
if longCondition and haClose > haOpen then
buy contractSize contract at market
set stop ploss lowest[3](low) - 1.75 * ATRValue
set target pprofit 5 * ATRValue
elsif shortCondition and haClose < haOpen then
sellshort contractSize contract at market
set stop ploss highest[3](high) + 1.75 * ATRValue
set target pprofit 5 * ATRValue
endif
endif