//By: Reden Darunday Gallera
//fastPeriod = 4
//slowPeriod = 8
//SmthLen = 3
set TopBand = 0.5
set LowBand = -0.5
#Arnaud Legoux Moving Average
Set ALMA9 = ALMA(Close, 9, 0.85, 6)
set xPrice = close
//TSI
set xPrice1 = xPrice - ref(xPrice,1)
set xPrice2x = xPrice - ref(xPrice,1)
set xPrice2 = abs(xPrice2x)
//fastPeriod = 4
set xSMA_Rx = ema(xPrice1,4)
set xSMA_aRx = ema(xPrice2, 4)
//slowPeriod = 8
set xSMA_R = ema(xSMA_Rx,8)
set xSMA_aR = ema(xSMA_aRx,8)
set xSMIx = xSMA_R / xSMA_aR
//If xSMA_aR = 0, I set result value to Zero instead of infinite
//SMI Line
set xSMI = if(xSMA_aR=0,0, xSMIx )
//SmthLen = 3 for SMI Signal
set xEMA_SMI = ema(xSMI, 3)
set Below =Crossover( xEMA_SMI, LowBand)
set Top = Crossover(xEMA_SMI, TopBand)
Set x = Top or Below
set osc = xSMI - xEMA_SMI
set XUP = crossover(xSMI, xEMA_SMI)
set XDown = crossover(xEMA_SMI, xSMI)
set Buy = XUP and close >= ALMA9
set Sell = XDown and close < ALMA9
####################################
//plot buy/sell
//plot(Buy ,buy,green,main)
//plot(Sell ,sell,red,main)
//plot Below and Top on SMIO area
plot(XDown ,buy,red,smio:xSMI)
plot(XUP ,sell,green,smio:xSMI)
##################################
//Uncomment this line and comment all above plot commands for a cleaner flags
plotbuysell(Buy,Sell,green,red,main)
##################################
//Plot the SMI Lines
plot(osc ,bar,any,smio)
plot(xEMA_SMI, line, red, smio)
plot(xSMI, line, blue, smio)
Plot(ALMA9, Line,Any, Main)
Signals(Buy,Sell)
