#--------------------------------------------------------------------------------------------------------#
//AOTS Strategy
//Buy when Close > MA20 AND MA20 > MA50 AND MA50 > MA100 AND RSI(14) > 70 AND Value > 5M AND 6-Month High
//Sell when Close < MA20 or when stoploss is hit (-4% from entry price)
#--------------------------------------------------------------------------------------------------------#
#MA 20
SET sma20 = SMA(CLOSE, 20)
PLOT(sma20, line, red, main)
#MA 50
SET sma50 = SMA(CLOSE, 50)
PLOT(sma50, line, yellow, main)
#MA 100
SET sma100 = SMA(CLOSE, 100)
PLOT(sma100, line, green, main)
#Value is greater than 5000000
SET isValueAbove5M = (CLOSE * VOLUME) > 5000000
//AOTS condition
SET aotsCondition = CLOSE > sma20 AND sma20 > sma50 AND sma50 > sma100 AND isValueAbove5M
//RSI(Price Vector, Periods)
SET rsi14 = RSI(CLOSE, 14)
//Stock must be at least at 6-month high
SET isSixMonthHigh = HHV(120) = HIGH
//Buy Signal
SET buySignal = aotsCondition AND rsi14 >= 70 AND isSixMonthHigh
//trail Stop
SET trailStop = CLOSE < sma20
//entry price
SET entryPrice = BLOCKREF(CLOSE, 0, buySignal, trailStop)
//day change
SET change = IF(entryPrice <> 0, (CLOSE - entryPrice) / entryPrice, 0)
//cutloss
SET cutloss = entryPrice <> 0 AND -0.04 > change
//Sell Signal
SET sellSignal = trailStop OR cutloss
//Plotting of buy and sell signals
PLOTBUYSELL(buySignal, sellSignal, green, red, main)
//SIGNALS(buyCondition, sellCondition)
SIGNALS(buySignal, sellSignal)