Candle Mania [starlord_xrp]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © starlord_xrp

//@version=5
indicator("Candle Mania [starlord_xrp]", overlay = true)

//fast volume weighted moving average that acts like a filter for uptrend or downtrend
ma = ta.vwma(close, 8)

//triggers 
bool doji_star = false
show_doji_star = input.bool(true, "Show Doji Star")
bool doji_long_leg_bull = false
bool doji_long_leg_bear = false
show_doji_long_leg = input.bool(true, "Show Long-Legged Doji")
bool morning_star = false
show_morning_star = input.bool(true, "Show Morning Star")
bool evening_star = false
show_evening_star = input.bool(true, "Show Evening Star")
bool no_trades = false
show_no_trades = input.bool(false, "Show No-Trading")
bool three_black_crows = false
show_three_black_crows = input.bool(false, "Show Three Black Crows")
bool three_white_soldiers = false
show_three_white_soldiers = input.bool(false, "Show Three White Soldiers")
bool grave_stone = false
show_gravestone = input.bool(true, "Show Gravestone")
bool dragenfly = false
show_dragonfly = input.bool(false, "Show Dragonfly")
bool hanging_man = false
show_hanging_man = input.bool(true, "Shwo Hanging Man")
bool hammer = false
show_hammer = input.bool(true, "Show Hammer")
bool inverted_hammer = false
show_inverted_hammer = input.bool(true, "Show Inverted Hammer")
bool bull_engulfing = false
show_bull_engulfing = input.bool(false, "Show Bullish Engulfing")
bool bear_engulfing = false
show_bear_engulfing = input.bool(false, "Show Bearish Engulfing")
bool dark_cloud = false
show_dark_cloud = input.bool(false, "Show Dark Cloud")
bool piercing_patern = false
show_piercing_patern = input.bool(false, "Show Piercing Pattern")
bool shooting_star = false
show_shooting_star = input.bool(true, "Show Shooting Star")
bool bearish_harami = false
show_bearish_harami = input.bool(false, "Show Bearish Harami")
bool bullish_harami = false
show_bullish_harami = input.bool(false, "Show Bullish Harami")
bool ha_bear = false
bool ha_bull = false
show_ha = input.bool(false, "Show Heiken Ashi Direction Changes On Chart")

//this lets the close and open be within 0.01% of each other to be counted as the same for dojis
bool open_close_same = close>open-(open*0.0001) and close<open+(open*0.0001)
bool close_high_same = close>high-(high*0.0001) and close<high+(high*0.0001)
bool close_low_same = close > low-(low*0.0001) and close < low+(low*0.0001)
bool open_high_same = open>high-(high*0.0001) and open<high+(high*0.0001)
bool open_low_same = open>low-(low*0.0001) and open<low+(low*0.0001)

//rsi
show_rsi = input.bool(true, "===Show RSI===", group = "RSI")
length = input.int(14, "RSI Length", group = "RSI")
src = input.source(close, "RSI Source", group = "RSI")
float rsi = ta.rsi(src, length)
rsi_over_bought = input.int(70, "RSI Over-bought Level", group = "RSI")
rsi_over_sold = input.int(30, "RSI Over-sold Level", group = "RSI")

//money flow index
show_mfi = input.bool(false, "===Show MFI===", group = "MFI" )
length2 = input.int(14, "MFI Length", group = "MFI")
mfi_over_bought = input.int(80, "MFI Over-bought Level", group = "MFI")
mfi_over_sold = input.int(20, "MFI Over-sold Level", group = "MFI")
src2 = hlc3
mfi = ta.mfi(src2, length2)

//stochastic RSI
show_stoch = input.bool(false, "===Show Stochastic RSI===", group = "Stochastic RSI")
smoothK = input.int(3, "K", minval=1, group = "Stochastic RSI")
smoothD = input.int(3, "D", minval=1, group = "Stochastic RSI")
lengthRSI = input.int(14, "RSI Length", minval=1, group = "Stochastic RSI")
lengthStoch = input.int(14, "Stochastic Length", minval=1, group = "Stochastic RSI")
src3 = input.source(close, title="Stochastic RSI Source", group = "Stochastic RSI")
stoch_over_bought = input.int(80, "Stochastic Over-bought Level", group = "Stochastic RSI")
stoch_over_sold = input.int(20, "Stochastic Over-sold Level", group = "Stochastic RSI")
rsi1 = ta.rsi(src3, lengthRSI)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)

// easy bull to caululate if the previous candle was up
bool bullrun = false
if close[1]>open[1]
    bullrun := true

//this just checks if the price did not move at all
if open == close and close==low and high==low and show_no_trades and barstate.isconfirmed
    no_trades := true

//dogi star
if open_close_same and (close-low == high-close) and close != low and show_doji_star and barstate.isconfirmed
    doji_star := true

//dogi long-legged
        //bear
if open_close_same and (close-low < high-close) and low != open and high != open and close>ma and show_doji_long_leg and barstate.isconfirmed
    doji_long_leg_bear := true
        //bull
if open_close_same and (close-low > high-close) and high != open and low != open and close<ma and show_doji_long_leg and barstate.isconfirmed
    doji_long_leg_bull := true

//gravestone doji
if open_close_same and (close==low or open==low) and high>open and high>close and close>ma and show_gravestone and barstate.isconfirmed
    grave_stone := true

// dragonfly
if open_close_same and (close==high or open==high) and low<open and low<close and rsi<rsi_over_bought and show_dragonfly and barstate.isconfirmed
    dragenfly := true

//hangman
if (close_high_same or open_high_same) and close>ma and show_hanging_man
    if close>open and close-open < (open-low)/2 and barstate.isconfirmed
        hanging_man := true
    if close<open and open-close < (close-low)/2 and barstate.isconfirmed
        hanging_man := true

//hammer
if (close_high_same or open_high_same) and close<ma and show_hammer
    if close>open and close-open < (open-low)/2 and barstate.isconfirmed
        hammer := true
    if close<open and open-close < (close-low)/2 and barstate.isconfirmed
        hammer := true

//bullish engulfing
if bullrun==false and close[1]>open and close>open[1] and close>open and show_bull_engulfing and barstate.isconfirmed
    bull_engulfing := true

//bearish engulfing
if bullrun and close[1]<open and close<open[1] and close<open and show_bear_engulfing and barstate.isconfirmed
    bear_engulfing := true

//dark cloud
if close[1]>ma and open>high[1] and close<(open[1]+close[1])/2 and show_dark_cloud and barstate.isconfirmed
    dark_cloud := true

//piercing pattern
if close[1]<ma and open<low[1] and close>(open[1]+close[1])/2 and close<open[1] and show_piercing_patern and barstate.isconfirmed
    piercing_patern := true

//evenging star
if close[2]>open[2] and open_close_same[1] and open[1]>close[2] and close<open and close<((open[2]+close[2])/2) and close[1]>ma and show_evening_star and barstate.isconfirmed
    evening_star := true

//morning star
if close[2]<open[2] and open_close_same[1] and open[1]<close[2] and close>open and close>((open[2]+close[2])/2) and close[1]<ma and show_morning_star and barstate.isconfirmed
    morning_star := true

//shooting star
if (close_low_same or open_low_same) and close>ma and show_shooting_star and close>ma
    if close>open and close-open < (high-close)/2 and barstate.isconfirmed
        shooting_star := true
    if close<open and open-close < (high-open)/2 and barstate.isconfirmed
        shooting_star := true

//inverted hammer
if (close_low_same or open_low_same) and close<ma and show_inverted_hammer and close<ma
    if close>open and close-open < (high-close)/2 and barstate.isconfirmed
        inverted_hammer := true
    if close<open and open-close < (high-open)/2 and barstate.isconfirmed
        inverted_hammer := true

//bearish harami
if bullrun and open<close[1] and open_close_same==false and close>open[1] and barstate.isconfirmed and close<open and close[1]>ma and show_bearish_harami and barstate.isconfirmed
    bearish_harami := true

//bullish harami
if bullrun==false and open>close[1] and close<open[1] and close>open and open_close_same==false and close[1]<ma and show_bullish_harami and barstate.isconfirmed 
    bullish_harami := true

//three black crows
if close[2]<open[3] and close[2]<close[3] and open[1]>close[2] and close[1]<close[2] and open>close[1] and close<close[1] and show_three_black_crows and barstate.isconfirmed
    three_black_crows := true

//three whise soldiers
if close[2]>open[3] and close[2]>close[3] and open[1]<close[2] and close[1]>close[2] and open<close[1] and close>close[1] and show_three_white_soldiers and barstate.isconfirmed
    three_white_soldiers := true

//heiken ashi trend turns
if show_ha and request.security(ticker.heikinashi(syminfo.tickerid), "", close>open) and ta.change(request.security(ticker.heikinashi(syminfo.tickerid), "", close>open))
    ha_bull := true
if show_ha and ta.change(request.security(ticker.heikinashi(syminfo.tickerid), "", close<open)) and request.security(ticker.heikinashi(syminfo.tickerid), "", close<open)
    ha_bear := true

//plots
plotshape(doji_star and bullrun, "", shape.cross, location.abovebar, color.red, 0, "Doji Star", textcolor = color.red, size = size.tiny)
plotshape(doji_star and bullrun==false, "", shape.cross, location.belowbar, color.green, 0, "Doji Star", textcolor = color.green, size = size.tiny)
plotchar(morning_star, "", "⭐", location.belowbar, color.green, -1, "Morning Star", textcolor = color.green, size = size.tiny)
plotchar(evening_star, "", "⭐", location.abovebar, color.red, -1, "Evening Star", textcolor = color.red, size = size.tiny)
plotchar(doji_long_leg_bear, "", "🦵", location.abovebar, color.red, 0, "Long-Leg Doji", color.red, size = size.tiny)
plotchar(doji_long_leg_bull and bullrun==false, "", "🦵", location.belowbar, color.green, 0, "Long-Leg Doji", textcolor = color.green, size = size.tiny)
plotshape(no_trades, "no trades", shape.xcross, location.abovebar, color.gray, 0, "No Trades", textcolor = color.gray, size = size.tiny)
plotchar(grave_stone, "", "💀", location.abovebar, color.red, 0, "Gravestone", textcolor = color.red, size = size.tiny)
plotchar(dragenfly, "", "🐉", location.belowbar, offset = 0, text = "Dragonfly", textcolor = color.green, size = size.tiny)
plotchar(hammer, "", "🔨", location.belowbar, color.green, 0, "Hammer", textcolor = color.green, size = size.tiny)
plotchar(hanging_man, "", "ᡷ", location.abovebar, color.red, 0, "Hanging Man", textcolor = color.red, size = size.tiny)
plotchar(bull_engulfing, "", "🐮", location.belowbar, color.green, 0, "Bull Engulfing", textcolor = color.green, size = size.tiny)
plotchar(bear_engulfing, "", "🐻", location.abovebar, color.red, 0, "Bear Engulfing", textcolor = color.red, size = size.tiny)
plotchar(dark_cloud, "", "🌩", location.abovebar, color.gray, 0, "Dark Cloud", textcolor = color.red, size = size.tiny)
plotchar(piercing_patern, "", "⚡", location.belowbar, color.green, 0, "Piercing Pattern", textcolor = color.green, size = size.tiny)
plotchar(shooting_star, "","🌠", location.abovebar, color.red, 0, "Shooting Star", color.red, size = size.tiny)
plotchar(inverted_hammer, "", "🔨", location.belowbar, color.green, 0, "Inverted Hammer", textcolor = color.green, size = size.tiny)
plotchar(bearish_harami, "", "🔥", location.abovebar, color.red, 0, "Bearish Harami", textcolor = color.red, size = size.tiny)
plotchar(bullish_harami, "", "🔥", location.belowbar, color.green, 0, "Bullish Harami", textcolor = color.green, size = size.tiny)
plotchar(three_black_crows, "", "🐦", location.abovebar, color.red, 0, "", color.red, size = size.tiny)
plotchar(three_black_crows, "", "🐦", location.abovebar, color.red, -1, "Three Black Crows", color.red, size = size.tiny)
plotchar(three_black_crows, "", "🐦", location.abovebar, color.red, -2, "", color.red, size = size.tiny)
plotchar(three_white_soldiers, "", "💣", location.belowbar, color.green, 0, "", color.green, size = size.tiny)
plotchar(three_white_soldiers, "", "💣", location.belowbar, color.green, -1, "Three White Soldiers", color.green, size = size.tiny)
plotchar(three_white_soldiers, "", "💣", location.belowbar, color.green, -2, "", color.green, size = size.tiny)
plotchar(ha_bull, "", "⇧", location.belowbar, color.green, 0, "\n", color.green, size = size.tiny)
plotchar(ha_bear, "", "⇩", location.abovebar, color.red, 0, "\n", color.red, size = size.tiny)


//background rsi/msi/stoch switches
color background = na
//rsi
if rsi<rsi_over_sold and show_rsi
    background := color.new(color.green, 80)
if rsi>rsi_over_bought and show_rsi
    background := color.new(color.red, 80)
//mfi
if mfi<mfi_over_sold and show_mfi
    background := color.new(color.green, 80)
if mfi>mfi_over_bought and show_mfi
    background := color.new(color.red, 80)
//stoch
if k<stoch_over_sold and show_stoch
    background := color.new(color.green, 80)
if k>stoch_over_bought and show_stoch
    background := color.new(color.red, 80)

//set background
bgcolor(background)