RK1383_2022_FRM
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RK1383
//@version=5
//indicator checks the fibonacci levels based on moving averages and makes buy and sell decision based on the RSI and MFI
// the moving average length is also based on the fibonacci numbers

indicator(title = "RK1383_2022_FRM", overlay = true)


//input data_Fibonacci
period = input(34, title="Fibonacci Avaraging period", tooltip = "select fibonacci numbers 8, 13, 21, 34, 55, 89, 144, 233")
price = input(hlc3, title="price")
mult = input(2.0, title="miltiplier")
//input data_moving average
ma_period = input (9, title="moving average period")
ma_price = input (hlc3, title="MA price")


//technical indicators
//trend:moving average crossovers
P_SMA = ta.sma(ma_price, ma_period)
P_WMA = ta.wma(ma_price, ma_period)
P_CO = P_WMA - P_SMA

//plot (P_CO, "Crossover", style = plot.style_columns)

//fibonacci bolinger bands
F_baseline = ta.wma(price,period)
deviation = ta.stdev(price,period) * mult

F_U_1= F_baseline + (0.236 * deviation)
F_U_2= F_baseline + (0.382*deviation)
F_U_3= F_baseline + (0.5*deviation)
F_U_4= F_baseline + (0.618*deviation)
F_U_5= F_baseline + (0.764*deviation)
F_U= F_baseline + (1*deviation)

F_L_1= F_baseline - (0.236 * deviation)
F_L_2= F_baseline - (0.382*deviation)
F_L_3= F_baseline - (0.5*deviation)
F_L_4= F_baseline - (0.618*deviation)
F_L_5= F_baseline - (0.764*deviation)
F_L= F_baseline - (1*deviation)



plot(F_baseline, color=color.new(color.green,10), linewidth=2)
plot(F_U_1, title="0.236",color=color.new(color.white,10), linewidth=1)
plot(F_U_2, title="0.382",color=color.new(color.white,10), linewidth=1)
plot(F_U_3, title="0.500",color=color.new(color.white,10), linewidth=1)
plot(F_U_4, title="0.618",color=color.new(color.white,10), linewidth=1)
plot(F_U_5, title="0.764",color=color.new(color.white,10), linewidth=1)
plot(F_U,   title="1.000",color=color.new(color.red,10),   linewidth=2)
plot(F_L_1, title="0.236",color=color.new(color.white,10), linewidth=1)
plot(F_L_2, title="0.382",color=color.new(color.white,10), linewidth=1)
plot(F_L_3, title="0.500",color=color.new(color.white,10), linewidth=1)
plot(F_L_4, title="0.618",color=color.new(color.white,10), linewidth=1)
plot(F_L_5, title="0.764",color=color.new(color.white,10), linewidth=1)
plot(F_L,   title="1.000",color=color.new(color.red,10),   linewidth=2)

//Volume: volume using MFI for selected period for close and hlc values. 
//momentum: momentum using RSI for selected period for close and hlc values.
mfi = ta.mfi(price, 13)
rsi = ta.rsi(price, 13)

//buysignal = close > F_U ? rsi > 70 ? mfi > 80 ? true : na :na :na
sellsignal = close[1] > F_U[1] ? close <F_U_5? rsi > 60 ? mfi > 50 ? high : na :na :na :na
plotshape(sellsignal, title='SELL', text='SELL', location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.maroon, 50), textcolor=color.new(color.white, 0))


buysignal = low[1] < F_L[1] ? close > F_L_5?  rsi <50 ?  low :na :na: na
plotshape(buysignal, title='BUY', text='BUY', location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, 50), textcolor=color.new(color.white, 0))
//ma crossovers
//WSMA_CO = ta.crossover(P_WMA, P_SMA)
//WSMA_CU = ta.crossunder(P_WMA, P_SMA)


  
    
 




//plot(rsi, "RSI", color=#7E57C2)
//plot (mfi, "MFI", color=#FF9800)
//plot(P_SMA, "SMA", color=#7E57C2)

//rsiUpperBand = hline(70, "RSI Upper Band", color=#787B86)
//mfiUpperBand = hline(80, "MFI Upper Band", color=#787B86)
//hline(50, "RSI Middle Band", color=color.new(#787B86, 50))
//rsiLowerBand = hline(30, "RSI Lower Band", color=#787B86)
//mfiLowerBand = hline(20, "MFI Lower Band", color=#787B86)
//fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 80), title="RSI Background Fill")
//fill(mfiUpperBand, mfiLowerBand, color=color.rgb(10, 50, 100, 70), title="MFI Background Fill")


//plot(close)


