MTF Candlestick Patterns Screening [tanayroy]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tanayroy

//@version=4
study("MTF Candlestick Patterns Screening [tanayroy]",shorttitle='MTF Candles', overlay=true)

var trendRule1 = "SMA50"
var trendRule2 = "SMA50, SMA200"
var trendRule = input(trendRule1, "Detect Trend Based On", options=[trendRule1, trendRule2, "No detection"])
detect_trend = trendRule==trendRule1?1:trendRule==trendRule2?2:0
candle_range = input(7,title='Lookback Bars',type=input.integer,minval=1)

AbandonedBabyInput = input(title = "Abandoned Baby" ,defval=true) 

DarkCloudCoverInput = input(title = "Dark Cloud Cover" ,defval=true) 

DojiInput = input(title = "Doji" ,defval=true) 

DojiStarInput = input(title = "Doji Star" ,defval=true) 

DownsideTasukiGapInput = input(title = "Downside Tasuki Gap" ,defval=true) 

DragonflyDojiInput = input(title = "Dragonfly Doji" ,defval=true) 

EngulfingInput = input(title = "Engulfing" ,defval=true) 

EveningDojiStarInput = input(title = "Evening Doji Star" ,defval=true) 

EveningStarInput = input(title = "Evening Star" ,defval=true) 

FallingThreeMethodsInput = input(title = "Falling Three Methods" ,defval=true) 

FallingWindowInput = input(title = "Falling Window" ,defval=true) 

GravestoneDojiInput = input(title = "Gravestone Doji" ,defval=true) 

HammerInput = input(title = "Hammer" ,defval=true) 

HangingManInput = input(title = "Hanging Man" ,defval=true) 

HaramiCrossInput = input(title = "Harami Cross" ,defval=true) 

HaramiInput = input(title = "Harami" ,defval=true) 

InvertedHammerInput = input(title = "Inverted Hammer" ,defval=true) 

KickingInput = input(title = "Kicking" ,defval=true) 

LongLowerShadowInput = input(title = "Long Lower Shadow" ,defval=true) 

LongUpperShadowInput = input(title = "Long Upper Shadow" ,defval=true) 

MarubozuBlackInput = input(title = "Marubozu Black" ,defval=true) 

MarubozuWhiteInput = input(title = "Marubozu White" ,defval=true) 

MorningDojiStarInput = input(title = "Morning Doji Star" ,defval=true) 

MorningStarInput = input(title = "Morning Star" ,defval=true) 

OnNeckInput = input(title = "On Neck" ,defval=true) 

PiercingInput = input(title = "Piercing" ,defval=true) 

RisingThreeMethodsInput = input(title = "Rising Three Methods" ,defval=true) 

RisingWindowInput = input(title = "Rising Window" ,defval=true) 

ShootingStarInput = input(title = "Shooting Star" ,defval=true) 

SpinningTopBlackInput = input(title = "Spinning Top Black" ,defval=true) 

SpinningTopWhiteInput = input(title = "Spinning Top White" ,defval=true) 

ThreeBlackCrowsInput = input(title = "Three Black Crows" ,defval=true) 

ThreeWhiteSoldiersInput = input(title = "Three White Soldiers" ,defval=true) 

TriStarInput = input(title = "Tri-Star" ,defval=true) 

TweezerBottomInput = input(title = "Tweezer Bottom" ,defval=true) 

TweezerTopInput = input(title = "Tweezer Top" ,defval=true) 

UpsideTasukiGapInput = input(title = "Upside Tasuki Gap" ,defval=true) 

//all bullish pattern
//"Rising Window – Bullish","Rising Three Methods – Bullish","Tweezer Bottom – Bullish","Upside Tasuki Gap – Bullish","Doji Star – Bullish",
//"Morning Doji Star – Bullish","Piercing – Bullish","Hammer – Bullish","Inverted Hammer – Bullish","Morning Star – Bullish","Marubozu White – Bullish",
//"Dragonfly Doji – Bullish","Harami Cross – Bullish","Harami – Bullish","Long Lower Shadow – Bullish","Three White Soldiers – Bullish","Engulfing – Bullish",
//"Abandoned Baby – Bullish","Tri-Star – Bullish","Kicking – Bullish"

//All bearish pattern
//"On Neck – Bearish","Falling Window – Bearish","Falling Three Methods – Bearish",
//"Tweezer Top – Bearish","Dark Cloud Cover – Bearish","Downside Tasuki Gap – Bearish","Evening Doji Star – Bearish","Doji Star – Bearish",
//"Hanging Man – Bearish","Shooting Star – Bearish","Evening Star – Bearish","Marubozu Black – Bearish","Gravestone Doji – Bearish",
//"Harami Cross – Bearish","Harami – Bearish","Long Upper Shadow – Bearish","Three Black Crows – Bearish","Engulfing – Bearish","Abandoned Baby – Bearish",
//"Tri-Star – Bearish","Kicking – Bearish"

//All neutral
//"Doji","Spinning Top White","Spinning Top Black"

candle_pattern_name = array.from("Rising Window – Bullish","Rising Three Methods – Bullish","Tweezer Bottom – Bullish","Upside Tasuki Gap – Bullish",
 "Doji Star – Bullish","Morning Doji Star – Bullish","Piercing – Bullish","Hammer – Bullish","Inverted Hammer – Bullish","Morning Star – Bullish","Marubozu White – Bullish",
 "Dragonfly Doji – Bullish","Harami Cross – Bullish","Harami – Bullish","Long Lower Shadow – Bullish","Three White Soldiers – Bullish","Engulfing – Bullish",
 "Abandoned Baby – Bullish","Tri-Star – Bullish","Kicking – Bullish","On Neck – Bearish","Falling Window – Bearish","Falling Three Methods – Bearish",
 "Tweezer Top – Bearish","Dark Cloud Cover – Bearish","Downside Tasuki Gap – Bearish","Evening Doji Star – Bearish","Doji Star – Bearish",
 "Hanging Man – Bearish","Shooting Star – Bearish","Evening Star – Bearish","Marubozu Black – Bearish","Gravestone Doji – Bearish",
 "Harami Cross – Bearish","Harami – Bearish","Long Upper Shadow – Bearish","Three Black Crows – Bearish","Engulfing – Bearish","Abandoned Baby – Bearish",
 "Tri-Star – Bearish","Kicking – Bearish","Doji","Spinning Top White","Spinning Top Black")
var a5_mint_candle_array = array.new_bool(44)
var a15_mint_candle_array = array.new_bool(44)
var a30_mint_candle_array = array.new_bool(44)
var a1_hr_candle_array=array.new_bool(44)
var a2_hr_candle_array=array.new_bool(44)
var a4_hr_candle_array=array.new_bool(44)
var ad_candle_array=array.new_bool(44)
var aw_candle_array=array.new_bool(44)
var am_candle_array=array.new_bool(44)

var a5_mint_candle_array_bar=array.new_int(44)
var a15_mint_candle_array_bar=array.new_int(44)
var a30_mint_candle_array_bar=array.new_int(44)
var a1_hr_candle_array_bar=array.new_int(44)
var a2_hr_candle_array_bar=array.new_int(44)
var a4_hr_candle_array_bar=array.new_int(44)
var ad_candle_array_bar=array.new_int(44)
var aw_candle_array_bar=array.new_int(44)
var am_candle_array_bar=array.new_int(44)


//get candle pattern 
//taken from tradingview builtin candle pattern
f_detect_candle_patterns(trend_detection)=>
    C_DownTrend = true
    C_UpTrend = true
    if detect_trend==1
        priceAvg = sma(close, 50)
	    C_DownTrend := close < priceAvg
	    C_UpTrend := close > priceAvg
	if detect_trend==2
	    sma200 = sma(close, 200)
	    sma50 = sma(close, 50)
	    C_DownTrend := close < sma50 and sma50 < sma200
	    C_UpTrend := close > sma50 and sma50 > sma200
	    
	C_Len = 14 // ema depth for bodyAvg
    C_ShadowPercent = 5.0 // size of shadows
    C_ShadowEqualsPercent = 100.0
    C_DojiBodyPercent = 5.0
    C_Factor = 2.0 
    C_BodyHi = max(close, open)
    C_BodyLo = min(close, open)
    C_Body = C_BodyHi - C_BodyLo
    C_BodyAvg = ema(C_Body, C_Len)
    C_SmallBody = C_Body < C_BodyAvg
    C_LongBody = C_Body > C_BodyAvg
    C_UpShadow = high - C_BodyHi
    C_DnShadow = C_BodyLo - low
    C_HasUpShadow = C_UpShadow > C_ShadowPercent / 100 * C_Body
    C_HasDnShadow = C_DnShadow > C_ShadowPercent / 100 * C_Body
    C_WhiteBody = open < close
    C_BlackBody = open > close
    C_Range = high-low
    C_IsInsideBar = C_BodyHi[1] > C_BodyHi and C_BodyLo[1] < C_BodyLo
    C_BodyMiddle = C_Body / 2 + C_BodyLo
    C_ShadowEquals = C_UpShadow == C_DnShadow or (abs(C_UpShadow - C_DnShadow) / C_DnShadow * 100) < C_ShadowEqualsPercent 
     and (abs(C_DnShadow - C_UpShadow) / C_UpShadow * 100) < C_ShadowEqualsPercent
    C_IsDojiBody = C_Range > 0 and C_Body <= C_Range * C_DojiBodyPercent / 100
    C_Doji = C_IsDojiBody and C_ShadowEquals
    //bullish patterns
    //"Rising Window – Bullish"
    C_RisingWindowBullish = false
    if C_UpTrend[1] and (C_Range!=0 and C_Range[1]!=0) and low > high[1] and RisingWindowInput
    	C_RisingWindowBullish := true
    //"Rising Three Methods – Bullish"
    C_RisingThreeMethodsBullish = false
    if C_UpTrend[4] and (C_LongBody[4] and C_WhiteBody[4]) and (C_SmallBody[3] and C_BlackBody[3] and open[3]<high[4] 
     and close[3]>low[4]) and (C_SmallBody[2] and C_BlackBody[2] and open[2]<high[4] and close[2]>low[4]) 
     and (C_SmallBody[1] and C_BlackBody[1] and open[1]<high[4] and close[1]>low[4]) and (C_LongBody and C_WhiteBody and close>close[4]) and RisingThreeMethodsInput
    	C_RisingThreeMethodsBullish := true
    //"Tweezer Bottom – Bullish"
    C_TweezerBottomBullish = false
    if C_UpTrend[1] and (not C_IsDojiBody or (C_HasUpShadow and C_HasDnShadow)) and abs(low-low[1]) <= C_BodyAvg*0.05 
     and C_BlackBody[1] and C_WhiteBody and C_LongBody[1] and TweezerBottomInput
    	C_TweezerBottomBullish := true
    //"Upside Tasuki Gap – Bullish"
    C_UpsideTasukiGapBullish = false
    if C_LongBody[2] and C_SmallBody[1] and C_UpTrend and C_WhiteBody[2] and C_BodyLo[1] > C_BodyHi[2] and C_WhiteBody[1] 
     and C_BlackBody and C_BodyLo >= C_BodyHi[2] and C_BodyLo <= C_BodyLo[1] and UpsideTasukiGapInput
    	C_UpsideTasukiGapBullish := true
    //"Doji Star – Bullish"
    C_DojiStarBullish = false
    if C_DownTrend and C_BlackBody[1] and C_LongBody[1] and C_IsDojiBody and C_BodyHi < C_BodyLo[1] and DojiStarInput
    	C_DojiStarBullish := true
    //"Morning Doji Star – Bullish"
    C_MorningDojiStarBullish = false
    if C_LongBody[2] and C_IsDojiBody[1] and C_LongBody and C_DownTrend and C_BlackBody[2] and C_BodyHi[1] < C_BodyLo[2] 
     and C_WhiteBody and C_BodyHi >= C_BodyMiddle[2] and C_BodyHi < C_BodyHi[2] and C_BodyHi[1] < C_BodyLo and MorningDojiStarInput
    	C_MorningDojiStarBullish := true
    //"Piercing – Bullish"
    C_PiercingBullish = false
    if (C_DownTrend[1] and C_BlackBody[1] and C_LongBody[1]) and (C_WhiteBody and open <= low[1] and close > C_BodyMiddle[1] and close < open[1])
    	C_PiercingBullish := true and PiercingInput
    //"Hammer – Bullish"
    C_HammerBullish = false
    if C_SmallBody and C_Body > 0 and C_BodyLo > hl2 and C_DnShadow >= C_Factor * C_Body and not C_HasUpShadow and HammerInput
        if C_DownTrend
            C_HammerBullish := true
    //"Inverted Hammer – Bullish"
    C_InvertedHammerBullish = false
    if C_SmallBody and C_Body > 0 and C_BodyHi < hl2 and C_UpShadow >= C_Factor * C_Body and not C_HasDnShadow and InvertedHammerInput
        if C_DownTrend
            C_InvertedHammerBullish := true
    //"Morning Star – Bullish"
    C_MorningStarBullish = false
    if C_LongBody[2] and C_SmallBody[1] and C_LongBody and MorningStarInput
        if C_DownTrend and C_BlackBody[2] and C_BodyHi[1] < C_BodyLo[2] and C_WhiteBody and C_BodyHi >= C_BodyMiddle[2] 
         and C_BodyHi < C_BodyHi[2] and C_BodyHi[1] < C_BodyLo
            C_MorningStarBullish := true
    //"Marubozu White – Bullish"
    C_MarubozuShadowPercentWhite = 5.0
    C_MarubozuWhiteBullish = C_WhiteBody and C_LongBody and C_UpShadow <= C_MarubozuShadowPercentWhite/100*C_Body and 
     C_DnShadow <= C_MarubozuShadowPercentWhite/100*C_Body and C_WhiteBody and MarubozuWhiteInput
    //"Dragonfly Doji – Bullish"
    C_DragonflyDojiBullish = C_IsDojiBody and C_UpShadow <= C_Body and DragonflyDojiInput
    //"Harami Cross – Bullish"
    C_HaramiCrossBullish = C_LongBody[1] and C_BlackBody[1] and C_DownTrend[1] and C_IsDojiBody and high <= C_BodyHi[1] and low >= C_BodyLo[1] and HaramiCrossInput
    //"Harami – Bullish"
    C_HaramiBullish = C_LongBody[1] and C_BlackBody[1] and C_DownTrend[1] and C_WhiteBody and C_SmallBody and high <= C_BodyHi[1] and low >= C_BodyLo[1] and HaramiInput
    //"Long Lower Shadow – Bullish"
    C_LongLowerShadowPercent = 75.0
    C_LongLowerShadowBullish = C_DnShadow > C_Range/100*C_LongLowerShadowPercent and LongLowerShadowInput
    //"Three White Soldiers – Bullish"
    C_3WSld_ShadowPercent = 5.0
    C_3WSld_HaveNotUpShadow = C_Range * C_3WSld_ShadowPercent / 100 > C_UpShadow
    C_ThreeWhiteSoldiersBullish = false
    if C_LongBody and C_LongBody[1] and C_LongBody[2]
        if C_WhiteBody and C_WhiteBody[1] and C_WhiteBody[2]
            C_ThreeWhiteSoldiersBullish := close > close[1] and close[1] > close[2] and open < close[1] and open > open[1] 
             and open[1] < close[2] and open[1] > open[2] and C_3WSld_HaveNotUpShadow and C_3WSld_HaveNotUpShadow[1] and C_3WSld_HaveNotUpShadow[2] and ThreeWhiteSoldiersInput
    //"Engulfing – Bullish"
    C_EngulfingBullish = C_DownTrend and C_WhiteBody and C_LongBody and C_BlackBody[1] and C_SmallBody[1] and 
     close >= open[1] and open <= close[1] and ( close > open[1] or open < close[1] ) and EngulfingInput
    //"Abandoned Baby – Bullish"
    C_AbandonedBabyBullish = C_DownTrend[2] and C_BlackBody[2] and C_IsDojiBody[1] and low[2] > high[1] and C_WhiteBody and high[1] < low and AbandonedBabyInput
    //"Tri-Star – Bullish"
    C_3DojisBullish = C_Doji[2] and C_Doji[1] and C_Doji
    C_BodyGapUpBullish = C_BodyHi[1] < C_BodyLo
    C_BodyGapDnBullish = C_BodyLo[1] > C_BodyHi
    C_TriStarBullish = C_3DojisBullish and C_DownTrend[2] and C_BodyGapDnBullish[1] and C_BodyGapUpBullish and TriStarInput
    //"Kicking – Bullish"
    C_MarubozuShadowPercent = 5.0
    C_Marubozu = C_LongBody and C_UpShadow <= C_MarubozuShadowPercent/100*C_Body and C_DnShadow <= C_MarubozuShadowPercent/100*C_Body
    C_MarubozuWhiteBullishKicking = C_Marubozu and C_WhiteBody
    C_MarubozuBlackBullish = C_Marubozu and C_BlackBody
    C_KickingBullish = C_MarubozuBlackBullish[1] and C_MarubozuWhiteBullishKicking and high[1] < low and KickingInput
    //"On Neck – Bearish"
    C_OnNeckBearish = false
    if C_DownTrend and C_BlackBody[1] and C_LongBody[1] and C_WhiteBody and open < close[1] and C_SmallBody and C_Range!=0 and abs(close-low[1])<=C_BodyAvg*0.05
    	C_OnNeckBearish := true and OnNeckInput
    //"Falling Window – Bearish"
    C_FallingWindowBearish = false
    if C_DownTrend[1] and (C_Range!=0 and C_Range[1]!=0) and high < low[1]
    	C_FallingWindowBearish := true and FallingWindowInput
    //"Falling Three Methods – Bearish"
    C_FallingThreeMethodsBearish = false
    if C_DownTrend[4] and (C_LongBody[4] and C_BlackBody[4]) and (C_SmallBody[3] and C_WhiteBody[3] and open[3]>low[4] 
     and close[3]<high[4]) and (C_SmallBody[2] and C_WhiteBody[2] and open[2]>low[4] and close[2]<high[4]) and (C_SmallBody[1] 
     and C_WhiteBody[1] and open[1]>low[4] and close[1]<high[4]) and (C_LongBody and C_BlackBody and close<close[4]) and FallingThreeMethodsInput
    	C_FallingThreeMethodsBearish := true
    //"Tweezer Top – Bearish"
    C_TweezerTopBearish = false
    if C_UpTrend[1] and (not C_IsDojiBody or (C_HasUpShadow and C_HasDnShadow)) and abs(high-high[1]) <= C_BodyAvg*0.05 
     and C_WhiteBody[1] and C_BlackBody and C_LongBody[1] and TweezerTopInput
    	C_TweezerTopBearish := true
    //"Dark Cloud Cover – Bearish"
    C_DarkCloudCoverBearish = false
    if (C_UpTrend[1] and C_WhiteBody[1] and C_LongBody[1]) and (C_BlackBody and open >= high[1] and  close < C_BodyMiddle[1] and close > open[1])
    	C_DarkCloudCoverBearish := true and DarkCloudCoverInput
    //"Downside Tasuki Gap – Bearish"
    C_DownsideTasukiGapBearish = false
    if C_LongBody[2] and C_SmallBody[1] and C_DownTrend and C_BlackBody[2] and C_BodyHi[1] < C_BodyLo[2] and C_BlackBody[1] 
     and C_WhiteBody and C_BodyHi <= C_BodyLo[2] and C_BodyHi >= C_BodyHi[1] and DownsideTasukiGapInput
    	C_DownsideTasukiGapBearish := true
    //"Evening Doji Star – Bearish"
    C_EveningDojiStarBearish = false
    if C_LongBody[2] and C_IsDojiBody[1] and C_LongBody and C_UpTrend and C_WhiteBody[2] and C_BodyLo[1] > C_BodyHi[2] 
     and C_BlackBody and C_BodyLo <= C_BodyMiddle[2] and C_BodyLo > C_BodyLo[2] and C_BodyLo[1] > C_BodyHi and EveningDojiStarInput
    	C_EveningDojiStarBearish := true
    //"Doji Star – Bearish"
    C_DojiStarBearish = false
    if C_UpTrend and C_WhiteBody[1] and C_LongBody[1] and C_IsDojiBody and C_BodyLo > C_BodyHi[1] and DojiStarInput
    	C_DojiStarBearish := true
    //"Hanging Man – Bearish"
    C_HangingManBearish = false
    if C_SmallBody and C_Body > 0 and C_BodyLo > hl2 and C_DnShadow >= C_Factor * C_Body and not C_HasUpShadow and HangingManInput
    	if C_UpTrend
    	    C_HangingManBearish := true
    //"Shooting Star – Bearish"
    C_ShootingStarBearish = false
    if C_SmallBody and C_Body > 0 and C_BodyHi < hl2 and C_UpShadow >= C_Factor * C_Body and not C_HasDnShadow and ShootingStarInput
    	if C_UpTrend
    	    C_ShootingStarBearish := true
    //"Evening Star – Bearish"
    C_EveningStarBearish = false
    if C_LongBody[2] and C_SmallBody[1] and C_LongBody and EveningStarInput
        if C_UpTrend and C_WhiteBody[2] and C_BodyLo[1] > C_BodyHi[2] and C_BlackBody and C_BodyLo <= C_BodyMiddle[2] 
         and C_BodyLo > C_BodyLo[2] and C_BodyLo[1] > C_BodyHi
            C_EveningStarBearish := true
    //"Marubozu Black – Bearish"
    C_MarubozuShadowPercentBearish = 5.0
    C_MarubozuBlackBearish = C_BlackBody and C_LongBody and C_UpShadow <= C_MarubozuShadowPercentBearish/100*C_Body 
     and C_DnShadow <= C_MarubozuShadowPercentBearish/100*C_Body and C_BlackBody and MarubozuBlackInput
    //"Gravestone Doji – Bearish"
    C_GravestoneDojiBearish = C_IsDojiBody and C_DnShadow <= C_Body and GravestoneDojiInput
    //"Harami Cross – Bearish"
    C_HaramiCrossBearish = C_LongBody[1] and C_WhiteBody[1] and C_UpTrend[1] and C_IsDojiBody and high <= C_BodyHi[1] and low >= C_BodyLo[1] and HaramiCrossInput
    //"Harami – Bearish"
    C_HaramiBearish = C_LongBody[1] and C_WhiteBody[1] and C_UpTrend[1] and C_BlackBody and C_SmallBody and high <= C_BodyHi[1] and low >= C_BodyLo[1]
     and HaramiInput
    //"Long Upper Shadow – Bearish"
    C_LongShadowPercent = 75.0
    C_LongUpperShadowBearish = C_UpShadow > C_Range/100*C_LongShadowPercent and LongUpperShadowInput
    //"Three Black Crows – Bearish"
    C_3BCrw_ShadowPercent = 5.0
    C_3BCrw_HaveNotDnShadow = C_Range * C_3BCrw_ShadowPercent / 100 > C_DnShadow
    C_ThreeBlackCrowsBearish = false
    if C_LongBody and C_LongBody[1] and C_LongBody[2] and ThreeBlackCrowsInput
        if C_BlackBody and C_BlackBody[1] and C_BlackBody[2]
            C_ThreeBlackCrowsBearish := close < close[1] and close[1] < close[2] and open > close[1] and open < open[1] 
             and open[1] > close[2] and open[1] < open[2] and C_3BCrw_HaveNotDnShadow and C_3BCrw_HaveNotDnShadow[1] and C_3BCrw_HaveNotDnShadow[2]
    //"Engulfing – Bearish"
    C_EngulfingBearish = C_UpTrend and C_BlackBody and C_LongBody and C_WhiteBody[1] and C_SmallBody[1] and close <= open[1] 
     and open >= close[1] and ( close < open[1] or open > close[1] ) and EngulfingInput
    //"Abandoned Baby – Bearish"
    C_AbandonedBabyBearish = C_UpTrend[2] and C_WhiteBody[2] and C_IsDojiBody[1] and high[2] < low[1] and C_BlackBody and low[1] > high and AbandonedBabyInput
    //"Tri-Star – Bearish"
    C_3Dojis = C_Doji[2] and C_Doji[1] and C_Doji
    C_BodyGapUp = C_BodyHi[1] < C_BodyLo
    C_BodyGapDn = C_BodyLo[1] > C_BodyHi
    C_TriStarBearish = C_3Dojis and C_UpTrend[2] and C_BodyGapUp[1] and C_BodyGapDn and TriStarInput
    //"Kicking – Bearish"
    C_MarubozuBullishShadowPercent = 5.0
    C_MarubozuBearishKicking = C_LongBody and C_UpShadow <= C_MarubozuBullishShadowPercent/100*C_Body 
     and C_DnShadow <= C_MarubozuBullishShadowPercent/100*C_Body
    C_MarubozuWhiteBearish = C_MarubozuBearishKicking and C_WhiteBody
    C_MarubozuBlackBearishKicking = C_MarubozuBearishKicking and C_BlackBody
    C_KickingBearish = C_MarubozuWhiteBearish[1] and C_MarubozuBlackBearishKicking and low[1] > high and KickingInput
    //"Doji"
    C_DragonflyDoji = C_IsDojiBody and C_UpShadow <= C_Body
    C_GravestoneDojiOne = C_IsDojiBody and C_DnShadow <= C_Body
    CN_doji=C_Doji and not C_DragonflyDoji and not C_GravestoneDojiOne and DojiInput
    //"Spinning Top White"
    C_SpinningTopWhitePercent = 34.0
    C_IsSpinningTopWhite = C_DnShadow >= C_Range / 100 * C_SpinningTopWhitePercent and C_UpShadow >= C_Range / 100 * C_SpinningTopWhitePercent 
     and not C_IsDojiBody
    C_SpinningTopWhite = C_IsSpinningTopWhite and C_WhiteBody and SpinningTopWhiteInput
    //"Spinning Top Black"
    C_SpinningTopBlackPercent = 34.0
    C_IsSpinningTop = C_DnShadow >= C_Range / 100 * C_SpinningTopBlackPercent and C_UpShadow >= C_Range / 100 * C_SpinningTopBlackPercent 
     and not C_IsDojiBody
    C_SpinningTopBlack = C_IsSpinningTop and C_BlackBody and SpinningTopBlackInput

    barEndTime = time_close
    [C_RisingWindowBullish,C_RisingThreeMethodsBullish,C_TweezerBottomBullish,C_UpsideTasukiGapBullish,C_DojiStarBullish,
     C_MorningDojiStarBullish ,C_PiercingBullish,C_HammerBullish,C_InvertedHammerBullish,C_MorningStarBullish,
     C_MarubozuWhiteBullish,C_DragonflyDojiBullish,C_HaramiCrossBullish,C_HaramiBullish,C_LongLowerShadowBullish,
     C_ThreeWhiteSoldiersBullish,C_EngulfingBullish,C_AbandonedBabyBullish,C_TriStarBullish,C_KickingBullish ,
     C_OnNeckBearish,C_FallingWindowBearish,C_FallingThreeMethodsBearish,C_TweezerTopBearish,C_DarkCloudCoverBearish,
     C_DownsideTasukiGapBearish,C_EveningDojiStarBearish,C_DojiStarBearish,C_HangingManBearish,
     C_ShootingStarBearish,C_EveningStarBearish,C_MarubozuBlackBearish,C_GravestoneDojiBearish,
     C_HaramiCrossBearish,C_HaramiBearish,C_LongUpperShadowBearish,C_ThreeBlackCrowsBearish,
     C_EngulfingBearish,C_AbandonedBabyBearish,C_TriStarBearish,C_KickingBearish,
     CN_doji,C_SpinningTopWhite,C_SpinningTopBlack,
     barEndTime,bar_index]
     
//set array
f_set_array(array_name,bar_array_name,C_RisingWindowBullish,C_RisingThreeMethodsBullish,C_TweezerBottomBullish,C_UpsideTasukiGapBullish,C_DojiStarBullish,
     C_MorningDojiStarBullish ,C_PiercingBullish,C_HammerBullish,C_InvertedHammerBullish,C_MorningStarBullish,
     C_MarubozuWhiteBullish,C_DragonflyDojiBullish,C_HaramiCrossBullish,C_HaramiBullish,C_LongLowerShadowBullish,
     C_ThreeWhiteSoldiersBullish,C_EngulfingBullish,C_AbandonedBabyBullish,C_TriStarBullish,C_KickingBullish ,
     C_OnNeckBearish,C_FallingWindowBearish,C_FallingThreeMethodsBearish,C_TweezerTopBearish,C_DarkCloudCoverBearish,
     C_DownsideTasukiGapBearish,C_EveningDojiStarBearish,C_DojiStarBearish,C_HangingManBearish,
     C_ShootingStarBearish,C_EveningStarBearish,C_MarubozuBlackBearish,C_GravestoneDojiBearish,
     C_HaramiCrossBearish,C_HaramiBearish,C_LongUpperShadowBearish,C_ThreeBlackCrowsBearish,
     C_EngulfingBearish,C_AbandonedBabyBearish,C_TriStarBearish,C_KickingBearish,
     CN_doji,C_SpinningTopWhite,C_SpinningTopBlack,
     barEndTime,barindex)=>
    if C_RisingWindowBullish
        array.set(array_name,0,C_RisingWindowBullish)
        array.set(bar_array_name,0,barindex)
    if C_RisingThreeMethodsBullish
        array.set(array_name,1,C_RisingThreeMethodsBullish)
        array.set(bar_array_name,1,barindex)
    if C_TweezerBottomBullish
        array.set(array_name,2,C_TweezerBottomBullish)
        array.set(bar_array_name,2,barindex)
    if C_UpsideTasukiGapBullish
        array.set(array_name,3,C_UpsideTasukiGapBullish)
        array.set(bar_array_name,3,barindex)
    if C_DojiStarBullish
        array.set(array_name,4,C_DojiStarBullish)
        array.set(bar_array_name,4,barindex)
    if C_MorningDojiStarBullish
        array.set(array_name,5,C_MorningDojiStarBullish)
        array.set(bar_array_name,5,barindex)
    if C_PiercingBullish
        array.set(array_name,6,C_PiercingBullish)
        array.set(bar_array_name,6,barindex)
    if C_HammerBullish
        array.set(array_name,7,C_HammerBullish)
        array.set(bar_array_name,7,barindex)
    if C_InvertedHammerBullish
        array.set(array_name,8,C_InvertedHammerBullish)
        array.set(bar_array_name,8,barindex)
    if C_MorningStarBullish 
        array.set(array_name,9,C_MorningStarBullish)
        array.set(bar_array_name,9,barindex)
    if C_MarubozuWhiteBullish
        array.set(array_name,10,C_MarubozuWhiteBullish)
        array.set(bar_array_name,10,barindex)
    if C_DragonflyDojiBullish
        array.set(array_name,11,C_DragonflyDojiBullish)
        array.set(bar_array_name,11,barindex)
    if C_HaramiCrossBullish
        array.set(array_name,12,C_HaramiCrossBullish)
        array.set(bar_array_name,12,barindex)
    if C_HaramiBullish
        array.set(array_name,13,C_HaramiBullish)
        array.set(bar_array_name,13,barindex)
    if C_LongLowerShadowBullish
        array.set(array_name,14,C_LongLowerShadowBullish)
        array.set(bar_array_name,14,barindex)
    if C_ThreeWhiteSoldiersBullish
        array.set(array_name,15,C_ThreeWhiteSoldiersBullish)
        array.set(bar_array_name,15,barindex)
    if C_EngulfingBullish
        array.set(array_name,16,C_EngulfingBullish)
        array.set(bar_array_name,16,barindex)
    if C_AbandonedBabyBullish
        array.set(array_name,17,C_AbandonedBabyBullish)
        array.set(bar_array_name,17,barindex)
    if C_TriStarBullish
        array.set(array_name,18,C_TriStarBullish)
        array.set(bar_array_name,18,barindex)
    if C_KickingBullish 
        array.set(array_name,19,C_KickingBullish )
        array.set(bar_array_name,19,barindex)
    if C_OnNeckBearish
        array.set(array_name,20,C_OnNeckBearish)
        array.set(bar_array_name,20,barindex)
    if C_FallingWindowBearish
        array.set(array_name,21,C_FallingWindowBearish)
        array.set(bar_array_name,21,barindex)
    if C_FallingThreeMethodsBearish
        array.set(array_name,22,C_FallingThreeMethodsBearish)
        array.set(bar_array_name,22,barindex)
    if C_TweezerTopBearish
        array.set(array_name,23,C_TweezerTopBearish)
        array.set(bar_array_name,23,barindex)
    if C_DarkCloudCoverBearish 
        array.set(array_name,24,C_DarkCloudCoverBearish )
        array.set(bar_array_name,24,barindex)
    if C_DownsideTasukiGapBearish
        array.set(array_name,25,C_DownsideTasukiGapBearish)
        array.set(bar_array_name,25,barindex)
    if C_EveningDojiStarBearish
        array.set(array_name,26,C_EveningDojiStarBearish)
        array.set(bar_array_name,26,barindex)
    if C_DojiStarBearish
        array.set(array_name,27,C_DojiStarBearish)
        array.set(bar_array_name,27,barindex)
    if C_HangingManBearish
        array.set(array_name,28,C_HangingManBearish)
        array.set(bar_array_name,28,barindex)
    if C_ShootingStarBearish
        array.set(array_name,29,C_ShootingStarBearish)
        array.set(bar_array_name,29,barindex)
    if C_EveningStarBearish
        array.set(array_name,30,C_EveningStarBearish)
        array.set(bar_array_name,30,barindex)
    if C_MarubozuBlackBearish
        array.set(array_name,31,C_MarubozuBlackBearish)
        array.set(bar_array_name,31,barindex)
    if C_GravestoneDojiBearish
        array.set(array_name,32,C_GravestoneDojiBearish)
        array.set(bar_array_name,32,barindex)
    if C_HaramiCrossBearish
        array.set(array_name,33,C_HaramiCrossBearish)
        array.set(bar_array_name,33,barindex)
    if C_HaramiBearish
        array.set(array_name,34,C_HaramiBearish)
        array.set(bar_array_name,34,barindex)
    if C_LongUpperShadowBearish
        array.set(array_name,35,C_LongUpperShadowBearish)
        array.set(bar_array_name,35,barindex)
    if C_ThreeBlackCrowsBearish
        array.set(array_name,36,C_ThreeBlackCrowsBearish)
        array.set(bar_array_name,36,barindex)
    if C_EngulfingBearish
        array.set(array_name,37,C_EngulfingBearish)
        array.set(bar_array_name,37,barindex)
    if C_AbandonedBabyBearish
        array.set(array_name,38,C_AbandonedBabyBearish)
        array.set(bar_array_name,38,barindex)
    if C_TriStarBearish
        array.set(array_name,39,C_TriStarBearish)
        array.set(bar_array_name,39,barindex)
    if C_KickingBearish
        array.set(array_name,40,C_KickingBearish)
        array.set(bar_array_name,40,barindex)
    if CN_doji
        array.set(array_name,41,CN_doji)
        array.set(bar_array_name,41,barindex)
        
    if C_SpinningTopWhite
        array.set(array_name,42,C_SpinningTopWhite)
        array.set(bar_array_name,42,barindex)
    if C_SpinningTopBlack
        array.set(array_name,43,C_SpinningTopBlack)
        array.set(bar_array_name,43,barindex)

 

[C_RisingWindowBullish,C_RisingThreeMethodsBullish,C_TweezerBottomBullish,C_UpsideTasukiGapBullish,C_DojiStarBullish,
     C_MorningDojiStarBullish ,C_PiercingBullish,C_HammerBullish,C_InvertedHammerBullish,C_MorningStarBullish,
     C_MarubozuWhiteBullish,C_DragonflyDojiBullish,C_HaramiCrossBullish,C_HaramiBullish,C_LongLowerShadowBullish,
     C_ThreeWhiteSoldiersBullish,C_EngulfingBullish,C_AbandonedBabyBullish,C_TriStarBullish,C_KickingBullish ,
     C_OnNeckBearish,C_FallingWindowBearish,C_FallingThreeMethodsBearish,C_TweezerTopBearish,C_DarkCloudCoverBearish,
     C_DownsideTasukiGapBearish,C_EveningDojiStarBearish,C_DojiStarBearish,C_HangingManBearish,
     C_ShootingStarBearish,C_EveningStarBearish,C_MarubozuBlackBearish,C_GravestoneDojiBearish,
     C_HaramiCrossBearish,C_HaramiBearish,C_LongUpperShadowBearish,C_ThreeBlackCrowsBearish,
     C_EngulfingBearish,C_AbandonedBabyBearish,C_TriStarBearish,C_KickingBearish,
     CN_doji,C_SpinningTopWhite,C_SpinningTopBlack,
     barEndTime,barindex ]=security(syminfo.tickerid,'5',f_detect_candle_patterns(detect_trend))
     
f_set_array(a5_mint_candle_array,a5_mint_candle_array_bar,C_RisingWindowBullish,C_RisingThreeMethodsBullish,
     C_TweezerBottomBullish,C_UpsideTasukiGapBullish,C_DojiStarBullish,
     C_MorningDojiStarBullish ,C_PiercingBullish,C_HammerBullish,C_InvertedHammerBullish,C_MorningStarBullish,
     C_MarubozuWhiteBullish,C_DragonflyDojiBullish,C_HaramiCrossBullish,C_HaramiBullish,C_LongLowerShadowBullish,
     C_ThreeWhiteSoldiersBullish,C_EngulfingBullish,C_AbandonedBabyBullish,C_TriStarBullish,C_KickingBullish ,
     C_OnNeckBearish,C_FallingWindowBearish,C_FallingThreeMethodsBearish,C_TweezerTopBearish,C_DarkCloudCoverBearish,
     C_DownsideTasukiGapBearish,C_EveningDojiStarBearish,C_DojiStarBearish,C_HangingManBearish,
     C_ShootingStarBearish,C_EveningStarBearish,C_MarubozuBlackBearish,C_GravestoneDojiBearish,
     C_HaramiCrossBearish,C_HaramiBearish,C_LongUpperShadowBearish,C_ThreeBlackCrowsBearish,
     C_EngulfingBearish,C_AbandonedBabyBearish,C_TriStarBearish,C_KickingBearish,
     CN_doji,C_SpinningTopWhite,C_SpinningTopBlack,
     barEndTime,barindex)     

[C_15RisingWindowBullish,C_15RisingThreeMethodsBullish,C_15TweezerBottomBullish,C_15UpsideTasukiGapBullish,C_15DojiStarBullish,
     C_15MorningDojiStarBullish ,C_15PiercingBullish,C_15HammerBullish,C_15InvertedHammerBullish,C_15MorningStarBullish,
     C_15MarubozuWhiteBullish,C_15DragonflyDojiBullish,C_15HaramiCrossBullish,C_15HaramiBullish,C_15LongLowerShadowBullish,
     C_15ThreeWhiteSoldiersBullish,C_15EngulfingBullish,C_15AbandonedBabyBullish,C_15TriStarBullish,C_15KickingBullish ,
     C_15OnNeckBearish,C_15FallingWindowBearish,C_15FallingThreeMethodsBearish,C_15TweezerTopBearish,C_15DarkCloudCoverBearish,
     C_15DownsideTasukiGapBearish,C_15EveningDojiStarBearish,C_15DojiStarBearish,C_15HangingManBearish,
     C_15ShootingStarBearish,C_15EveningStarBearish,C_15MarubozuBlackBearish,C_15GravestoneDojiBearish,
     C_15HaramiCrossBearish,C_15HaramiBearish,C_15LongUpperShadowBearish,C_15ThreeBlackCrowsBearish,
     C_15EngulfingBearish,C_15AbandonedBabyBearish,C_15TriStarBearish,C_15KickingBearish,
     CN15_doji,C15_SpinningTopWhite,C15_SpinningTopBlack,
     barEndTime15,barindex15 ]=security(syminfo.tickerid,'15',f_detect_candle_patterns(detect_trend))
     
f_set_array(a15_mint_candle_array,a15_mint_candle_array_bar,C_15RisingWindowBullish,C_15RisingThreeMethodsBullish,
     C_15TweezerBottomBullish,C_15UpsideTasukiGapBullish,C_15DojiStarBullish,
     C_15MorningDojiStarBullish ,C_15PiercingBullish,C_15HammerBullish,C_15InvertedHammerBullish,C_15MorningStarBullish,
     C_15MarubozuWhiteBullish,C_15DragonflyDojiBullish,C_15HaramiCrossBullish,C_15HaramiBullish,C_15LongLowerShadowBullish,
     C_15ThreeWhiteSoldiersBullish,C_15EngulfingBullish,C_15AbandonedBabyBullish,C_15TriStarBullish,C_15KickingBullish ,
     C_15OnNeckBearish,C_15FallingWindowBearish,C_15FallingThreeMethodsBearish,C_15TweezerTopBearish,C_15DarkCloudCoverBearish,
     C_15DownsideTasukiGapBearish,C_15EveningDojiStarBearish,C_15DojiStarBearish,C_15HangingManBearish,
     C_15ShootingStarBearish,C_15EveningStarBearish,C_15MarubozuBlackBearish,C_15GravestoneDojiBearish,
     C_15HaramiCrossBearish,C_15HaramiBearish,C_15LongUpperShadowBearish,C_15ThreeBlackCrowsBearish,
     C_15EngulfingBearish,C_15AbandonedBabyBearish,C_15TriStarBearish,C_15KickingBearish,
     CN15_doji,C15_SpinningTopWhite,C15_SpinningTopBlack,
     barEndTime15,barindex15)
     
[C_30RisingWindowBullish,C_30RisingThreeMethodsBullish,C_30TweezerBottomBullish,C_30UpsideTasukiGapBullish,C_30DojiStarBullish,
     C_30MorningDojiStarBullish ,C_30PiercingBullish,C_30HammerBullish,C_30InvertedHammerBullish,C_30MorningStarBullish,
     C_30MarubozuWhiteBullish,C_30DragonflyDojiBullish,C_30HaramiCrossBullish,C_30HaramiBullish,C_30LongLowerShadowBullish,
     C_30ThreeWhiteSoldiersBullish,C_30EngulfingBullish,C_30AbandonedBabyBullish,C_30TriStarBullish,C_30KickingBullish ,
     C_30OnNeckBearish,C_30FallingWindowBearish,C_30FallingThreeMethodsBearish,C_30TweezerTopBearish,C_30DarkCloudCoverBearish,
     C_30DownsideTasukiGapBearish,C_30EveningDojiStarBearish,C_30DojiStarBearish,C_30HangingManBearish,
     C_30ShootingStarBearish,C_30EveningStarBearish,C_30MarubozuBlackBearish,C_30GravestoneDojiBearish,
     C_30HaramiCrossBearish,C_30HaramiBearish,C_30LongUpperShadowBearish,C_30ThreeBlackCrowsBearish,
     C_30EngulfingBearish,C_30AbandonedBabyBearish,C_30TriStarBearish,C_30KickingBearish,
     CN30_doji,C30_SpinningTopWhite,C30_SpinningTopBlack,
     barEndTime30,barindex30 ]=security(syminfo.tickerid,'30',f_detect_candle_patterns(detect_trend))
     
f_set_array(a30_mint_candle_array,a30_mint_candle_array_bar,C_30RisingWindowBullish,C_30RisingThreeMethodsBullish,
     C_30TweezerBottomBullish,C_30UpsideTasukiGapBullish,C_30DojiStarBullish,
     C_30MorningDojiStarBullish ,C_30PiercingBullish,C_30HammerBullish,C_30InvertedHammerBullish,C_30MorningStarBullish,
     C_30MarubozuWhiteBullish,C_30DragonflyDojiBullish,C_30HaramiCrossBullish,C_30HaramiBullish,C_30LongLowerShadowBullish,
     C_30ThreeWhiteSoldiersBullish,C_30EngulfingBullish,C_30AbandonedBabyBullish,C_30TriStarBullish,C_30KickingBullish ,
     C_30OnNeckBearish,C_30FallingWindowBearish,C_30FallingThreeMethodsBearish,C_30TweezerTopBearish,C_30DarkCloudCoverBearish,
     C_30DownsideTasukiGapBearish,C_30EveningDojiStarBearish,C_30DojiStarBearish,C_30HangingManBearish,
     C_30ShootingStarBearish,C_30EveningStarBearish,C_30MarubozuBlackBearish,C_30GravestoneDojiBearish,
     C_30HaramiCrossBearish,C_30HaramiBearish,C_30LongUpperShadowBearish,C_30ThreeBlackCrowsBearish,
     C_30EngulfingBearish,C_30AbandonedBabyBearish,C_30TriStarBearish,C_30KickingBearish,
     CN30_doji,C30_SpinningTopWhite,C30_SpinningTopBlack,
     barEndTime30,barindex30)
   
[C_1_hrRisingWindowBullish,C_1_hrRisingThreeMethodsBullish,C_1_hrTweezerBottomBullish,C_1_hrUpsideTasukiGapBullish,C_1_hrDojiStarBullish,
     C_1_hrMorningDojiStarBullish ,C_1_hrPiercingBullish,C_1_hrHammerBullish,C_1_hrInvertedHammerBullish,C_1_hrMorningStarBullish,
     C_1_hrMarubozuWhiteBullish,C_1_hrDragonflyDojiBullish,C_1_hrHaramiCrossBullish,C_1_hrHaramiBullish,C_1_hrLongLowerShadowBullish,
     C_1_hrThreeWhiteSoldiersBullish,C_1_hrEngulfingBullish,C_1_hrAbandonedBabyBullish,C_1_hrTriStarBullish,C_1_hrKickingBullish ,
     C_1_hrOnNeckBearish,C_1_hrFallingWindowBearish,C_1_hrFallingThreeMethodsBearish,C_1_hrTweezerTopBearish,C_1_hrDarkCloudCoverBearish,
     C_1_hrDownsideTasukiGapBearish,C_1_hrEveningDojiStarBearish,C_1_hrDojiStarBearish,C_1_hrHangingManBearish,
     C_1_hrShootingStarBearish,C_1_hrEveningStarBearish,C_1_hrMarubozuBlackBearish,C_1_hrGravestoneDojiBearish,
     C_1_hrHaramiCrossBearish,C_1_hrHaramiBearish,C_1_hrLongUpperShadowBearish,C_1_hrThreeBlackCrowsBearish,
     C_1_hrEngulfingBearish,C_1_hrAbandonedBabyBearish,C_1_hrTriStarBearish,C_1_hrKickingBearish,
     CN1_hr_doji,C1_hr_SpinningTopWhite,C1_hr_SpinningTopBlack,
     barEndTime1_hr,barindex1_hr ]=security(syminfo.tickerid,'60',f_detect_candle_patterns(detect_trend))
     
f_set_array(a1_hr_candle_array,a1_hr_candle_array_bar,C_1_hrRisingWindowBullish,C_1_hrRisingThreeMethodsBullish,
     C_1_hrTweezerBottomBullish,C_1_hrUpsideTasukiGapBullish,C_1_hrDojiStarBullish,
     C_1_hrMorningDojiStarBullish ,C_1_hrPiercingBullish,C_1_hrHammerBullish,C_1_hrInvertedHammerBullish,C_1_hrMorningStarBullish,
     C_1_hrMarubozuWhiteBullish,C_1_hrDragonflyDojiBullish,C_1_hrHaramiCrossBullish,C_1_hrHaramiBullish,C_1_hrLongLowerShadowBullish,
     C_1_hrThreeWhiteSoldiersBullish,C_1_hrEngulfingBullish,C_1_hrAbandonedBabyBullish,C_1_hrTriStarBullish,C_1_hrKickingBullish ,
     C_1_hrOnNeckBearish,C_1_hrFallingWindowBearish,C_1_hrFallingThreeMethodsBearish,C_1_hrTweezerTopBearish,C_1_hrDarkCloudCoverBearish,
     C_1_hrDownsideTasukiGapBearish,C_1_hrEveningDojiStarBearish,C_1_hrDojiStarBearish,C_1_hrHangingManBearish,
     C_1_hrShootingStarBearish,C_1_hrEveningStarBearish,C_1_hrMarubozuBlackBearish,C_1_hrGravestoneDojiBearish,
     C_1_hrHaramiCrossBearish,C_1_hrHaramiBearish,C_1_hrLongUpperShadowBearish,C_1_hrThreeBlackCrowsBearish,
     C_1_hrEngulfingBearish,C_1_hrAbandonedBabyBearish,C_1_hrTriStarBearish,C_1_hrKickingBearish,
     CN1_hr_doji,C1_hr_SpinningTopWhite,C1_hr_SpinningTopBlack,
     barEndTime1_hr,barindex1_hr)     

[C_2_hrRisingWindowBullish,C_2_hrRisingThreeMethodsBullish,C_2_hrTweezerBottomBullish,C_2_hrUpsideTasukiGapBullish,C_2_hrDojiStarBullish,
     C_2_hrMorningDojiStarBullish ,C_2_hrPiercingBullish,C_2_hrHammerBullish,C_2_hrInvertedHammerBullish,C_2_hrMorningStarBullish,
     C_2_hrMarubozuWhiteBullish,C_2_hrDragonflyDojiBullish,C_2_hrHaramiCrossBullish,C_2_hrHaramiBullish,C_2_hrLongLowerShadowBullish,
     C_2_hrThreeWhiteSoldiersBullish,C_2_hrEngulfingBullish,C_2_hrAbandonedBabyBullish,C_2_hrTriStarBullish,C_2_hrKickingBullish ,
     C_2_hrOnNeckBearish,C_2_hrFallingWindowBearish,C_2_hrFallingThreeMethodsBearish,C_2_hrTweezerTopBearish,C_2_hrDarkCloudCoverBearish,
     C_2_hrDownsideTasukiGapBearish,C_2_hrEveningDojiStarBearish,C_2_hrDojiStarBearish,C_2_hrHangingManBearish,
     C_2_hrShootingStarBearish,C_2_hrEveningStarBearish,C_2_hrMarubozuBlackBearish,C_2_hrGravestoneDojiBearish,
     C_2_hrHaramiCrossBearish,C_2_hrHaramiBearish,C_2_hrLongUpperShadowBearish,C_2_hrThreeBlackCrowsBearish,
     C_2_hrEngulfingBearish,C_2_hrAbandonedBabyBearish,C_2_hrTriStarBearish,C_2_hrKickingBearish,
     CN2_hr_doji,C2_hr_SpinningTopWhite,C2_hr_SpinningTopBlack,
     barEndTime2_hr,barindex2_hr ]=security(syminfo.tickerid,'120',f_detect_candle_patterns(detect_trend))
     
f_set_array(a2_hr_candle_array,a2_hr_candle_array_bar,C_2_hrRisingWindowBullish,C_2_hrRisingThreeMethodsBullish,
     C_2_hrTweezerBottomBullish,C_2_hrUpsideTasukiGapBullish,C_2_hrDojiStarBullish,
     C_2_hrMorningDojiStarBullish ,C_2_hrPiercingBullish,C_2_hrHammerBullish,C_2_hrInvertedHammerBullish,C_2_hrMorningStarBullish,
     C_2_hrMarubozuWhiteBullish,C_2_hrDragonflyDojiBullish,C_2_hrHaramiCrossBullish,C_2_hrHaramiBullish,C_2_hrLongLowerShadowBullish,
     C_2_hrThreeWhiteSoldiersBullish,C_2_hrEngulfingBullish,C_2_hrAbandonedBabyBullish,C_2_hrTriStarBullish,C_2_hrKickingBullish ,
     C_2_hrOnNeckBearish,C_2_hrFallingWindowBearish,C_2_hrFallingThreeMethodsBearish,C_2_hrTweezerTopBearish,C_2_hrDarkCloudCoverBearish,
     C_2_hrDownsideTasukiGapBearish,C_2_hrEveningDojiStarBearish,C_2_hrDojiStarBearish,C_2_hrHangingManBearish,
     C_2_hrShootingStarBearish,C_2_hrEveningStarBearish,C_2_hrMarubozuBlackBearish,C_2_hrGravestoneDojiBearish,
     C_2_hrHaramiCrossBearish,C_2_hrHaramiBearish,C_2_hrLongUpperShadowBearish,C_2_hrThreeBlackCrowsBearish,
     C_2_hrEngulfingBearish,C_2_hrAbandonedBabyBearish,C_2_hrTriStarBearish,C_2_hrKickingBearish,
     CN2_hr_doji,C2_hr_SpinningTopWhite,C2_hr_SpinningTopBlack,
     barEndTime2_hr,barindex2_hr)
     
[C_4_hrRisingWindowBullish,C_4_hrRisingThreeMethodsBullish,C_4_hrTweezerBottomBullish,C_4_hrUpsideTasukiGapBullish,C_4_hrDojiStarBullish,
     C_4_hrMorningDojiStarBullish ,C_4_hrPiercingBullish,C_4_hrHammerBullish,C_4_hrInvertedHammerBullish,C_4_hrMorningStarBullish,
     C_4_hrMarubozuWhiteBullish,C_4_hrDragonflyDojiBullish,C_4_hrHaramiCrossBullish,C_4_hrHaramiBullish,C_4_hrLongLowerShadowBullish,
     C_4_hrThreeWhiteSoldiersBullish,C_4_hrEngulfingBullish,C_4_hrAbandonedBabyBullish,C_4_hrTriStarBullish,C_4_hrKickingBullish ,
     C_4_hrOnNeckBearish,C_4_hrFallingWindowBearish,C_4_hrFallingThreeMethodsBearish,C_4_hrTweezerTopBearish,C_4_hrDarkCloudCoverBearish,
     C_4_hrDownsideTasukiGapBearish,C_4_hrEveningDojiStarBearish,C_4_hrDojiStarBearish,C_4_hrHangingManBearish,
     C_4_hrShootingStarBearish,C_4_hrEveningStarBearish,C_4_hrMarubozuBlackBearish,C_4_hrGravestoneDojiBearish,
     C_4_hrHaramiCrossBearish,C_4_hrHaramiBearish,C_4_hrLongUpperShadowBearish,C_4_hrThreeBlackCrowsBearish,
     C_4_hrEngulfingBearish,C_4_hrAbandonedBabyBearish,C_4_hrTriStarBearish,C_4_hrKickingBearish,
     CN4_hr_doji,C4_hr_SpinningTopWhite,C4_hr_SpinningTopBlack,
     barEndTime4_hr,barindex4_hr ]=security(syminfo.tickerid,'240',f_detect_candle_patterns(detect_trend))
     
f_set_array(a4_hr_candle_array,a4_hr_candle_array_bar,C_4_hrRisingWindowBullish,C_4_hrRisingThreeMethodsBullish,
     C_4_hrTweezerBottomBullish,C_4_hrUpsideTasukiGapBullish,C_4_hrDojiStarBullish,
     C_4_hrMorningDojiStarBullish ,C_4_hrPiercingBullish,C_4_hrHammerBullish,C_4_hrInvertedHammerBullish,C_4_hrMorningStarBullish,
     C_4_hrMarubozuWhiteBullish,C_4_hrDragonflyDojiBullish,C_4_hrHaramiCrossBullish,C_4_hrHaramiBullish,C_4_hrLongLowerShadowBullish,
     C_4_hrThreeWhiteSoldiersBullish,C_4_hrEngulfingBullish,C_4_hrAbandonedBabyBullish,C_4_hrTriStarBullish,C_4_hrKickingBullish ,
     C_4_hrOnNeckBearish,C_4_hrFallingWindowBearish,C_4_hrFallingThreeMethodsBearish,C_4_hrTweezerTopBearish,C_4_hrDarkCloudCoverBearish,
     C_4_hrDownsideTasukiGapBearish,C_4_hrEveningDojiStarBearish,C_4_hrDojiStarBearish,C_4_hrHangingManBearish,
     C_4_hrShootingStarBearish,C_4_hrEveningStarBearish,C_4_hrMarubozuBlackBearish,C_4_hrGravestoneDojiBearish,
     C_4_hrHaramiCrossBearish,C_4_hrHaramiBearish,C_4_hrLongUpperShadowBearish,C_4_hrThreeBlackCrowsBearish,
     C_4_hrEngulfingBearish,C_4_hrAbandonedBabyBearish,C_4_hrTriStarBearish,C_4_hrKickingBearish,
     CN4_hr_doji,C4_hr_SpinningTopWhite,C4_hr_SpinningTopBlack,
     barEndTime4_hr,barindex4_hr)
     
[C_dRisingWindowBullish,C_dRisingThreeMethodsBullish,C_dTweezerBottomBullish,C_dUpsideTasukiGapBullish,C_dDojiStarBullish,
     C_dMorningDojiStarBullish ,C_dPiercingBullish,C_dHammerBullish,C_dInvertedHammerBullish,C_dMorningStarBullish,
     C_dMarubozuWhiteBullish,C_dDragonflyDojiBullish,C_dHaramiCrossBullish,C_dHaramiBullish,C_dLongLowerShadowBullish,
     C_dThreeWhiteSoldiersBullish,C_dEngulfingBullish,C_dAbandonedBabyBullish,C_dTriStarBullish,C_dKickingBullish ,
     C_dOnNeckBearish,C_dFallingWindowBearish,C_dFallingThreeMethodsBearish,C_dTweezerTopBearish,C_dDarkCloudCoverBearish,
     C_dDownsideTasukiGapBearish,C_dEveningDojiStarBearish,C_dDojiStarBearish,C_dHangingManBearish,
     C_dShootingStarBearish,C_dEveningStarBearish,C_dMarubozuBlackBearish,C_dGravestoneDojiBearish,
     C_dHaramiCrossBearish,C_dHaramiBearish,C_dLongUpperShadowBearish,C_dThreeBlackCrowsBearish,
     C_dEngulfingBearish,C_dAbandonedBabyBearish,C_dTriStarBearish,C_dKickingBearish,
     CNd_doji,Cd_SpinningTopWhite,Cd_SpinningTopBlack,
     barEndTimed,barindexd ]=security(syminfo.tickerid,'D',f_detect_candle_patterns(detect_trend))
     
f_set_array(ad_candle_array,ad_candle_array_bar,C_dRisingWindowBullish,C_dRisingThreeMethodsBullish,
     C_dTweezerBottomBullish,C_dUpsideTasukiGapBullish,C_dDojiStarBullish,
     C_dMorningDojiStarBullish ,C_dPiercingBullish,C_dHammerBullish,C_dInvertedHammerBullish,C_dMorningStarBullish,
     C_dMarubozuWhiteBullish,C_dDragonflyDojiBullish,C_dHaramiCrossBullish,C_dHaramiBullish,C_dLongLowerShadowBullish,
     C_dThreeWhiteSoldiersBullish,C_dEngulfingBullish,C_dAbandonedBabyBullish,C_dTriStarBullish,C_dKickingBullish ,
     C_dOnNeckBearish,C_dFallingWindowBearish,C_dFallingThreeMethodsBearish,C_dTweezerTopBearish,C_dDarkCloudCoverBearish,
     C_dDownsideTasukiGapBearish,C_dEveningDojiStarBearish,C_dDojiStarBearish,C_dHangingManBearish,
     C_dShootingStarBearish,C_dEveningStarBearish,C_dMarubozuBlackBearish,C_dGravestoneDojiBearish,
     C_dHaramiCrossBearish,C_dHaramiBearish,C_dLongUpperShadowBearish,C_dThreeBlackCrowsBearish,
     C_dEngulfingBearish,C_dAbandonedBabyBearish,C_dTriStarBearish,C_dKickingBearish,
     CNd_doji,Cd_SpinningTopWhite,Cd_SpinningTopBlack,
     barEndTimed,barindexd)

[C_wRisingWindowBullish,C_wRisingThreeMethodsBullish,C_wTweezerBottomBullish,C_wUpsideTasukiGapBullish,C_wDojiStarBullish,
     C_wMorningDojiStarBullish ,C_wPiercingBullish,C_wHammerBullish,C_wInvertedHammerBullish,C_wMorningStarBullish,
     C_wMarubozuWhiteBullish,C_wDragonflyDojiBullish,C_wHaramiCrossBullish,C_wHaramiBullish,C_wLongLowerShadowBullish,
     C_wThreeWhiteSoldiersBullish,C_wEngulfingBullish,C_wAbandonedBabyBullish,C_wTriStarBullish,C_wKickingBullish ,
     C_wOnNeckBearish,C_wFallingWindowBearish,C_wFallingThreeMethodsBearish,C_wTweezerTopBearish,C_wDarkCloudCoverBearish,
     C_wDownsideTasukiGapBearish,C_wEveningDojiStarBearish,C_wDojiStarBearish,C_wHangingManBearish,
     C_wShootingStarBearish,C_wEveningStarBearish,C_wMarubozuBlackBearish,C_wGravestoneDojiBearish,
     C_wHaramiCrossBearish,C_wHaramiBearish,C_wLongUpperShadowBearish,C_wThreeBlackCrowsBearish,
     C_wEngulfingBearish,C_wAbandonedBabyBearish,C_wTriStarBearish,C_wKickingBearish,
     CNw_doji,Cw_SpinningTopWhite,Cw_SpinningTopBlack,
     barEndTimew,barindexw ]=security(syminfo.tickerid,'W',f_detect_candle_patterns(detect_trend))
     
f_set_array(aw_candle_array,aw_candle_array_bar,C_wRisingWindowBullish,C_wRisingThreeMethodsBullish,
     C_wTweezerBottomBullish,C_wUpsideTasukiGapBullish,C_wDojiStarBullish,
     C_wMorningDojiStarBullish ,C_wPiercingBullish,C_wHammerBullish,C_wInvertedHammerBullish,C_wMorningStarBullish,
     C_wMarubozuWhiteBullish,C_wDragonflyDojiBullish,C_wHaramiCrossBullish,C_wHaramiBullish,C_wLongLowerShadowBullish,
     C_wThreeWhiteSoldiersBullish,C_wEngulfingBullish,C_wAbandonedBabyBullish,C_wTriStarBullish,C_wKickingBullish ,
     C_wOnNeckBearish,C_wFallingWindowBearish,C_wFallingThreeMethodsBearish,C_wTweezerTopBearish,C_wDarkCloudCoverBearish,
     C_wDownsideTasukiGapBearish,C_wEveningDojiStarBearish,C_wDojiStarBearish,C_wHangingManBearish,
     C_wShootingStarBearish,C_wEveningStarBearish,C_wMarubozuBlackBearish,C_wGravestoneDojiBearish,
     C_wHaramiCrossBearish,C_wHaramiBearish,C_wLongUpperShadowBearish,C_wThreeBlackCrowsBearish,
     C_wEngulfingBearish,C_wAbandonedBabyBearish,C_wTriStarBearish,C_wKickingBearish,
     CNw_doji,Cw_SpinningTopWhite,Cw_SpinningTopBlack,
     barEndTimew,barindexw)

[C_mRisingWindowBullish,C_mRisingThreeMethodsBullish,C_mTweezerBottomBullish,C_mUpsideTasukiGapBullish,C_mDojiStarBullish,
     C_mMorningDojiStarBullish ,C_mPiercingBullish,C_mHammerBullish,C_mInvertedHammerBullish,C_mMorningStarBullish,
     C_mMarubozuWhiteBullish,C_mDragonflyDojiBullish,C_mHaramiCrossBullish,C_mHaramiBullish,C_mLongLowerShadowBullish,
     C_mThreeWhiteSoldiersBullish,C_mEngulfingBullish,C_mAbandonedBabyBullish,C_mTriStarBullish,C_mKickingBullish ,
     C_mOnNeckBearish,C_mFallingWindowBearish,C_mFallingThreeMethodsBearish,C_mTweezerTopBearish,C_mDarkCloudCoverBearish,
     C_mDownsideTasukiGapBearish,C_mEveningDojiStarBearish,C_mDojiStarBearish,C_mHangingManBearish,
     C_mShootingStarBearish,C_mEveningStarBearish,C_mMarubozuBlackBearish,C_mGravestoneDojiBearish,
     C_mHaramiCrossBearish,C_mHaramiBearish,C_mLongUpperShadowBearish,C_mThreeBlackCrowsBearish,
     C_mEngulfingBearish,C_mAbandonedBabyBearish,C_mTriStarBearish,C_mKickingBearish,
     CNm_doji,Cm_SpinningTopWhite,Cm_SpinningTopBlack,
     barEndTimem,barindexm ]=security(syminfo.tickerid,'M',f_detect_candle_patterns(detect_trend))
     
f_set_array(am_candle_array,am_candle_array_bar,C_mRisingWindowBullish,C_mRisingThreeMethodsBullish,
     C_mTweezerBottomBullish,C_mUpsideTasukiGapBullish,C_mDojiStarBullish,
     C_mMorningDojiStarBullish ,C_mPiercingBullish,C_mHammerBullish,C_mInvertedHammerBullish,C_mMorningStarBullish,
     C_mMarubozuWhiteBullish,C_mDragonflyDojiBullish,C_mHaramiCrossBullish,C_mHaramiBullish,C_mLongLowerShadowBullish,
     C_mThreeWhiteSoldiersBullish,C_mEngulfingBullish,C_mAbandonedBabyBullish,C_mTriStarBullish,C_mKickingBullish ,
     C_mOnNeckBearish,C_mFallingWindowBearish,C_mFallingThreeMethodsBearish,C_mTweezerTopBearish,C_mDarkCloudCoverBearish,
     C_mDownsideTasukiGapBearish,C_mEveningDojiStarBearish,C_mDojiStarBearish,C_mHangingManBearish,
     C_mShootingStarBearish,C_mEveningStarBearish,C_mMarubozuBlackBearish,C_mGravestoneDojiBearish,
     C_mHaramiCrossBearish,C_mHaramiBearish,C_mLongUpperShadowBearish,C_mThreeBlackCrowsBearish,
     C_mEngulfingBearish,C_mAbandonedBabyBearish,C_mTriStarBearish,C_mKickingBearish,
     CNm_doji,Cm_SpinningTopWhite,Cm_SpinningTopBlack,
     barEndTimem,barindexm)


var display_table=table.new(position.top_right, 2, 10, border_color=color.black,border_width = 2)

txt_candlels_5=''
txt_candlels_15=''
txt_candlels_30=''
txt_candlels_60=''
txt_candlels_120=''
txt_candlels_240=''
txt_candlels_d=''
txt_candlels_w=''
txt_candlels_m=''


f_bullish_bearish_text(num)=>
    tt=''
    if num <= 20
        tt:='🟢' 
    else if num>20 and num <=40
        tt:='🔴'
    else
        tt:='⚫'
    tt

if barstate.islast
    for a=0 to 43
        sym=f_bullish_bearish_text(a)
        if timeframe.period=='5'
            if array.get(a5_mint_candle_array,a) and barindex-array.get(a5_mint_candle_array_bar,a)<=candle_range
                txt_candlels_5:=txt_candlels_5+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindex-array.get(a5_mint_candle_array_bar,a))+' bars ago\n'
            if array.get(a15_mint_candle_array,a) and barindex15-array.get(a15_mint_candle_array_bar,a)<=candle_range
                txt_candlels_15:=txt_candlels_15+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindex15-array.get(a15_mint_candle_array_bar,a))+' bars ago\n'
            if array.get(a30_mint_candle_array,a) and barindex30-array.get(a30_mint_candle_array_bar,a)<=candle_range
                txt_candlels_30:=txt_candlels_30+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindex30-array.get(a30_mint_candle_array_bar,a))+' bars ago\n'
            if array.get(a1_hr_candle_array,a) and barindex1_hr-array.get(a1_hr_candle_array_bar,a)<=candle_range
                txt_candlels_60:=txt_candlels_60+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindex1_hr-array.get(a1_hr_candle_array_bar,a))+' bars ago\n'
            if array.get(a2_hr_candle_array,a) and barindex2_hr-array.get(a2_hr_candle_array_bar,a)<=candle_range
                txt_candlels_120:=txt_candlels_120+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindex2_hr-array.get(a2_hr_candle_array_bar,a))+' bars ago\n'
            if array.get(a4_hr_candle_array,a) and barindex4_hr-array.get(a4_hr_candle_array_bar,a)<=candle_range
                txt_candlels_240:=txt_candlels_240+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindex4_hr-array.get(a4_hr_candle_array_bar,a))+' bars ago\n'
            if array.get(ad_candle_array,a) and barindexd-array.get(ad_candle_array_bar,a)<=candle_range
                txt_candlels_d:=txt_candlels_d+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexd-array.get(ad_candle_array_bar,a))+' bars ago\n'
            if array.get(aw_candle_array,a) and barindexw-array.get(aw_candle_array_bar,a)<=candle_range
                txt_candlels_w:=txt_candlels_w+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexw-array.get(aw_candle_array_bar,a))+' bars ago\n'
            if array.get(am_candle_array,a) and barindexm-array.get(am_candle_array_bar,a)<=candle_range
                txt_candlels_m:=txt_candlels_m+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexm-array.get(am_candle_array_bar,a))+' bars ago\n'
        
        if timeframe.period=='15'
            txt_candlels_5:='NA'
            if array.get(a15_mint_candle_array,a) and barindex15-array.get(a15_mint_candle_array_bar,a)<=candle_range
                txt_candlels_15:=txt_candlels_15+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindex15-array.get(a15_mint_candle_array_bar,a))+' bars ago\n'
            if array.get(a30_mint_candle_array,a) and barindex30-array.get(a30_mint_candle_array_bar,a)<=candle_range
                txt_candlels_30:=txt_candlels_30+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindex30-array.get(a30_mint_candle_array_bar,a))+' bars ago\n'
            if array.get(a1_hr_candle_array,a) and barindex1_hr-array.get(a1_hr_candle_array_bar,a)<=candle_range
                txt_candlels_60:=txt_candlels_60+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindex1_hr-array.get(a1_hr_candle_array_bar,a))+' bars ago\n'
            if array.get(a2_hr_candle_array,a) and barindex2_hr-array.get(a2_hr_candle_array_bar,a)<=candle_range
                txt_candlels_120:=txt_candlels_120+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindex2_hr-array.get(a2_hr_candle_array_bar,a))+' bars ago\n'
            if array.get(a4_hr_candle_array,a) and barindex4_hr-array.get(a4_hr_candle_array_bar,a)<=candle_range
                txt_candlels_240:=txt_candlels_240+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindex4_hr-array.get(a4_hr_candle_array_bar,a))+' bars ago\n'
            if array.get(ad_candle_array,a) and barindexd-array.get(ad_candle_array_bar,a)<=candle_range
                txt_candlels_d:=txt_candlels_d+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexd-array.get(ad_candle_array_bar,a))+' bars ago\n'
            if array.get(aw_candle_array,a) and barindexw-array.get(aw_candle_array_bar,a)<=candle_range
                txt_candlels_w:=txt_candlels_w+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexw-array.get(aw_candle_array_bar,a))+' bars ago\n'
            if array.get(am_candle_array,a) and barindexm-array.get(am_candle_array_bar,a)<=candle_range
                txt_candlels_m:=txt_candlels_m+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexm-array.get(am_candle_array_bar,a))+' bars ago\n'
        
        if timeframe.period=='30'
            txt_candlels_5:='NA'
            txt_candlels_15:='NA'
            if array.get(a30_mint_candle_array,a) and barindex30-array.get(a30_mint_candle_array_bar,a)<=candle_range
                txt_candlels_30:=txt_candlels_30+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindex30-array.get(a30_mint_candle_array_bar,a))+' bars ago\n'
            if array.get(a1_hr_candle_array,a) and barindex1_hr-array.get(a1_hr_candle_array_bar,a)<=candle_range
                txt_candlels_60:=txt_candlels_60+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindex1_hr-array.get(a1_hr_candle_array_bar,a))+' bars ago\n'
            if array.get(a2_hr_candle_array,a) and barindex2_hr-array.get(a2_hr_candle_array_bar,a)<=candle_range
                txt_candlels_120:=txt_candlels_120+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindex2_hr-array.get(a2_hr_candle_array_bar,a))+' bars ago\n'
            if array.get(a4_hr_candle_array,a) and barindex4_hr-array.get(a4_hr_candle_array_bar,a)<=candle_range
                txt_candlels_240:=txt_candlels_240+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindex4_hr-array.get(a4_hr_candle_array_bar,a))+' bars ago\n'
            if array.get(ad_candle_array,a) and barindexd-array.get(ad_candle_array_bar,a)<=candle_range
                txt_candlels_d:=txt_candlels_d+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexd-array.get(ad_candle_array_bar,a))+' bars ago\n'
            if array.get(aw_candle_array,a) and barindexw-array.get(aw_candle_array_bar,a)<=candle_range
                txt_candlels_w:=txt_candlels_w+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexw-array.get(aw_candle_array_bar,a))+' bars ago\n'
            if array.get(am_candle_array,a) and barindexm-array.get(am_candle_array_bar,a)<=candle_range
                txt_candlels_m:=txt_candlels_m+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexm-array.get(am_candle_array_bar,a))+' bars ago\n'
       
        if timeframe.period=='60'
            txt_candlels_5:='NA'
            txt_candlels_15:='NA'
            txt_candlels_30:='NA'
            if array.get(a1_hr_candle_array,a) and barindex1_hr-array.get(a1_hr_candle_array_bar,a)<=candle_range
                txt_candlels_60:=txt_candlels_60+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindex1_hr-array.get(a1_hr_candle_array_bar,a))+' bars ago\n'
            if array.get(a2_hr_candle_array,a) and barindex2_hr-array.get(a2_hr_candle_array_bar,a)<=candle_range
                txt_candlels_120:=txt_candlels_120+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindex2_hr-array.get(a2_hr_candle_array_bar,a))+' bars ago\n'
            if array.get(a4_hr_candle_array,a) and barindex4_hr-array.get(a4_hr_candle_array_bar,a)<=candle_range
                txt_candlels_240:=txt_candlels_240+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindex4_hr-array.get(a4_hr_candle_array_bar,a))+' bars ago\n'
            if array.get(ad_candle_array,a) and barindexd-array.get(ad_candle_array_bar,a)<=candle_range
                txt_candlels_d:=txt_candlels_d+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexd-array.get(ad_candle_array_bar,a))+' bars ago\n'
            if array.get(aw_candle_array,a) and barindexw-array.get(aw_candle_array_bar,a)<=candle_range
                txt_candlels_w:=txt_candlels_w+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexw-array.get(aw_candle_array_bar,a))+' bars ago\n'
            if array.get(am_candle_array,a) and barindexm-array.get(am_candle_array_bar,a)<=candle_range
                txt_candlels_m:=txt_candlels_m+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexm-array.get(am_candle_array_bar,a))+' bars ago\n'

        if timeframe.period=='120'
            txt_candlels_5:='NA'
            txt_candlels_15:='NA'
            txt_candlels_30:='NA'
            txt_candlels_60:='NA'
            if array.get(a2_hr_candle_array,a) and barindex2_hr-array.get(a2_hr_candle_array_bar,a)<=candle_range
                txt_candlels_120:=txt_candlels_120+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindex2_hr-array.get(a2_hr_candle_array_bar,a))+' bars ago\n'
            if array.get(a4_hr_candle_array,a) and barindex4_hr-array.get(a4_hr_candle_array_bar,a)<=candle_range
                txt_candlels_240:=txt_candlels_240+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindex4_hr-array.get(a4_hr_candle_array_bar,a))+' bars ago\n'
            if array.get(ad_candle_array,a) and barindexd-array.get(ad_candle_array_bar,a)<=candle_range
                txt_candlels_d:=txt_candlels_d+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexd-array.get(ad_candle_array_bar,a))+' bars ago\n'
            if array.get(aw_candle_array,a) and barindexw-array.get(aw_candle_array_bar,a)<=candle_range
                txt_candlels_w:=txt_candlels_w+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexw-array.get(aw_candle_array_bar,a))+' bars ago\n'
            if array.get(am_candle_array,a) and barindexm-array.get(am_candle_array_bar,a)<=candle_range
                txt_candlels_m:=txt_candlels_m+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexm-array.get(am_candle_array_bar,a))+' bars ago\n'
        
        if timeframe.period=='240'
            txt_candlels_5:='NA'
            txt_candlels_15:='NA'
            txt_candlels_30:='NA'
            txt_candlels_60:='NA'
            txt_candlels_120:='NA'
            if array.get(a4_hr_candle_array,a) and barindex4_hr-array.get(a4_hr_candle_array_bar,a)<=candle_range
                txt_candlels_240:=txt_candlels_240+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindex4_hr-array.get(a4_hr_candle_array_bar,a))+' bars ago\n'
            if array.get(ad_candle_array,a) and barindexd-array.get(ad_candle_array_bar,a)<=candle_range
                txt_candlels_d:=txt_candlels_d+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexd-array.get(ad_candle_array_bar,a))+' bars ago\n'
            if array.get(aw_candle_array,a) and barindexw-array.get(aw_candle_array_bar,a)<=candle_range
                txt_candlels_w:=txt_candlels_w+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexw-array.get(aw_candle_array_bar,a))+' bars ago\n'
            if array.get(am_candle_array,a) and barindexm-array.get(am_candle_array_bar,a)<=candle_range
                txt_candlels_m:=txt_candlels_m+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexm-array.get(am_candle_array_bar,a))+' bars ago\n'

        if timeframe.period=='D'
            txt_candlels_5:='NA'
            txt_candlels_15:='NA'
            txt_candlels_30:='NA'
            txt_candlels_60:='NA'
            txt_candlels_120:='NA'
            txt_candlels_240:='NA'
            if array.get(ad_candle_array,a) and barindexd-array.get(ad_candle_array_bar,a)<=candle_range
                txt_candlels_d:=txt_candlels_d+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexd-array.get(ad_candle_array_bar,a))+' bars ago\n'
            if array.get(aw_candle_array,a) and barindexw-array.get(aw_candle_array_bar,a)<=candle_range
                txt_candlels_w:=txt_candlels_w+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexw-array.get(aw_candle_array_bar,a))+' bars ago\n'
            if array.get(am_candle_array,a) and barindexm-array.get(am_candle_array_bar,a)<=candle_range
                txt_candlels_m:=txt_candlels_m+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexm-array.get(am_candle_array_bar,a))+' bars ago\n'
        
        if timeframe.period=='W'
            txt_candlels_5:='NA'
            txt_candlels_15:='NA'
            txt_candlels_30:='NA'
            txt_candlels_60:='NA'
            txt_candlels_120:='NA'
            txt_candlels_240:='NA'
            txt_candlels_d:='NA'
            if array.get(aw_candle_array,a) and barindexw-array.get(aw_candle_array_bar,a)<=candle_range
                txt_candlels_w:=txt_candlels_w+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexw-array.get(aw_candle_array_bar,a))+' bars ago\n'
            if array.get(am_candle_array,a) and barindexm-array.get(am_candle_array_bar,a)<=candle_range
                txt_candlels_m:=txt_candlels_m+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexm-array.get(am_candle_array_bar,a))+' bars ago\n'
  
        if timeframe.period=='M'
            txt_candlels_5:='NA'
            txt_candlels_15:='NA'
            txt_candlels_30:='NA'
            txt_candlels_60:='NA'
            txt_candlels_120:='NA'
            txt_candlels_240:='NA'
            txt_candlels_d:='NA' 
            txt_candlels_w:='NA'
            if array.get(am_candle_array,a) and barindexm-array.get(am_candle_array_bar,a)<=candle_range
                txt_candlels_m:=txt_candlels_m+sym+array.get(candle_pattern_name,a)+' found '+ 
                 tostring(barindexm-array.get(am_candle_array_bar,a))+' bars ago\n'

            

    if txt_candlels_5==''
        txt_candlels_5:='No Pattern Detected'
        
    if txt_candlels_15==''
        txt_candlels_15:='No Pattern Detected'
    
    if txt_candlels_30==''
        txt_candlels_30:='No Pattern Detected'
    
    if txt_candlels_60==''
        txt_candlels_60:='No Pattern Detected'
        
    if txt_candlels_120==''
        txt_candlels_120:='No Pattern Detected'
        
    if txt_candlels_240==''
        txt_candlels_240:='No Pattern Detected'
        
    if txt_candlels_d==''
        txt_candlels_d:='No Pattern Detected'
    
    if txt_candlels_w==''
        txt_candlels_w:='No Pattern Detected'
    
    if txt_candlels_m==''
        txt_candlels_m:='No Pattern Detected'
    
    table.cell(display_table,0,0,'Time Frame',text_color=color.white,bgcolor=#1848CC)
    table.cell(display_table,1,0,'Candle Patterns found in '+tostring(candle_range)+' bars lookback',text_color=color.white,bgcolor=#1848CC)
    table.cell(display_table,0,1,'5M',text_color=color.white,bgcolor=#1848CC)
    table.cell(display_table,0,2,'15M',text_color=color.white,bgcolor=#1848CC)
    table.cell(display_table,0,3,'30M',text_color=color.white,bgcolor=#1848CC)
    table.cell(display_table,0,4,'1H',text_color=color.white,bgcolor=#1848CC)
    table.cell(display_table,0,5,'2H',text_color=color.white,bgcolor=#1848CC)
    table.cell(display_table,0,6,'4H',text_color=color.white,bgcolor=#1848CC)
    table.cell(display_table,0,7,'D',text_color=color.white,bgcolor=#1848CC)
    table.cell(display_table,0,8,'W',text_color=color.white,bgcolor=#1848CC)
    table.cell(display_table,0,9,'M',text_color=color.white,bgcolor=#1848CC)
    table.cell(display_table,1,1,txt_candlels_5,text_color=color.white,bgcolor=#1848CC)
    table.cell(display_table,1,2,txt_candlels_15,text_color=color.white,bgcolor=#1848CC)
    table.cell(display_table,1,3,txt_candlels_30,text_color=color.white,bgcolor=#1848CC)
    table.cell(display_table,1,4,txt_candlels_60,text_color=color.white,bgcolor=#1848CC)
    table.cell(display_table,1,5,txt_candlels_120,text_color=color.white,bgcolor=#1848CC)
    table.cell(display_table,1,6,txt_candlels_240,text_color=color.white,bgcolor=#1848CC)
    table.cell(display_table,1,7,txt_candlels_d,text_color=color.white,bgcolor=#1848CC)
    table.cell(display_table,1,8,txt_candlels_w,text_color=color.white,bgcolor=#1848CC)
    table.cell(display_table,1,9,txt_candlels_m,text_color=color.white,bgcolor=#1848CC)
    
