Indicator Cheat Mode
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ExoPlanetaryEdu

//@version=5
indicator("Cheat Mode Enabled", overlay = true)


//MACD Variables
fastLength = input.int( defval=12, title="Fast Length") 
slowLength = input.int( defval=26, title="Slow Length")
MACDLength = input.int( defval=9, title="MACD Length")
//Stochastic Variables
KPeriod = input.int( defval=14, title="Stochastic K Period") 
DPeriod = input.int( defval=3, title="Stochastic D Period") 
smoothK = input.int(1, title="%K Smoothing", minval=1)
//RSI Variable
RSILength = input.int( defval=9, title="RSI Length")
Midpt = 0.00

// MACD histogram change

//Get the MACD 
[macdLine, signalLine, histLine] = ta.macd(close, fastLength, slowLength, MACDLength)


//Set Buy to be when the the hist is lower than previous candle but that previous candle is higher than it's previous (Previous candle is a peak)
MACDBuy = histLine > histLine [1] and histLine[1] < histLine [2] 
//Set Sell to be opposite (Negative Peak)
MACDSell = histLine < histLine [1] and histLine[1] > histLine [2]
//plotshape(MACDBuy, title="MACD", location=location.belowbar, color=color.green, style=shape.triangleup, text="MACDBuy", textcolor=color.green)
//plotshape(MACDSell, title="MACD", location=location.abovebar, color=color.red, style=shape.triangledown, text="MACDSell", textcolor=color.red)


//Stochastic slowK14  SlowD3

k = ta.sma(ta.stoch(close, high, low, KPeriod), smoothK)
d = ta.sma(k, DPeriod)

//Set Buy to be when K is greater than D but between 80 and 30, Do not want to buy with K having no up side room, or buy when in a low state
StochBuy = k > k[1] and k[1] > k[2] and k > 30
//Set sell to be when k is less than D
StochSell =k < k[1] and k[1] < k[2]
//plotshape(StochBuy, title="Stoch", location=location.belowbar, color=color.green, style=shape.triangleup, text="StochBuy", textcolor=color.green)
//plotshape(StochSell, title="Stoch", location=location.abovebar, color=color.red, style=shape.triangledown, text="StochSell", textcolor=color.red)



//Get RSI
RSIValue = ta.rsi(close, RSILength)
//set buy to be RSI rising for 2 periods but still less than overbought (70)
RSIBuy = (RSIValue > RSIValue[1]) and (RSIValue > RSIValue[2]) and RSIValue < 70
//Set sell to be RSI falling for 2 periods but still not oversold
RSISell = (RSIValue < RSIValue[1]) and (RSIValue < RSIValue[2]) and RSIValue > 30
//RSI troubleshooting
//plotshape(RSIBuy, title="RSI", location=location.belowbar, color=color.green, style=shape.triangleup, text="RSIBuy", textcolor=color.green)
//plotshape(RSISell, title="RSI", location=location.abovebar, color=color.red, style=shape.triangledown, text="RSISell", textcolor=color.red)

//Buy-sell stock definitions
BuyStock = (StochBuy  and  RSIBuy and  (MACDBuy  or MACDBuy[1]))
SellStock = (StochSell and  RSISell and (MACDSell  or MACDSell[1])) 


//Plot Shapes
plotshape(SellStock, title="Sell", location=location.abovebar, color=color.red, style=shape.triangledown, text="Sell", textcolor=color.red)
plotshape(BuyStock, title="Buy", location=location.belowbar, color=color.green, style=shape.triangleup, text="Buy", textcolor=color.green)

//if (open > close)
//    Midpt := low
//if (close > open)
//    Midpt := high
//if (open == close)
//   Midpt := open

//if ((Midpt > Midpt[1]) and (Midpt[1] >= Midpt[2]))
//    Midpt[1] == (Midpt + Midpt[2])/2
    
//plot(Midpt, color=color.red, linewidth=2)



