X48 - Strategy | BreakOut & Consecutive (11in1) + Alert | V.1.2
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © X4815162342

//================== Read This First Before Use This Strategy ==============
// *********** Please be aware that this strategy is not a guarantee of success and may lead to losses.
// *********** Trading involves risk and you should always do your own research before making any decisions.

// ================= Thanks Source Script and Explain This Strategy ===================
// This Strategy Are Combine [5] Strategy and [8] Indicators [1] Alert Function For Systematric Trading User.
// [3] Strategy List, Thanks For Original Source Script [1],[2] From Tradingview Build-in Script [3] From fmzquant Github
// [3.1] Channel BreakOut Strategy : Calculate BreakOut Zone For Buy and Sell.
// [3.2] Consecutive Bars UP/Down Strategy : The consecutive bars up/down strategy is a trading strategy used to identify potential buy and sell signals in the stock market. This strategy involves looking for a series of bars (or candles) that are either all increasing or all decreasing in price. If the bars are all increasing, it can be a signal to buy, and if the bars are all decreasing, it can be a signal to sell. This strategy can be used on any timeframe, from a daily chart to an intraday chart.
// [3.3] 15m Range Length SD : Range Of High and Low Candle Price and Lookback For Calculate Buy and Sell.
// [3.4] MA Type CrossOver and CrossUnder
// [3.5] MACD CrossOver and CrossUnder
// [8] Indicators Are Simple Source Script (Almost I'm Chating With CHAT-GPT and Convert pinescript V4 to V5 again for complete almost script and combine after)
// [8.1] SwingHigh and SwingLow Plot For SL (StopLoss by Last Swing).
// [8.2] Engulfing and 3 Candle Engulfing Plot.
// [8.3] Stochastic RSI for Plot and Fill Background Paint and Plot TEXT For BULL and BEAR TREND.
// [8.4] MA TYPE MODE are plot 2 line of MA Type (EMA, SMA, HMA, WMA, VWMA) for Crossover and Crossunder.
// [8.5] Donchian Fans MODE are Plot Dot Line With Triangle Degree Bull Trend is Green Plot and Bear Trend is Red Plot.
// [8.6] Ichimoku Cloud Are Plot Cloud A-B For Bull and Bear Trend.
// [8.7] RSI OB and OS for TEXT PLOT 'OB' , 'OS' you will know after OB and OS, you can combo with other indicators that's make you know what's the similar trend look like?
// [8.8] MACD for Plot Diamond when MACD > 0 and MACD < 0, you can combo with other indicators that's make you know what's the similar trend look like?
// [1] Alert Can Alert Sent When Buy and Sell or TP and SL, you can adjust text to alert sent by your self or use default setting.

// ========== Let'e Me Explain How To Use This Strategy =============

// ========== Properties Setting ==========
// Capital : Default : 500 USDT For Alot Of People Are Beginner Investor = It's Capital Your Cash For Invertment
// Ordersize : Default Are Setting 5% / Order [It's Mean 5% From 1,000] We Call Compounded

// ========== INPUT Setting ==========
// First Part Use Must Choose Checkbox For Use [1] of [3] Strategy and Choose TP/SL by Swing or % (can chosoe both)
// In Detail Of Setting Are Not Too Much, Please Read The Header Of Setting Before Change The Value
// For The Indicator In List You Want To Add Just Check ✅ From MODE Setting, It's Show On Your Chart
// You Can Custom TP/SL % You Want

// ========== ##### No trading strategy is guaranteed to be 100% successful. ###### =========
// For Example In My Systematic Trading
// Select 1/3 Strategy Setting TP/SL % Match With Timeframe TP Long Are Not Set It's Can 161.8 - 423.6% but Short Position Are Not Than 100% Just Fine From Your Aset
// Choose Indicators For Make Sure Trend and Strategy are the same way like Strategy are Long Position but MACD and Sto background is bear. that's mean this time not open position.
// Donchian Fans is Simple Support and Ressistant If You Don't Know How To Plot That's, This indicator plot a simple for you ><.
// Make Sure With Engulfing and 3 Candle Engulfing If You Don't Know, What's The Engulfing, This Indicator are plot for you too ><.
// For a Big Trend You can use Ichimoku Cloud For Check Trend, Candle Upper Than Cloud or Lower Than Cloud for Bull and Bear Trend.  

/////////notes////////////////////////////////////////
// This is based on the ATR trailing stop indicator //
// width addition of two levels of stops and        //
// different interpretation.                        //
// This is a fast-reacting system and is better     //
// suited for higher volatility markets             //
//////////////////////////////////////////////////////

// ========== Confirm Setting ==========
// 1. Confirm by MACD > 0 and < 0
// 2. Confirm by Stochastic RSI Cross
// 3. Confirm by MA Type Fast > Slow or <
// 4. Confirm by Ichimoku Tenkan > Kijun or <

// ========== TP/SL Setting ==========
// 1. By Swing High / Low
// 2. By ATR Trailing Stop
// 3. By Callback [%] From Last H/L
// 4. By FIX [%] TP/SL

// For Forex Setting (For Free Swap And Commission 0 Only)
// Capital = 50$
// Order Size = 1 Contract
// Commission = 0
// Slippage = Average Your Spread Broker
// TP = 0.0055% - 0.0057% (For Forex Use Lot For Easy TP by PNL 7-11 pip)

// For Cryptocurrency Setting
// Capital = 100$
// Order Size = 16.333 USDT
// Commission = 0.1 or 0.04

//@version=5
strategy("X48 - Strategy | Channel BreakOut & Consecutive (17in1) + TL/TP/SL | V.2.13", overlay=true, calc_on_order_fills = true, initial_capital = 50, default_qty_type = strategy.cash, default_qty_value = 16.333, commission_type = strategy.commission.percent, commission_value = 0.1, currency = currency.USDT, calc_on_every_tick = true)
//================ SPOT MODE ==============
GRSPT = "=== 🍀🍀🍀 SPOT MODE 🍀🍀🍀 ==="
Spot_MODE = input.bool(defval = false, title = "🍀 SPOT MODE", group = GRSPT)
//================ CHANNEL BREAKOUT SETTING ===============
GRS = "==1️⃣2️⃣3️⃣4️⃣5️⃣ SELECT [X] STRATEGY + TAKE PROFIT & STOP LOSS ? + CONFIRM MODE ? 5️⃣4️⃣3️⃣2️⃣1️⃣=="
GR1 = "===== 1️⃣1️⃣1️⃣ CHANNEL BREAKOUT STRATEGY 1️⃣1️⃣1️⃣====="
BreakOut_MODE = input.bool(defval = true, title = "1️⃣ CHANNEL BREAKOUT MODE", group = GRS, inline = "MainHEAD", tooltip = "Use Channel BreakOut Strategy")

GRCON = "=====🅰️🅱️ CONFIRM MODE 🅱️🅰️====="
MACDConfirm_MODE = input.bool(defval = false, title = "🅰️ MACD CONFIRM MODE", group = GRCON, tooltip = "Use MACD For Confirm Signal")
//StoConfirm_MODE = input.bool(defval = false, title = "🅱️ STOCHASTIC CONFIRM MODE", group = GRCON, tooltip = "Use Stochastic For Confirm Signal")
RSIConfirm_MODE = input.bool(defval = false, title = "🉐 RSI CONFIRM MODE", group = GRCON, tooltip = "Use Stochastic For Confirm Signal")
MACross_MODE = input.bool(defval = false, title = "💯 MA CROSS X CONFIRM MODE", group = GRCON, tooltip = "Use MA Type Cross For Confirm Signal")
IchiConfirm_MODE = input.bool(defval = false, title = "💮 ICHIMOKU TENKAN&KIJUN CROSS X CONFIRM MODE", group = GRCON, tooltip = "Use Ichimoku Tenkan & Kijun Cross For Confirm Signal")

GRSUB = "=====🆎🆑🅾️🆘 TP & SL SELECT MODE 🆘🅾️🆑🆎====="
Swing_STOP = input.bool(title="🆎 STOP LOSS BY SWING MODE", defval=false, group = GRSUB, tooltip = 'If Mode On = Use Stop Loss By Last Swing', inline = "SubMAIN")
plotcolor = input.bool(defval = false, title = '🆑 ATR Trailing Stop', group = GRSUB)
BOTrail_MODE = input.bool(defval = false, title = "🅾️ CALLBACK Trailing Stop [Low Profit But More TP]", group = GRSUB, tooltip = "BreakOut Length For Who's Want Fast Trailing But This Low Profit But More Time For TP\nIt's Can Combo With Breakout and 15m")
BungToon_Mode = input.bool(defval = false, title = "🅾️ Entry Cover Mode", group = GRSUB, tooltip = "Stop Buy and Sell Cover Your Loss With Entry Price")

/////////////////////////////////////////////////////////////////////////////////////////////////////
Text_Alert_Future = '{{strategy.order.alert_message}}'
copy_Fu = input( defval= Text_Alert_Future ,    title="Alert Message for BOT", inline = '00'  ,group = '═ Bot Setting ═ \n >> If You Dont Use Bot Just Pass It' ,tooltip = 'Alert For X48-BOT > Copy and Paste To Alert Function')
passphrase = input.string(defval='1234', title ='Bot Pass',group='═ Bot Setting ═ \n >> If You Dont Use Bot Just Pass It', tooltip = 'Passphrase Must Be Same as X48-BOT')
leveragex  = input.int(125,title='leverage',group='═ Bot Setting ═ \n >> If You Dont Use Bot Just Pass It',tooltip='"NOTHING" to do with Position size For Command To X48-BOT Only',minval=1)
longcommand = input.string(defval='AutoLong', title = 'Bot Long Command',group='═ Bot Setting ═ \n >> If You Dont Use Bot Just Pass It', tooltip = '1.OpenLong\n2.AutoLong\n***If AutoLong = Close(100%) First > Open Long Position Auto')
shortcommand = input.string(defval='AutoShort', title = 'Bot Short Command',group='═ Bot Setting ═ \n >> If You Dont Use Bot Just Pass It', tooltip = '1.OpenShort\n2.AutoShort\n***If AutoShort = Close(100%) First > Open Short Position Auto')
markettype = input.string(defval='bnfuture', title = 'Future/Spot Command',group='═ Bot Setting ═ \n >> If You Dont Use Bot Just Pass It', tooltip = '1. bnfuture = FUTURE MODE\n2. bnspot = SPOT MODE\n 3.bncombo = EZ 2in1 Order')

//////////////// Strategy Alert For X4815162342 BOT //////////////////////
//////// For Use Bot Can Change This Command By Your Self /////////////////////
string Alert_OpenLong       = '{"ex":"'+markettype+'","side": "'+longcommand+'", "amount": "@{{strategy.order.contracts}}", "symbol": "{{ticker}}", "passphrase": "'+passphrase+'","leverage":"'+str.tostring(leveragex)+'", "tp" : "25", "sl" : "0", "tl" : "0", "callback" : "0"}'
string Alert_OpenShort      = '{"ex":"'+markettype+'","side": "'+shortcommand+'", "amount": "@{{strategy.order.contracts}}", "symbol": "{{ticker}}", "passphrase": "'+passphrase+'","leverage":"'+str.tostring(leveragex)+'", "tp" : "25", "sl" : "0", "tl" : "0", "callback" : "0"}'
//string Alert_LongTP         = '{"ex":"bnfuture","side": "CloseLong", "amount": "@{{strategy.order.contracts}}", "symbol": "{{ticker}}", "passphrase": "'+passphrase+'","leverage":"'+str.tostring(leveragex)+'"}'
//string Alert_ShortTP        = '{"ex":"bnfuture","side": "CloseShort", "amount": "@{{strategy.order.contracts}}", "symbol": "{{ticker}}", "passphrase": "'+passphrase+'","leverage":"'+str.tostring(leveragex)+'"}'
//var message_closelong       = '{"ex":"bnfuture","side": "CloseLong", "amount": "%100", "symbol": "{{ticker}}", "passphrase": "'+passphrase+'","leverage":"'+str.tostring(leveragex)+'"}'
//var message_closeshort      = '{"ex":"bnfuture","side": "CloseShort", "amount": "%100", "symbol": "{{ticker}}", "passphrase": "'+passphrase+'","leverage":"'+str.tostring(leveragex)+'"}'
string Alert_StopLosslong   = '{"ex":"'+markettype+'","side": "CloseLong", "amount": "%100", "symbol": "{{ticker}}", "passphrase": "'+passphrase+'","leverage":"'+str.tostring(leveragex)+'", "tp" : "0", "sl" : "0", "tl" : "0", "callback" : "0"}'
string Alert_StopLossshort  = '{"ex":"'+markettype+'","side": "CloseShort", "amount": "%100", "symbol": "{{ticker}}", "passphrase": "'+passphrase+'","leverage":"'+str.tostring(leveragex)+'", "tp" : "0", "sl" : "0", "tl" : "0", "callback" : "0"}'

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////  
ticker_close_price = request.security(syminfo.tickerid, timeframe = "1", expression = close)
ticker_high_price = request.security(syminfo.tickerid, timeframe = "1", expression = high)
ticker_low_price = request.security(syminfo.tickerid, timeframe = "1", expression = low)
period_close_price = request.security(syminfo.tickerid, timeframe = timeframe.period, expression = close)
period_high_price = request.security(syminfo.tickerid, timeframe = timeframe.period, expression = high)
period_low_price = request.security(syminfo.tickerid, timeframe = timeframe.period, expression = low)
entry_price = strategy.opentrades.entry_price(strategy.opentrades - 1)

PLOTBO_MODE = input.bool(title="[PLOT] BreakOut LINE [PLOT]", defval = false, group = GR1)
lengthBO = input.int(title="1️⃣ Length BreakOut", minval=1, maxval=1000, defval=5, group = GR1)
triling_BO = input.float(title = "🅾️ BreakOut Trailing CALLBACK [%]", defval = 2, minval = 0.01, maxval = 999.99, group = GR1)
upBound = ta.highest(high, lengthBO)
downBound = ta.lowest(low, lengthBO)

SL_LongBO = (ticker_close_price <= upBound-((upBound*triling_BO)/100))
//SL_LongBOPrice = upBound-((upBound*triling_BO)/100)
//SL_LongBOPrice = high[0]-((high[0]*triling_BO)/100)

SL_ShortBO = (ticker_close_price >= downBound+((downBound*triling_BO)/100))
//SL_ShortBOPrice = downBound+((downBound*triling_BO)/100)
//SL_ShortBOPrice = (low[0]+((low[0]*triling_BO)/100))

pvthi_BO = upBound
pvtlo_BO = downBound

ShuntBO = 1  //Wait for close before printing pivot? 1 for true 0 for flase
maxLvlLenBO = 0  //Maximum Extension Length
pvthiBO = pvthi_BO[ShuntBO]
pvtloBO = pvtlo_BO[ShuntBO]

// Count How many candles for current Pivot Level, If new reset.
counthiBO = ta.barssince(not na(pvthiBO))
countloBO = ta.barssince(not na(pvtloBO))

pvthisBO = fixnan(pvthiBO)
pvtlosBO = fixnan(pvtloBO)
hipcBO = ta.change(pvthisBO) != 0 ? na : color.lime
lopcBO = ta.change(pvtlosBO) != 0 ? na : color.red

// Display Pivot lines
plot(PLOTBO_MODE ? maxLvlLenBO == 0 or counthiBO < maxLvlLenBO ? pvthisBO : na : na, color=hipcBO, linewidth=2, title='Top LevelsBO')
plot(PLOTBO_MODE ? maxLvlLenBO == 0 or countloBO < maxLvlLenBO ? pvtlosBO : na : na, color=lopcBO, linewidth=2, title='Bottom LevelsBO')

//================ Consecutive UP/Down ===============
GR2 = "=====2️⃣2️⃣2️⃣ Consecutive Up/Down Strategy 2️⃣2️⃣2️⃣====="
Consecutive_MODE = input.bool(defval = false, title = "2️⃣ CONSECUTIVE BarsUP/DOWN MODE", group = GRS, tooltip = "Use Consecutive Strategy")
consecutiveBarsUp = input.int(defval = 3, title = '2️⃣ Consecutive BarsUp', minval = 1, group = GR2)
consecutiveBarsDown = input.int(defval = 3, title = '2️⃣ Consecutive BarsDown', minval = 1, group = GR2)
price = close
ups = 0.0
ups := price > price[1] ? nz(ups[1]) + 1 : 0
dns = 0.0
dns := price < price[1] ? nz(dns[1]) + 1 : 0

// ============= 15m BREAK RANGE GOLD AND CRYPTO ===============
GR3 = "=====3️⃣3️⃣3️⃣ 15m BREAK RANGE STRATEGY 3️⃣3️⃣3️⃣====="
hlrang_mode = input.bool(defval = false, title = "3️⃣ 15m High/Low Range Break MODE [BUY ONLY]", group = GRS)
hlrang_plot = input.bool(defval = false, title = "[PLOT] 15m High/Low Range Break [PLOT]", group = GR3)
rrange = high-low
lookback = input.int(2, minval=1, title="3️⃣ 15m - Lookback", group = GR3)
xr = input.int(10, minval=1, title="3️⃣ 15m - Range Length", group = GR3)
mult = input.float(2.0, minval=0.001, maxval=50, title="15m - SD", group = GR3)

computation = mult * ta.stdev(rrange, xr) + ta.sma(rrange, xr)
cond1 = rrange > computation

plot(hlrang_plot ? rrange : na, title="Range H-L", style=plot.style_columns)
plot(hlrang_plot ? computation : na, title="H-L SD", style=plot.style_line, color=color.orange)
plot(hlrang_plot ? close - close[lookback] : na, title="Close Direction", color=close > close[lookback] ? color.green : color.red, style=plot.style_histogram)

longCondition15 =  hlrang_mode ? cond1 and close > close[lookback] : na

shortCondition15 = hlrang_mode ? cond1 and close < close[lookback] : na

//============== Swing High and Low Mode ===============
// Swing Plot
//Swing_MODE = input.bool(title="PLOT SWING MODE", defval=true, group = '= SWING SETTING =', tooltip = 'If Mode On = Plot Swing High and Swing Low')
pvtLenL = input.int(3, minval=1, title='🆎 Pivot Length Left Hand Side', group = '==🆎🆎🆎 TP/SL SWING SETTING 🆎🆎🆎==')
pvtLenR = input.int(3, minval=1, title='🆎 Pivot Length Right Hand Side', group = '==🆎🆎🆎 TP/SL SWING SETTING 🆎🆎🆎==')

// Get High and Low Pivot Points
pvthi_ = ta.pivothigh(high, pvtLenL, pvtLenR)
pvtlo_ = ta.pivotlow(low, pvtLenL, pvtLenR)

// Force Pivot completion before plotting.
Shunt = 1  //Wait for close before printing pivot? 1 for true 0 for flase
maxLvlLen = 0  //Maximum Extension Length
pvthi = pvthi_[Shunt]
pvtlo = pvtlo_[Shunt]

// Count How many candles for current Pivot Level, If new reset.
counthi = ta.barssince(not na(pvthi))
countlo = ta.barssince(not na(pvtlo))

pvthis = fixnan(pvthi)
pvtlos = fixnan(pvtlo)
hipc = ta.change(pvthis) != 0 ? na : color.maroon
lopc = ta.change(pvtlos) != 0 ? na : color.green

// Display Pivot lines
plot(Swing_STOP ? maxLvlLen == 0 or counthi < maxLvlLen ? pvthis : na : na, color=hipc, linewidth=1, offset=-pvtLenR - Shunt, title='Top Levels')
plot(Swing_STOP ? maxLvlLen == 0 or countlo < maxLvlLen ? pvtlos : na : na, color=lopc, linewidth=1, offset=-pvtLenR - Shunt, title='Bottom Levels')
plot(Swing_STOP ? maxLvlLen == 0 or counthi < maxLvlLen ? pvthis : na : na, color=hipc, linewidth=1, offset=0, title='Top Levels 2')
plot(Swing_STOP ? maxLvlLen == 0 or countlo < maxLvlLen ? pvtlos : na : na, color=lopc, linewidth=1, offset=0, title='Bottom Levels 2')

stopswinglow = ta.crossunder(close,pvtlos)
stopswinghigh = ta.crossover(close,pvthis)

if Swing_STOP == true
    if Spot_MODE == false
        if (close < pvtlos)
            strategy.close("Long", qty_percent = 100, comment = "StopLong🏳️SwLow", alert_message = Alert_StopLosslong)
        if (close > pvthis)
            strategy.close("Short", qty_percent = 100, comment = "StopShort🏳️SwHi", alert_message = Alert_StopLossshort)
    if Spot_MODE == true
        if (close < pvtlos)
            strategy.close("Long", qty_percent = 100, comment = "StopLong🏳️SwLow", alert_message = Alert_StopLosslong)

///////////////////////////////////////////////////////////////////////////////////
//GRSTO = "==🅱️🅱️🅱️ STOCHASTIC RSI SETTING [BG/Confirm]🅱️🅱️🅱️=="
//stobg_mode = input.bool(title="Stochastic RSI Background Paint", defval=false, group=GRSTO)
//stobg_plot = input.bool(title="STO-TEXT", defval=false, group=GRSTO, inline = 'STOT1')
//stobull_text = input.color(title = 'BULL', defval = color.white, group = GRSTO, inline = 'STOT1')
//stobear_text = input.color(title = 'BEAR', defval = color.orange, group = GRSTO, inline = 'STOT1')
//lengthMACD = input(title='🅱️ Length', defval=21, group = GRSTO, inline = '15')
//offsetMACD = input(title='🅱️ Offset', defval=0, group = GRSTO, inline = '15')
//srcMACD = input(close, title='🅱️ Source', group = GRSTO, inline = '16')
//length2MACD = input(title='🅱️ Trigger Length', defval=6, group = GRSTO, inline = '16')
//bullstobg = input.color(title = 'Bull BG Color', defval = color.green, group = GRSTO, inline = 'STOBG1')
//bearstobg = input.color(title = 'Bear BG Color', defval = color.red, group = GRSTO, inline = 'STOBG1')
//transstobg = input.int(defval = 75, title = 'Trans', minval = 0, maxval = 100, group = GRSTO, inline = 'STOBG1')
//
//lsma = ta.linreg(srcMACD, lengthMACD, offsetMACD)
//lsma2 = ta.linreg(lsma, lengthMACD, offsetMACD)
//b = lsma - lsma2
//zlsma2 = lsma + b
//trig2 = ta.sma(zlsma2, length2MACD)
//
//c1 = zlsma2 > trig2 ? bullstobg : bearstobg
//stobull = ta.crossover(zlsma2,trig2)
//stobear = ta.crossunder(zlsma2, trig2)
//stobullplus = zlsma2 > trig2
//stobearplus = zlsma2 < trig2
//plotshape(stobg_plot ? stobull : na, title = 'STO-BULL', text = 'STO-BULL', location = location.belowbar, textcolor = stobull_text, size = size.tiny)
//plotshape(stobg_plot ? stobear : na, title = 'STO-BULL', text = 'STO-BEAR', location = location.abovebar, textcolor = stobear_text, size = size.tiny)
//
//p1 = plot(stobg_mode ? zlsma2 : na, color=c1, linewidth=0)
//p2 = plot(stobg_mode ? trig2 : na, color=c1, linewidth=0)
//fill(p1, p2, color=color.new(c1,transp = transstobg))

////////////////////////////////////////////////////////////////////////////////////
GRMAC = '===💯💯💯4️⃣ Multi MA SETTING 4️⃣💯💯💯==='
MAStrategy_MODE = input.bool(title='4️⃣ MA CROSS X STRATEGY MODE', defval=false, group = GRS)
MARepeat_Mode = input.bool(title='4️⃣ 🎯MA CROSS X REPEAT MODE', defval=false, group = GRS, tooltip = "Repeat Mode After TP/SL Open Position With Trend Fast >,< Slow Again")
/////////// Normal Setting ////////////////
srcstrategy = input(close, title='💯4️⃣ Source Multi MA', group = GRMAC, tooltip = 'Normal Line = Close \nSmooth Line = ohlc4')

///////////// EMA/SMA SETTING /////////////
pricestrategy = request.security(syminfo.tickerid, timeframe.period, srcstrategy)
fastSW = input.bool(title='Show Fast MA Line', defval=false, group = GRMAC, inline = '11')
fastcolor = input.color(color.new(color.red,0), group = GRMAC, inline = '110', title = 'Fast MA Color')
slowSW = input.bool(title='Show Slow MA Line', defval=false, group = GRMAC, inline = '11')
slowcolor = input.color(color.new(color.yellow,0), group = GRMAC, inline = '110', title = 'Slow MA Color')
ma1strategy = input(12, title='💯4️⃣ Fast MA Length', group = GRMAC, inline = '12')
type1strategy = input.string('EMA', 'Fast MA Type', options=['SMA', 'EMA', 'WMA', 'HMA', 'RMA', 'VWMA'], group = GRMAC, tooltip = 'SMA / EMA / WMA / HMA / RMA / VWMA', inline = '12')

ma3strategy = input(26, title='💯4️⃣ Slow MA Length', group = GRMAC, inline = '13')
type3strategy = input.string('EMA', 'Slow MA Type', options=['SMA', 'EMA', 'WMA', 'HMA', 'RMA', 'VWMA'], group = GRMAC, tooltip = 'SMA / EMA / WMA / HMA / RMA / VWMA', inline = '13')

price1strategy = switch type1strategy
	"EMA" => ta.ema(pricestrategy, ma1strategy)
	"SMA" => ta.sma(pricestrategy, ma1strategy)
	"WMA" => ta.wma(pricestrategy, ma1strategy)
	"HMA" => ta.hma(pricestrategy, ma1strategy)
	"RMA" => ta.rma(pricestrategy, ma1strategy)
	"VWMA" => ta.vwma(pricestrategy, ma1strategy)
		
price3strategy = switch type3strategy
	"EMA" => ta.ema(pricestrategy, ma3strategy)
	"SMA" => ta.sma(pricestrategy, ma3strategy)
	"WMA" => ta.wma(pricestrategy, ma3strategy)
	"HMA" => ta.hma(pricestrategy, ma3strategy)
	"RMA" => ta.rma(pricestrategy, ma3strategy)
	"VWMA" => ta.vwma(pricestrategy, ma3strategy)

FastL = plot(fastSW ? price1strategy : na, 'Fast MA', color=fastcolor, style = plot.style_line, linewidth=2)
SlowL = plot(slowSW ? price3strategy : na, 'Slow MA', color=slowcolor, style = plot.style_line, linewidth=2)

BullMACross = ta.crossover(price1strategy, price3strategy)
BearMACross = ta.crossunder(price1strategy, price3strategy)

BullMAPlus = price1strategy > price3strategy
BearMAPlus = price1strategy < price3strategy

//********* Background Paint ***********************
prefillFast = plot(fastSW ? price1strategy : na, 'Fast MA', color=color.new(color.red, 100), style = plot.style_line, linewidth=2)
prefillSlow = plot(slowSW ? price3strategy : na, 'Fast MA', color=color.new(color.yellow, 100), style = plot.style_line, linewidth=2)
fcolor = price1strategy > price3strategy ? color.new(color.lime,70) : color.new(color.red,70)
fill(prefillFast,prefillSlow, color=fcolor, title='BACKGROUND PAINT')
// **********************************************


// ==================== DONCHIAN FANS MODE =====================
Donchian_MODE = input.bool(defval = false, title = "DONCHIAN FANS MODE", group = "== DONCHIAN FANS MODE ==")
Donchian_Bollinger = input.bool(defval = false, title = "DONCHIAN BOLLINGER LINE", group = "== DONCHIAN FANS MODE ==")
//  Initiate bars:
var int bd = -1
bd += 1
//----------------------------------------------------------------------------------
//  Required functions:
f_highest_bar(_source, _bars, _length) =>
    float _h_value = _source
    int _h_bar = _bars
    for _i = 0 to math.max(_length - 1, 0) by 1
        bool _isSourceOver = _source[_i] > _h_value
        if _isSourceOver
            _h_value := _source[_i]
            _h_bar := _bars[_i]
            _h_bar
    [_h_value, _h_bar]

f_lowest_bar(_source, _bars, _length) =>
    float _l_value = _source
    int _l_bar = _bars
    for _i = 0 to math.max(_length - 1, 0) by 1
        bool _isSourceUnder = _source[_i] < _l_value
        if _isSourceUnder
            _l_value := _source[_i]
            _l_bar := _bars[_i]
            _l_bar
    [_l_value, _l_bar]

f_line(_x1, _y1, _r, _color) =>
    var line _li = na
    line.delete(id=_li)
    _li := line.new(x1=_x1 - 1, y1=_y1 - _r, x2=_x1, y2=_y1, xloc=xloc.bar_index, extend=extend.right, color=_color, style=line.style_dashed, width=1)
    _li
//----------------------------------------------------------------------------------

int FANSlength = input.int(defval=100, title='FANS length:', minval=1, group = "== DONCHIAN FANS MODE ==")

[h_price, h_bar] = f_highest_bar(high, bd, FANSlength)
[l_price, l_bar] = f_lowest_bar(low, bd, FANSlength)

float mid = (h_price + l_price) / 2

plot(Donchian_Bollinger ? h_price : na, title='H', color=color.new(color.white, 20), linewidth=1, style=plot.style_line)
plot(Donchian_Bollinger ? mid : na, title='M', color=color.new(color.white, 20), linewidth=1, style=plot.style_line)
plot(Donchian_Bollinger ? l_price : na, title='L', color=color.new(color.white, 20), linewidth=1, style=plot.style_line)

var float r = ta.atr(FANSlength)
if ta.change(mid) != 0
    r := ta.atr(FANSlength)
    r

var line h_1_04 = na
var line h_1_08 = na
var line h_1_16 = na
var line h_1_32 = na
var line h_1_64 = na

var line l_1_04 = na
var line l_1_08 = na
var line l_1_16 = na
var line l_1_32 = na
var line l_1_64 = na

bool is_new_h = h_price > h_price[1]
bool is_new_l = l_price < l_price[1]

vhb = ta.valuewhen(high >= h_price, h_bar, 0)
vhp = ta.valuewhen(high >= h_price, h_price, 0)
vlb = ta.valuewhen(low <= l_price, l_bar, 0)
vlp = ta.valuewhen(low <= l_price, l_price, 0)

if is_new_l and Donchian_MODE == true
    h_1_04 := f_line(vhb, vhp, -r * (1. / 04.), color.red)
    h_1_08 := f_line(vhb, vhp, -r * (1. / 08.), color.red)
    h_1_16 := f_line(vhb, vhp, -r * (1. / 16.), color.red)
    h_1_32 := f_line(vhb, vhp, -r * (1. / 32.), color.red)
    h_1_64 := f_line(vhb, vhp, -r * (1. / 64.), color.red)
    h_1_64
if is_new_h and Donchian_MODE == true
    l_1_04 := f_line(vlb, vlp, r * (1. / 04.), color.lime)
    l_1_08 := f_line(vlb, vlp, r * (1. / 08.), color.lime)
    l_1_16 := f_line(vlb, vlp, r * (1. / 16.), color.lime)
    l_1_32 := f_line(vlb, vlp, r * (1. / 32.), color.lime)
    l_1_64 := f_line(vlb, vlp, r * (1. / 64.), color.lime)
    l_1_64

// **********************************************
GRIC = '===💮💮💮 ICHIMOKU SETTING 💮💮💮==='
Ichi_Mode = input.bool(title="ICHIMOKU PLOT MODE", defval=false, group = GRIC)
tenkan_len  = input(9,'💮 Tenkan          ',inline='tenkan', group = GRIC, tooltip = 'TENKAN = FAST SIGNAL')
tenkan_mult = input(2.,'',inline='tenkan', group = GRIC)

kijun_len   = input(26,'💮 Kijun             ',inline='kijun', group = GRIC, tooltip = 'KIJUN = SLOW SIGNAL')
kijun_mult  = input(4.,'',inline='kijun', group = GRIC)

spanB_len   = input(52,'Senkou Span A/B ',inline='span', group = GRIC, tooltip = 'SENKOU = CLOUD SIGNAL')
spanB_mult  = input(6.,'',inline='span', group = GRIC)
cloudacolor = input.color(defval = color.new(color.orange,20), title = 'CLOUD-A', inline='span1', group = GRIC)
cloudbcolor = input.color(defval = color.new(color.purple,20), title = 'CLOUD-B', inline='span1', group = GRIC)

chi_color = input.color(defval = color.new(#73ecff,0), title = "Chikou-Color", group = GRIC, inline = 'CHIKOU')
offset      = input(26,'Chikou', group = GRIC, tooltip = 'CHIKOU = CANDLE LOOK BACK DEFAULT = 26', inline = 'CHIKOU')
//------------------------------------------------------------------------------
avg(src,length,mult)=>
    atr = ta.atr(length)*mult
    up = hl2 + atr
    dn = hl2 - atr
    upper = 0.,lower = 0.
    upper := src[1] < upper[1] ? math.min(up,upper[1]) : up
    lower := src[1] > lower[1] ? math.max(dn,lower[1]) : dn
    
    os = 0,max = 0.,min = 0.
    os := src > upper ? 1 : src < lower ? 0 : os[1]
    spt = os == 1 ? lower : upper
    max := ta.cross(src,spt) ? math.max(src,max[1]) : os == 1 ? math.max(src,max[1]) : spt
    min := ta.cross(src,spt) ? math.min(src,min[1]) : os == 0 ? math.min(src,min[1]) : spt
    math.avg(max,min)
//------------------------------------------------------------------------------
tenkan = avg(close,tenkan_len,tenkan_mult)
kijun = avg(close,kijun_len,kijun_mult)

senkouA = math.avg(kijun,tenkan)
senkouB = avg(close,spanB_len,spanB_mult)
//------------------------------------------------------------------------------
tenkan_css = color.white
kijun_css = #ff5d00

cloud_a = cloudacolor
cloud_b = cloudbcolor

chikou_css = color.new(#73ecff,20)

plot(Ichi_Mode ? tenkan : na,'Tenkan-Sen',tenkan_css,style = plot.style_stepline, linewidth = 2)
plot(Ichi_Mode ? kijun : na,'Kijun-Sen',kijun_css, style = plot.style_stepline, linewidth = 2)

plot(Ichi_Mode ? ta.crossover(tenkan,kijun) ? kijun : na : na,'Crossover',#2157f3,3,plot.style_circles)
plot(Ichi_Mode ? ta.crossunder(tenkan,kijun) ? kijun : na : na,'Crossunder',#ff5d00,3,plot.style_circles)

A = plot(Ichi_Mode ? senkouA : na,'Senkou Span A',na,offset=offset-1)
B = plot(Ichi_Mode ? senkouB : na,'Senkou Span B',na,offset=offset-1)
fill(A,B,senkouA > senkouB ? cloud_a : cloud_b)

ichi_bull = ta.crossover(tenkan,kijun)
ichi_bear = ta.crossunder(tenkan,kijun)

ichi_bullplus = tenkan > kijun
ichi_bearplus = tenkan < kijun
plot(Ichi_Mode ? close : na,'Chikou',chi_color,offset=-offset+1, linewidth = 2)

////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////  
GRCMA = '==🅰️🅰️5️⃣5️⃣ MACD SETTING [PLOT/Confirm]5️⃣5️⃣🅰️🅰️=='
MACDStrategy_MODE = input.bool(title='5️⃣  MACD CROSS [0] STRATEGY MODE', defval=false, group = GRS)
MACDStrategy_Repeat = input.bool(title='5️⃣🎯 MACD CROSS [0] REPEAT MODE', defval=false, group = GRS, tooltip = "Repeat Mode After TP/SL Open Position With Trend Fast >,< Slow Again")
MACD_MODE_SIG= input.bool(title="MACD MODE = MACD Cross Signal", defval=false, group = GRCMA, tooltip = 'If Mode On = Use MACD Strategy for Signal When Cross Up and Cross Down')
//if MACD_MODE_SIG == true
MACDfastLength = input(12, title='🅰️5️⃣ MACD Fast', group = GRCMA, inline = 'MACDSIG1')
MACDslowlength = input(26, title='🅰️5️⃣ MACD Slow', group = GRCMA, inline = 'MACDSIG1')
MACDLength = input(18, title='🅰️5️⃣ MACD Length', group = GRCMA)
macdupcolor = input.color(defval = color.new(color.green,0), title = 'CROSS-UP', inline = 'MACDCO', group = GRCMA)
macddowncolor = input.color(defval = color.new(color.red,0), title = 'CROSS-DOWN', inline = 'MACDCO', group = GRCMA)
MACD = ta.ema(close, MACDfastLength) - ta.ema(close, MACDslowlength)
aMACD = ta.ema(MACD, MACDLength)
delta = MACD - aMACD
macdTPl = (ta.crossover(delta, 0))
macdTPs = (ta.crossunder(delta, 0))
MACDBull = delta > 0
MACDBear = delta < 0
plotshape(MACD_MODE_SIG ? macdTPl : na, title='macdTPl', text = '💎', color=macdupcolor, style=shape.circle, location=location.belowbar, size=size.auto)  //plot for buy icon
plotshape(MACD_MODE_SIG ? macdTPs : na, title='macdTPs', text = '💎', color=macddowncolor, style=shape.circle, location=location.abovebar, size=size.auto)  //plot for buy icon

//=============== TAKE PROFIT and STOP LOSS by % =================

tpsl(percent) =>
    strategy.position_avg_price * percent / 100 / syminfo.mintick
GR4 = "=====🆘🆘🆘 TAKE PROFIT & STOP LOSS BY [%] 🆘🆘🆘====="
mode = input.bool(title="🆘 Take Profit & Stop Loss By Percent (%)", defval=false, group=GRSUB, tooltip = "Take Profit & Stop Loss by % Change")
pnl_mode = input.bool(title="🆘 PNL MODE ($) -->> ", defval=false, group=GRSUB, tooltip = "Take Profit By PNL ($) Ex. 5 = 5$ Then Auto Close Position", inline = "PNL")
pnl_value = input.float(defval = 5, title = "🆘 PNL Value ($)", group = GRSUB, tooltip = "Take Profit By PNL ($) Ex. 5 = 5$ Then Auto Close Position", inline = "PNL")
tp_l = tpsl(input.float(99999, title='🆘 TP [LONG] %', group=GR4))
tp_s = tpsl(input.float(33.3, title='🆘 TP [SHORT] %', group=GR4))
sl = tpsl(input.float(0, title='🆘 Stop Loss %', group=GR4))

current_pnl = strategy.openprofit
pnl_tp = current_pnl >= pnl_value

calcStopLossPrice(OffsetPts) =>
    if strategy.position_size > 0
        strategy.position_avg_price - OffsetPts * syminfo.mintick
    else if strategy.position_size < 0
        strategy.position_avg_price + OffsetPts * syminfo.mintick
    else
        na

calcStopLossL_AlertPrice(OffsetPts) =>
    strategy.position_avg_price - OffsetPts * syminfo.mintick
calcStopLossS_AlertPrice(OffsetPts) =>
    strategy.position_avg_price + OffsetPts * syminfo.mintick

calcTakeProfitPrice(OffsetPts) =>
    if strategy.position_size > 0
        strategy.position_avg_price + OffsetPts * syminfo.mintick
    else if strategy.position_size < 0
        strategy.position_avg_price - OffsetPts * syminfo.mintick
    else
        na

calcTakeProfitL_AlertPrice(OffsetPts) =>
    strategy.position_avg_price + OffsetPts * syminfo.mintick
calcTakeProfitS_AlertPrice(OffsetPts) =>
    strategy.position_avg_price - OffsetPts * syminfo.mintick

var stoploss = 0.
var stoploss_l = 0.
var stoploss_s = 0.
var takeprofit = 0.
var takeprofit_l = 0.
var takeprofit_s = 0.
var takeprofit_ll = 0.
var takeprofit_ss = 0.

GRT = "=====🆑🆑🆑 ATR TRAILING STOP 🆑🆑🆑====="

/////////notes////////////////////////////////////////
// This is based on the ATR trailing stop indicator //
// width addition of two levels of stops and        //
// different interpretation.                        //
// This is a fast-reacting system and is better     //
// suited for higher volatility markets             //
//////////////////////////////////////////////////////
 
// Fast Trail //
AP1 = input.int(5, '🆑 Fast ATR period', group = GRT)  // ATR Period
AF1 = input.float(0.5, '🆑 Fast ATR multiplier', group = GRT)  // ATR Factor
SL1 = AF1 * ta.atr(AP1)  // Stop Loss
Trail1 = 0.0
iff_1 = close > nz(Trail1[1], 0) ? close - SL1 : close + SL1
iff_2 = close < nz(Trail1[1], 0) and close[1] < nz(Trail1[1], 0) ? math.min(nz(Trail1[1], 0), close + SL1) : iff_1
Trail1 := close > nz(Trail1[1], 0) and close[1] > nz(Trail1[1], 0) ? math.max(nz(Trail1[1], 0), close - SL1) : iff_2

// Slow Trail //
AP2 = input.int(10, '🆑 Slow ATR period', group = GRT)  // ATR Period
AF2 = input.float(2, '🆑 Slow ATR multiplier', group = GRT)  // ATR Factor
SL2 = AF2 * ta.atr(AP2)  // Stop Loss
Trail2 = 0.0
iff_3 = close > nz(Trail2[1], 0) ? close - SL2 : close + SL2
iff_4 = close < nz(Trail2[1], 0) and close[1] < nz(Trail2[1], 0) ? math.min(nz(Trail2[1], 0), close + SL2) : iff_3
Trail2 := close > nz(Trail2[1], 0) and close[1] > nz(Trail2[1], 0) ? math.max(nz(Trail2[1], 0), close - SL2) : iff_4

BuyLong = ta.crossover(Trail1, Trail2)
SellShort = ta.crossunder(Trail1, Trail2)

TS1 = plot(plotcolor ? Trail1 : na, 'Fast Trail', style=plot.style_line, color=Trail1 > Trail2 ? color.blue : color.yellow, linewidth=3, display=display.none)
TS2 = plot(plotcolor ? Trail2 : na, 'Slow Trail', style=plot.style_line, color=Trail1 > Trail2 ? color.lime : color.blue, linewidth=3)

if plotcolor == true
    if BuyLong and strategy.position_size < 0
        strategy.close('Short', qty_percent = 100, alert_message = Alert_StopLossshort, comment = "🚨ATR TL🚨")
    if SellShort and strategy.position_size > 0
        strategy.close('Long', qty_percent = 100, alert_message = Alert_StopLosslong, comment = "🚨ATR TL🚨")

GRARO = "===🍩🍩🍩 AROON SETTING 🍩🍩🍩==="
// ######### TRENDLOCK CONFIRM (MACD > 0 and MA FAST > SLOW) ########
AroonConfirm_MODE = input.bool(defval = false, title = "🍩 AROON 100% & -100% CONFIRM", group = GRCON)
lengthAroon = input.int(14, minval=1, title = "AROON LENGTH", group = GRARO)
AroonUpper = 100 * (ta.highestbars(high, lengthAroon) + lengthAroon)/lengthAroon
AroonLower = 100 * (ta.lowestbars(low, lengthAroon) + lengthAroon)/lengthAroon
AroonCrossUp = ta.crossover(AroonUpper, AroonLower)
AroonCrossDown = ta.crossunder(AroonUpper, AroonLower)
AroonHitUp = AroonUpper > AroonLower
AroonHitDown = AroonUpper < AroonLower

GRRSI = "🉐=== RSI MODE ==="
RSI_PLOT = input.bool(defval = false, title = "🉐=== RSI LINE ===", group = GRRSI)
RSI_OB = input.int(defval = 50, title = "🉐 RSI OverBought", minval = 1, maxval = 100, tooltip = "RSI OB", group = GRRSI)
RSI_OS = input.int(defval = 50, title = "🉐 RSI OverSold", minval = 1, maxval = 100, tooltip = "RSI OS", group = GRRSI)
RSI_LENGTH = input.int(defval = 14, title = "RSI LENGTH", minval = 1, maxval = 999, tooltip = "RSI LENGTH", group = GRRSI)
RSI_SMA = input.int(defval = 50, title = "RSI SMA LENGTH", minval = 1, maxval = 999, tooltip = "RSI SMA LENGTH FOR PREDICT TREND", group = GRRSI)
RSI_COL = input.color(defval = color.white, title = "RSI LINE", group = GRRSI, inline = "RSI1")
RSI_SIZE = input.int(defval = 2, title = "SIZE", minval = 0, maxval = 4, tooltip = "Width 0-4", inline = "RSI1", group = GRRSI)
RSI_TRANS = input.int(defval = 0, title = "TRNS", minval = 0, maxval = 100, tooltip = "Transparency 0-100", inline = "RSI1", group = GRRSI)
RSIMA_COL1 = input.color(defval = color.blue, title = "RSIMA LINE", group = GRRSI, inline = "RSI2")
RSIMA_COL2 = input.color(defval = color.teal, title = "", group = GRRSI, inline = "RSI2")
RSIMA_SIZE = input.int(defval = 3, title = "SIZE", minval = 0, maxval = 4, tooltip = "Width 0-4", inline = "RSI2", group = GRRSI)
RSIMA_TRANS = input.int(defval = 0, title = "TRNS", minval = 0, maxval = 100, tooltip = "Transparency 0-100", inline = "RSI2", group = GRRSI)
up = ta.rma(math.max(ta.change(close), 0), RSI_LENGTH)
down = ta.rma(-math.min(ta.change(close), 0), RSI_LENGTH)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
vrsi = ta.rsi(close, RSI_LENGTH)
RSIUP = ta.crossover(vrsi, RSI_OB)
RSIDOWN = ta.crossunder(vrsi, RSI_OS)
rsiMA = ta.sma(rsi, RSI_SMA)
RSIBULL = ta.crossover(rsi, rsiMA)
RSIBEAR = ta.crossunder(rsi, rsiMA)
BULLRSI = rsi <= RSI_OB
BEARRSI = rsi >= RSI_OS
RSIc1 = rsi > rsiMA ? color.new(RSIMA_COL1, RSIMA_TRANS) : color.new(RSIMA_COL2, RSIMA_TRANS)
plotshape(RSI_PLOT ? RSIUP : na, title='RSIUP', text = 'OB', color=color.new(color.yellow, 100), style=shape.circle, location=location.belowbar, size=size.auto)  //plot for buy icon
plotshape(RSI_PLOT ? RSIDOWN : na, title='RSIDOWN', text = 'OS', color=color.new(color.red, 100), style=shape.circle, location=location.abovebar, size=size.auto)  //plot for buy icon
plot(RSI_PLOT ? rsi : na, title = "RSI", color = color.new(RSI_COL,RSI_TRANS), linewidth = RSI_SIZE, style = plot.style_line)
plot(RSI_PLOT ? rsiMA : na, title = "RSI-based MA", color=RSIc1, linewidth = RSIMA_SIZE, style = plot.style_line)

Disable_Confirm = MACDConfirm_MODE == false and RSIConfirm_MODE == false and MACross_MODE == false and IchiConfirm_MODE == false and AroonConfirm_MODE == false

//////////// INPUT BACKTEST RANGE ////////////////////////////////////////////////////
var string BTR1         = '════════ INPUT BACKTEST TIME RANGE ════════'
i_startTime             = input.time(defval = timestamp("01 Jan 1945 00:00 +0000"), title = "Start", inline="timestart", group=BTR1, tooltip = 'Start Backtest YYYY/MM/DD')
i_endTime               = input.time(defval = timestamp("01 Jan 2074 23:59 +0000"), title = "End", inline="timeend", group=BTR1, tooltip = 'End Backtest YYYY/MM/DD')
// Define the trading time range
startHour = input.int(defval = 0, title = "⌛⌛ Start Trade , O Clock", group = GRCON, inline = "Start01")
startMinute = input.int(defval = 0, title = "Minute ", group = GRCON, inline = "Start01")
endHour = input.int(defval = 23, title = "⌛⌛ Stop Trade , O Clock", group = GRCON, inline = "Stop01")
endMinute = input.int(defval = 59, title = "Minute ", group = GRCON, inline = "Stop01")

// Convert the trading time range to seconds
startSeconds = (startHour * 60 + startMinute) * 60
endSeconds = (endHour * 60 + endMinute) * 60

// Check if the current time is within the specified range
isTradingTime = time >= timestamp(year, month, dayofmonth, startHour, startMinute) and time <= timestamp(year, month, dayofmonth, endHour, endMinute)
if time >= i_startTime and time <= i_endTime and isTradingTime
    // ##### BreakOut Strategy ######
    if Spot_MODE == false
        if MACDConfirm_MODE == true
            if BreakOut_MODE == true
                if not na(close[lengthBO]) and MACDBull
                	strategy.entry("Long", strategy.long, stop=upBound + syminfo.mintick, comment="Break🌙MACD", alert_message = Alert_OpenLong)
                if MACDBear
                    strategy.entry("Short", strategy.short, stop=downBound - syminfo.mintick, comment="Break👻MACD", alert_message = Alert_OpenShort)
            // ##### Consecutive Strategy #######
            if (Consecutive_MODE ? ups >= consecutiveBarsUp : na) and MACDBull
            	strategy.entry("Long", strategy.long, comment="Up🌙MACD", alert_message = Alert_OpenLong)
            if (Consecutive_MODE ? dns >= consecutiveBarsDown : na) and MACDBear
            	strategy.entry("Short", strategy.short, comment="Down👻MACD", alert_message = Alert_OpenShort)
            // ##### 15m Strategy ######
            if (longCondition15) and MACDBull
                strategy.entry("Long", strategy.long, alert_message = Alert_OpenLong, comment = "15m🌙MACD")
                alert("15m BREAK UP", freq = alert.freq_once_per_bar_close)
            if (shortCondition15) and MACDBear
                strategy.close_all("15m BREAK DOWN", immediately = true, alert_message = Alert_StopLosslong)
                alert("15m BREAK DOWN", freq = alert.freq_once_per_bar_close)
            if MAStrategy_MODE == true and MARepeat_Mode == false
                if BullMACross and MACDBull
                	strategy.entry("Long", strategy.long, comment="X🌙MACD", alert_message = Alert_OpenLong)
                if BearMACross and MACDBear
                    strategy.entry("Short", strategy.short, comment="X👻MACD", alert_message = Alert_OpenShort)
            if (MAStrategy_MODE == true and MARepeat_Mode == true) or (MAStrategy_MODE == false and MARepeat_Mode == true)
                if BullMAPlus and MACDBull
                	strategy.entry("Long", strategy.long, comment="X-Re🌙MACD", alert_message = Alert_OpenLong)
                if BearMAPlus and MACDBear
                    strategy.entry("Short", strategy.short, comment="X-Re👻MACD", alert_message = Alert_OpenShort)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == false
                if macdTPl
                	strategy.entry("Long", strategy.long, comment="MACD🌙X", alert_message = Alert_OpenLong)
                if macdTPs
                    strategy.entry("Short", strategy.short, comment="MACD👻X", alert_message = Alert_OpenShort)
            if (MACDStrategy_MODE == true and MACDStrategy_Repeat == true)
                if MACDBull or macdTPl
                	strategy.entry("Long", strategy.long, comment="MACD🌙X", alert_message = Alert_OpenLong)
                if MACDBear or macdTPs
                    strategy.entry("Short", strategy.short, comment="MACD👻X", alert_message = Alert_OpenShort)
            if (MACDStrategy_MODE == false and MACDStrategy_Repeat == true)
                if MACDBull
                	strategy.entry("Long", strategy.long, comment="MACD🌙X", alert_message = Alert_OpenLong)
                if MACDBear
                    strategy.entry("Short", strategy.short, comment="MACD👻X", alert_message = Alert_OpenShort)
        if RSIConfirm_MODE == true
            if BreakOut_MODE == true
                if not na(close[lengthBO]) and BULLRSI
                	strategy.entry("Long", strategy.long, stop=upBound + syminfo.mintick, comment="Break🌙RSI", alert_message = Alert_OpenLong)
                if BEARRSI
                    strategy.entry("Short", strategy.short, stop=downBound - syminfo.mintick, comment="Break👻RSI", alert_message = Alert_OpenShort)
            // ##### Consecutive Strategy #######
            if (Consecutive_MODE ? ups >= consecutiveBarsUp : na) and BULLRSI
            	strategy.entry("Long", strategy.long, comment="Up🌙RSI", alert_message = Alert_OpenLong)
            if (Consecutive_MODE ? dns >= consecutiveBarsDown : na) and BEARRSI
            	strategy.entry("Short", strategy.short, comment="Down👻RSI", alert_message = Alert_OpenShort)
            // ##### 15m Strategy ######
            if (longCondition15) and BULLRSI
                strategy.entry("Long", strategy.long, alert_message = Alert_OpenLong, comment = "15m🌙RSI")
                alert("15m BREAK UP", freq = alert.freq_once_per_bar_close)
            if (shortCondition15) and BEARRSI
                strategy.close_all("15m BREAK DOWN", immediately = true, alert_message = Alert_StopLosslong)
                alert("15m BREAK DOWN", freq = alert.freq_once_per_bar_close)
            if MAStrategy_MODE == true and MARepeat_Mode == false
                if BullMAPlus and BULLRSI
                	strategy.entry("Long", strategy.long, comment="X🌙RSI", alert_message = Alert_OpenLong)
                if BearMAPlus and BEARRSI
                    strategy.entry("Short", strategy.short, comment="X👻RSI", alert_message = Alert_OpenShort)
            if (MAStrategy_MODE == true and MARepeat_Mode == true) or (MAStrategy_MODE == false and MARepeat_Mode == true)
                if BullMAPlus and BULLRSI
                	strategy.entry("Long", strategy.long, comment="X-Re🌙RSI", alert_message = Alert_OpenLong)
                if BearMAPlus and BEARRSI
                    strategy.entry("Short", strategy.short, comment="X-Re👻RSI", alert_message = Alert_OpenShort)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == false
                if macdTPl and BULLRSI
                	strategy.entry("Long", strategy.long, comment="MACD🌙RSI", alert_message = Alert_OpenLong)
                if macdTPs and BEARRSI
                    strategy.entry("Short", strategy.short, comment="MACD👻RSI", alert_message = Alert_OpenShort)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == true
                if (MACDBull and BULLRSI) or (macdTPl and BULLRSI)
                	strategy.entry("Long", strategy.long, comment="MACD🌙RSI", alert_message = Alert_OpenLong)
                if (MACDBear and BEARRSI) or (macdTPs and BEARRSI)
                    strategy.entry("Short", strategy.short, comment="MACD👻RSI", alert_message = Alert_OpenShort)
            if MACDStrategy_MODE == false and MACDStrategy_Repeat == true
                if MACDBull and BULLRSI
                	strategy.entry("Long", strategy.long, comment="MACD🌙RSI", alert_message = Alert_OpenLong)
                if MACDBear and BEARRSI
                    strategy.entry("Short", strategy.short, comment="MACD👻RSI", alert_message = Alert_OpenShort)
        if MACross_MODE == true
            if BreakOut_MODE == true
                if not na(close[lengthBO]) and BullMAPlus
                	strategy.entry("Long", strategy.long, stop=upBound + syminfo.mintick, comment="Break🌙MA", alert_message = Alert_OpenLong)
                if BearMAPlus
                    strategy.entry("Short", strategy.short, stop=downBound - syminfo.mintick, comment="Break👻MA", alert_message = Alert_OpenShort)
            // ##### Consecutive Strategy #######
            if (Consecutive_MODE ? ups >= consecutiveBarsUp : na) and BullMAPlus
            	strategy.entry("Long", strategy.long, comment="Up🌙MA", alert_message = Alert_OpenLong)
            if (Consecutive_MODE ? dns >= consecutiveBarsDown : na) and BearMAPlus
            	strategy.entry("Short", strategy.short, comment="Down👻MA", alert_message = Alert_OpenShort)
            // ##### 15m Strategy ######
            if (longCondition15) and BullMAPlus
                strategy.entry("Long", strategy.long, alert_message = Alert_OpenLong, comment = "15m🌙MA")
                alert("15m BREAK UP", freq = alert.freq_once_per_bar_close)
            if (shortCondition15) and BearMAPlus
                strategy.close_all("15m BREAK DOWN", immediately = true, alert_message = Alert_StopLosslong)
                alert("15m BREAK DOWN", freq = alert.freq_once_per_bar_close)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == true
                if (macdTPl and BullMAPlus) or (MACDBull and BullMAPlus)
                	strategy.entry("Long", strategy.long, comment="MACD🌙MA", alert_message = Alert_OpenLong)
                if (macdTPs and BearMAPlus) or (MACDBear and BearMAPlus)
                    strategy.entry("Short", strategy.short, comment="MACD👻MA", alert_message = Alert_OpenShort)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == false
                if (macdTPl and BullMAPlus)
                	strategy.entry("Long", strategy.long, comment="MACD🌙MA", alert_message = Alert_OpenLong)
                if (macdTPs and BearMAPlus)
                    strategy.entry("Short", strategy.short, comment="MACD👻MA", alert_message = Alert_OpenShort)
            if MACDStrategy_MODE == false and MACDStrategy_Repeat == true
                if (MACDBull and BullMAPlus)
                	strategy.entry("Long", strategy.long, comment="MACD🌙MA", alert_message = Alert_OpenLong)
                if (MACDBear and BearMAPlus)
                    strategy.entry("Short", strategy.short, comment="MACD👻MA", alert_message = Alert_OpenShort)
            if MAStrategy_MODE == true and MARepeat_Mode == false
                if BullMACross
                	strategy.entry("Long", strategy.long, comment="X🌙", alert_message = Alert_OpenLong)
                if BearMACross
                    strategy.entry("Short", strategy.short, comment="X👻", alert_message = Alert_OpenShort)
            if (MAStrategy_MODE == true and MARepeat_Mode == true) or (MAStrategy_MODE == false and MARepeat_Mode == true)
                if BullMAPlus
                	strategy.entry("Long", strategy.long, comment="X-Re🌙", alert_message = Alert_OpenLong)
                if BearMAPlus
                    strategy.entry("Short", strategy.short, comment="X-Re👻", alert_message = Alert_OpenShort)
        if IchiConfirm_MODE == true
            if BreakOut_MODE == true
                if not na(close[lengthBO]) and ichi_bullplus
                	strategy.entry("Long", strategy.long, stop=upBound + syminfo.mintick, comment="Break🌙ICHI", alert_message = Alert_OpenLong)
                if ichi_bearplus
                    strategy.entry("Short", strategy.short, stop=downBound - syminfo.mintick, comment="Break👻ICHI", alert_message = Alert_OpenShort)
            // ##### Consecutive Strategy #######
            if (Consecutive_MODE ? ups >= consecutiveBarsUp : na) and ichi_bullplus
            	strategy.entry("Long", strategy.long, comment="Up🌙ICHI", alert_message = Alert_OpenLong)
            if (Consecutive_MODE ? dns >= consecutiveBarsDown : na) and ichi_bearplus
            	strategy.entry("Short", strategy.short, comment="Down👻ICHI", alert_message = Alert_OpenShort)
            // ##### 15m Strategy ######
            if (longCondition15) and ichi_bullplus
                strategy.entry("Long", strategy.long, alert_message = Alert_OpenLong, comment = "15m🌙ICHI")
                alert("15m BREAK UP", freq = alert.freq_once_per_bar_close)
            if (shortCondition15) and ichi_bearplus
                strategy.close_all("15m BREAK DOWN", immediately = true, alert_message = Alert_StopLosslong)
                alert("15m BREAK DOWN", freq = alert.freq_once_per_bar_close)
            if MAStrategy_MODE == true and MARepeat_Mode == false
                if BullMACross and ichi_bullplus
                	strategy.entry("Long", strategy.long, comment="X🌙ICHI", alert_message = Alert_OpenLong)
                if BearMACross and ichi_bearplus
                    strategy.entry("Short", strategy.short, comment="X👻ICHI", alert_message = Alert_OpenShort)
            if (MAStrategy_MODE == true and MARepeat_Mode == true) or (MAStrategy_MODE == false and MARepeat_Mode == true)
                if BullMAPlus and ichi_bullplus
                	strategy.entry("Long", strategy.long, comment="X-Re🌙ICHI", alert_message = Alert_OpenLong)
                if BearMAPlus and ichi_bearplus
                    strategy.entry("Short", strategy.short, comment="X-Re👻ICHI", alert_message = Alert_OpenShort)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == true
                if (macdTPl and ichi_bullplus) or (MACDBull and ichi_bullplus)
                	strategy.entry("Long", strategy.long, comment="MACD🌙ICHI", alert_message = Alert_OpenLong)
                if (macdTPs and ichi_bearplus) or (MACDBear and ichi_bearplus)
                    strategy.entry("Short", strategy.short, comment="MACD👻ICHI", alert_message = Alert_OpenShort)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == false
                if (macdTPl and ichi_bullplus)
                	strategy.entry("Long", strategy.long, comment="MACD🌙ICHI", alert_message = Alert_OpenLong)
                if (macdTPs and ichi_bearplus)
                    strategy.entry("Short", strategy.short, comment="MACD👻ICHI", alert_message = Alert_OpenShort)
            if MACDStrategy_MODE == false and MACDStrategy_Repeat == true
                if (MACDBull and ichi_bullplus)
                	strategy.entry("Long", strategy.long, comment="MACD🌙ICHI", alert_message = Alert_OpenLong)
                if (MACDBear and ichi_bearplus)
                    strategy.entry("Short", strategy.short, comment="MACD👻ICHI", alert_message = Alert_OpenShort)
        if AroonConfirm_MODE == true
            if BreakOut_MODE == true
                if not na(close[lengthBO]) and AroonHitUp
                	strategy.entry("Long", strategy.long, stop=upBound + syminfo.mintick, comment="Break🌙AR", alert_message = Alert_OpenLong)
                if AroonHitDown
                    strategy.entry("Short", strategy.short, stop=downBound - syminfo.mintick, comment="Break👻AR", alert_message = Alert_OpenShort)
            // ##### Consecutive Strategy #######
            if (Consecutive_MODE ? ups >= consecutiveBarsUp : na) and AroonHitUp
            	strategy.entry("Long", strategy.long, comment="Up🌙AR", alert_message = Alert_OpenLong)
            if (Consecutive_MODE ? dns >= consecutiveBarsDown : na) and AroonHitDown
            	strategy.entry("Short", strategy.short, comment="Down👻AR", alert_message = Alert_OpenShort)
            // ##### 15m Strategy ######
            if (longCondition15) and AroonHitUp
                strategy.entry("Long", strategy.long, alert_message = Alert_OpenLong, comment = "15m🌙AR")
                alert("15m BREAK UP", freq = alert.freq_once_per_bar_close)
            if (shortCondition15) and AroonHitDown
                strategy.close_all("15m BREAK DOWN", immediately = true, alert_message = Alert_StopLosslong)
                alert("15m BREAK DOWN", freq = alert.freq_once_per_bar_close)
            if MAStrategy_MODE == true and MARepeat_Mode == false
                if BullMACross and AroonHitUp
                	strategy.entry("Long", strategy.long, comment="X🌙AR", alert_message = Alert_OpenLong)
                if BearMACross and AroonHitDown
                    strategy.entry("Short", strategy.short, comment="X👻AR", alert_message = Alert_OpenShort)
            if (MAStrategy_MODE == true and MARepeat_Mode == true) or (MAStrategy_MODE == false and MARepeat_Mode == true)
                if BullMAPlus and AroonHitUp
                	strategy.entry("Long", strategy.long, comment="X-Re🌙AR", alert_message = Alert_OpenLong)
                if BearMAPlus and AroonHitDown
                    strategy.entry("Short", strategy.short, comment="X-Re👻AR", alert_message = Alert_OpenShort)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == false
                if macdTPl and AroonHitUp
                	strategy.entry("Long", strategy.long, comment="MACD🌙AR", alert_message = Alert_OpenLong)
                if macdTPs and AroonHitDown
                    strategy.entry("Short", strategy.short, comment="MACD👻AR", alert_message = Alert_OpenShort)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == true
                if (macdTPl and AroonHitUp) or (MACDBull and AroonHitUp)
                	strategy.entry("Long", strategy.long, comment="MACD🌙AR", alert_message = Alert_OpenLong)
                if (macdTPs and AroonHitDown) or (MACDBear and AroonHitDown)
                    strategy.entry("Short", strategy.short, comment="MACD👻AR", alert_message = Alert_OpenShort)
            if MACDStrategy_MODE == false and MACDStrategy_Repeat == true
                if (MACDBull and AroonHitUp)
                	strategy.entry("Long", strategy.long, comment="MACD🌙AR", alert_message = Alert_OpenLong)
                if (MACDBear and AroonHitDown)
                    strategy.entry("Short", strategy.short, comment="MACD👻AR", alert_message = Alert_OpenShort)
        if MACDConfirm_MODE == false and RSIConfirm_MODE == false and MACross_MODE == false and IchiConfirm_MODE == false and AroonConfirm_MODE == false
            if BreakOut_MODE == true
                if not na(close[lengthBO])
                	strategy.entry("Long", strategy.long, stop=upBound + syminfo.mintick, comment="Break🌙", alert_message = Alert_OpenLong)
                strategy.entry("Short", strategy.short, stop=downBound - syminfo.mintick, comment="Break👻", alert_message = Alert_OpenShort)
            // ##### Consecutive Strategy #######
            if (Consecutive_MODE ? ups >= consecutiveBarsUp : na)
            	strategy.entry("Long", strategy.long, comment="Up🌙", alert_message = Alert_OpenLong)
            if (Consecutive_MODE ? dns >= consecutiveBarsDown : na)
            	strategy.entry("Short", strategy.short, comment="Down👻", alert_message = Alert_OpenShort)
            // ##### 15m Strategy ######
            if (longCondition15)
                strategy.entry("Long", strategy.long, alert_message = Alert_OpenLong)
                alert("15m BREAK UP", freq = alert.freq_once_per_bar_close)
            if (shortCondition15)
                strategy.close_all("15m BREAK DOWN", immediately = true, alert_message = Alert_StopLosslong)
                alert("15m BREAK DOWN", freq = alert.freq_once_per_bar_close)
            if MAStrategy_MODE == true and MARepeat_Mode == false
                if BullMACross
                	strategy.entry("Long", strategy.long, comment="X🌙", alert_message = Alert_OpenLong)
                if BearMACross
                    strategy.entry("Short", strategy.short, comment="X👻", alert_message = Alert_OpenShort)
            if (MAStrategy_MODE == true and MARepeat_Mode == true) or (MAStrategy_MODE == false and MARepeat_Mode == true)
                if BullMAPlus
                	strategy.entry("Long", strategy.long, comment="X-Re🌙", alert_message = Alert_OpenLong)
                if BearMAPlus
                    strategy.entry("Short", strategy.short, comment="X-Re👻", alert_message = Alert_OpenShort)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == false
                if macdTPl
                	strategy.entry("Long", strategy.long, comment="MACD🌙X", alert_message = Alert_OpenLong)
                if macdTPs
                    strategy.entry("Short", strategy.short, comment="MACD👻X", alert_message = Alert_OpenShort)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == true
                if macdTPl or MACDBull
                	strategy.entry("Long", strategy.long, comment="MACD🌙X", alert_message = Alert_OpenLong)
                if macdTPs or MACDBear
                    strategy.entry("Short", strategy.short, comment="MACD👻X", alert_message = Alert_OpenShort)
            if MACDStrategy_MODE == false and MACDStrategy_Repeat == true
                if MACDBull
                	strategy.entry("Long", strategy.long, comment="MACD🌙X", alert_message = Alert_OpenLong)
                if MACDBear
                    strategy.entry("Short", strategy.short, comment="MACD👻X", alert_message = Alert_OpenShort)
    else if Spot_MODE == true
        if MACDConfirm_MODE == true
            if BreakOut_MODE == true
                if not na(close[lengthBO]) and MACDBull
                	strategy.entry("Long", strategy.long, stop=upBound + syminfo.mintick, comment="Break🌙MACD", alert_message = Alert_OpenLong)
                if MACDBear
                    strategy.close_all(immediately = true, comment="Break👻MACD", alert_message = Alert_StopLosslong)
            // ##### Consecutive Strategy #######
            if (Consecutive_MODE ? ups >= consecutiveBarsUp : na) and MACDBull
            	strategy.entry("Long", strategy.long, comment="Up🌙MACD", alert_message = Alert_OpenLong)
            if (Consecutive_MODE ? dns >= consecutiveBarsDown : na) and MACDBear
            	strategy.close_all(immediately = true, comment="Down👻MACD", alert_message = Alert_StopLosslong)
            // ##### 15m Strategy ######
            if (longCondition15) and MACDBull
                strategy.entry("Long", strategy.long, alert_message = Alert_OpenLong, comment = "15m🌙MACD")
                alert("15m BREAK UP", freq = alert.freq_once_per_bar_close)
            if (shortCondition15) and MACDBear
                strategy.close_all("15m BREAK DOWN", immediately = true, alert_message = Alert_StopLosslong)
                alert("15m BREAK DOWN", freq = alert.freq_once_per_bar_close)
            if MAStrategy_MODE == true and MARepeat_Mode == false
                if BullMACross and MACDBull
                	strategy.entry("Long", strategy.long, comment="X🌙MACD", alert_message = Alert_OpenLong)
                if BearMACross and MACDBear
                    strategy.close_all(immediately = true, comment="X👻MACD", alert_message = Alert_StopLosslong)
            if (MAStrategy_MODE == true and MARepeat_Mode == true) or (MAStrategy_MODE == false and MARepeat_Mode == true)
                if BullMAPlus and MACDBull
                	strategy.entry("Long", strategy.long, comment="X-Re🌙MACD", alert_message = Alert_OpenLong)
                if BearMAPlus and MACDBear
                    strategy.close_all(immediately = true, comment="X👻MACD", alert_message = Alert_StopLosslong)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == false
                if macdTPl
                	strategy.entry("Long", strategy.long, comment="MACD🌙X", alert_message = Alert_OpenLong)
                if macdTPs
                    strategy.close_all(immediately = true, comment="MACD👻X", alert_message = Alert_StopLosslong)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == true
                if macdTPl or MACDBull
                	strategy.entry("Long", strategy.long, comment="MACD🌙X", alert_message = Alert_OpenLong)
                if macdTPs or MACDBear
                    strategy.close_all(immediately = true, comment="MACD👻X", alert_message = Alert_StopLosslong)
            if MACDStrategy_MODE == false and MACDStrategy_Repeat == true
                if MACDBull
                	strategy.entry("Long", strategy.long, comment="MACD🌙X", alert_message = Alert_OpenLong)
                if MACDBear
                    strategy.close_all(immediately = true, comment="MACD👻X", alert_message = Alert_StopLosslong)
        if RSIConfirm_MODE == true
            if BreakOut_MODE == true
                if not na(close[lengthBO]) and BULLRSI
                	strategy.entry("Long", strategy.long, stop=upBound + syminfo.mintick, comment="Break🌙RSI", alert_message = Alert_OpenLong)
                if BEARRSI
                    strategy.close_all(immediately = true, comment="Break👻RSI", alert_message = Alert_StopLosslong)
            // ##### Consecutive Strategy #######
            if (Consecutive_MODE ? ups >= consecutiveBarsUp : na) and BULLRSI
            	strategy.entry("Long", strategy.long, comment="Up🌙RSI", alert_message = Alert_OpenLong)
            if (Consecutive_MODE ? dns >= consecutiveBarsDown : na) and BEARRSI
            	strategy.close_all(immediately = true, comment="Down👻RSI", alert_message = Alert_StopLosslong)
            // ##### 15m Strategy ######
            if (longCondition15) and BULLRSI
                strategy.entry("Long", strategy.long, alert_message = Alert_OpenLong, comment = "15m🌙RSI")
                alert("15m BREAK UP", freq = alert.freq_once_per_bar_close)
            if (shortCondition15) and BEARRSI
                strategy.close_all("15m BREAK DOWN", immediately = true, alert_message = Alert_StopLosslong)
                alert("15m BREAK DOWN", freq = alert.freq_once_per_bar_close)
            if MAStrategy_MODE == true and MARepeat_Mode == false
                if BullMACross and BULLRSI
                	strategy.entry("Long", strategy.long, comment="X🌙RSI", alert_message = Alert_OpenLong)
                if BearMACross and BEARRSI
                    strategy.close_all(immediately = true, comment="X👻RSI", alert_message = Alert_StopLosslong)
            if (MAStrategy_MODE == true and MARepeat_Mode == true) or (MAStrategy_MODE == false and MARepeat_Mode == true)
                if BullMAPlus and BULLRSI
                	strategy.entry("Long", strategy.long, comment="X-Re🌙RSI", alert_message = Alert_OpenLong)
                if BearMAPlus and BEARRSI
                    strategy.close_all(immediately = true, comment="X👻RSI", alert_message = Alert_StopLosslong)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == false
                if macdTPl and BULLRSI
                	strategy.entry("Long", strategy.long, comment="MACD🌙RSI", alert_message = Alert_OpenLong)
                if macdTPs and BEARRSI
                    strategy.close_all(immediately = true, comment="MACD👻RSI", alert_message = Alert_StopLosslong)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == true
                if (macdTPl and BULLRSI) or (MACDBull and BULLRSI)
                	strategy.entry("Long", strategy.long, comment="MACD🌙RSI", alert_message = Alert_OpenLong)
                if (macdTPs and BEARRSI) or (MACDBear and BEARRSI)
                    strategy.close_all(immediately = true, comment="MACD👻RSI", alert_message = Alert_StopLosslong)
            if MACDStrategy_MODE == false and MACDStrategy_Repeat == true
                if (MACDBull and BULLRSI)
                	strategy.entry("Long", strategy.long, comment="MACD🌙RSI", alert_message = Alert_OpenLong)
                if (MACDBear and BEARRSI)
                    strategy.close_all(immediately = true, comment="MACD👻RSI", alert_message = Alert_StopLosslong)
        if MACross_MODE == true
            if BreakOut_MODE == true
                if not na(close[lengthBO]) and BullMAPlus
                	strategy.entry("Long", strategy.long, stop=upBound + syminfo.mintick, comment="Break🌙MA", alert_message = Alert_OpenLong)
                if BearMAPlus
                    strategy.close_all(immediately = true, comment="Break👻MA", alert_message = Alert_StopLosslong)
            // ##### Consecutive Strategy #######
            if (Consecutive_MODE ? ups >= consecutiveBarsUp : na) and BullMAPlus
            	strategy.entry("Long", strategy.long, comment="Up🌙MA", alert_message = Alert_OpenLong)
            if (Consecutive_MODE ? dns >= consecutiveBarsDown : na) and BearMAPlus
            	strategy.close_all(immediately = true, comment="Down👻MA", alert_message = Alert_StopLosslong)
            // ##### 15m Strategy ######
            if (longCondition15) and BullMAPlus
                strategy.entry("Long", strategy.long, alert_message = Alert_OpenLong, comment = "15m🌙MA")
                alert("15m BREAK UP", freq = alert.freq_once_per_bar_close)
            if (shortCondition15) and BearMAPlus
                strategy.close_all("15m BREAK DOWN", immediately = true, alert_message = Alert_StopLosslong)
                alert("15m BREAK DOWN", freq = alert.freq_once_per_bar_close)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == false
                if macdTPl and BullMAPlus
                	strategy.entry("Long", strategy.long, comment="MACD🌙MA", alert_message = Alert_OpenLong)
                if macdTPs and BearMAPlus
                    strategy.close_all(immediately = true, comment="MACD👻MA", alert_message = Alert_StopLosslong)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == true
                if (macdTPl and BullMAPlus) or (MACDBull and BullMAPlus)
                	strategy.entry("Long", strategy.long, comment="MACD🌙MA", alert_message = Alert_OpenLong)
                if (macdTPs and BearMAPlus) or (MACDBear and BearMAPlus)
                    strategy.close_all(immediately = true, comment="MACD👻MA", alert_message = Alert_StopLosslong)
            if MACDStrategy_MODE == false and MACDStrategy_Repeat == true
                if (MACDBull and BullMAPlus)
                	strategy.entry("Long", strategy.long, comment="MACD🌙MA", alert_message = Alert_OpenLong)
                if (MACDBear and BearMAPlus)
                    strategy.close_all(immediately = true, comment="MACD👻MA", alert_message = Alert_StopLosslong)
            if MAStrategy_MODE == true and MARepeat_Mode == false
                if BullMACross
                	strategy.entry("Long", strategy.long, comment="X🌙MA", alert_message = Alert_OpenLong)
                if BearMACross
                    strategy.close_all(immediately = true, comment="X👻MA", alert_message = Alert_StopLosslong)
            if (MAStrategy_MODE == true and MARepeat_Mode == true) or (MAStrategy_MODE == false and MARepeat_Mode == true)
                if BullMAPlus
                	strategy.entry("Long", strategy.long, comment="X-Re🌙MA", alert_message = Alert_OpenLong)
                if BearMAPlus
                    strategy.close_all(immediately = true, comment="X👻MA", alert_message = Alert_StopLosslong)
        if IchiConfirm_MODE == true
            if BreakOut_MODE == true
                if not na(close[lengthBO]) and ichi_bullplus
                	strategy.entry("Long", strategy.long, stop=upBound + syminfo.mintick, comment="Break🌙ICHI", alert_message = Alert_OpenLong)
                if ichi_bearplus
                    strategy.close_all(immediately = true, comment="Break👻ICHI", alert_message = Alert_StopLosslong)
            // ##### Consecutive Strategy #######
            if (Consecutive_MODE ? ups >= consecutiveBarsUp : na) and ichi_bullplus
            	strategy.entry("Long", strategy.long, comment="Up🌙ICHI", alert_message = Alert_OpenLong)
            if (Consecutive_MODE ? dns >= consecutiveBarsDown : na) and ichi_bearplus
            	strategy.close_all(immediately = true, comment="Down👻ICHI", alert_message = Alert_StopLosslong)
            // ##### 15m Strategy ######
            if (longCondition15) and ichi_bullplus
                strategy.entry("Long", strategy.long, alert_message = Alert_OpenLong, comment = "15m🌙ICHI")
                alert("15m BREAK UP", freq = alert.freq_once_per_bar_close)
            if (shortCondition15) and ichi_bearplus
                strategy.close_all("15m BREAK DOWN", immediately = true, alert_message = Alert_StopLosslong)
                alert("15m BREAK DOWN", freq = alert.freq_once_per_bar_close)
            if MAStrategy_MODE == true and MARepeat_Mode == false
                if BullMACross and ichi_bullplus
                	strategy.entry("Long", strategy.long, comment="X🌙ICHI", alert_message = Alert_OpenLong)
                if BearMACross and ichi_bearplus
                    strategy.close_all(immediately = true, comment="X👻ICHI", alert_message = Alert_StopLosslong)
            if (MAStrategy_MODE == true and MARepeat_Mode == true) or (MAStrategy_MODE == false and MARepeat_Mode == true)
                if BullMAPlus and ichi_bullplus
                	strategy.entry("Long", strategy.long, comment="X-Re🌙ICHI", alert_message = Alert_OpenLong)
                if BearMAPlus and ichi_bearplus
                    strategy.close_all(immediately = true, comment="X👻ICHI", alert_message = Alert_StopLosslong)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == false
                if macdTPl and ichi_bullplus
                	strategy.entry("Long", strategy.long, comment="MACD🌙ICHI", alert_message = Alert_OpenLong)
                if macdTPs and ichi_bearplus
                    strategy.close_all(immediately = true, comment="MACD👻ICHI", alert_message = Alert_StopLosslong)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == true
                if (macdTPl and ichi_bullplus) or (MACDBull and ichi_bullplus)
                	strategy.entry("Long", strategy.long, comment="MACD🌙ICHI", alert_message = Alert_OpenLong)
                if (macdTPs and ichi_bearplus) or (MACDBear and ichi_bearplus)
                    strategy.close_all(immediately = true, comment="MACD👻ICHI", alert_message = Alert_StopLosslong)
            if MACDStrategy_MODE == false and MACDStrategy_Repeat == true
                if (MACDBull and ichi_bullplus)
                	strategy.entry("Long", strategy.long, comment="MACD🌙ICHI", alert_message = Alert_OpenLong)
                if (MACDBear and ichi_bearplus)
                    strategy.close_all(immediately = true, comment="MACD👻ICHI", alert_message = Alert_StopLosslong)
        if AroonConfirm_MODE == true
            if BreakOut_MODE == true
                if not na(close[lengthBO]) and AroonHitUp
                	strategy.entry("Long", strategy.long, stop=upBound + syminfo.mintick, comment="Break🌙AR", alert_message = Alert_OpenLong)
                if AroonHitDown
                    strategy.close_all(immediately = true, comment="Break👻AR", alert_message = Alert_StopLosslong)
            // ##### Consecutive Strategy #######
            if (Consecutive_MODE ? ups >= consecutiveBarsUp : na) and AroonHitUp
            	strategy.entry("Long", strategy.long, comment="Up🌙AR", alert_message = Alert_OpenLong)
            if (Consecutive_MODE ? dns >= consecutiveBarsDown : na) and AroonHitDown
            	strategy.close_all(immediately = true, comment="Down👻AR", alert_message = Alert_StopLosslong)
            // ##### 15m Strategy ######
            if (longCondition15) and AroonHitUp
                strategy.entry("Long", strategy.long, alert_message = Alert_OpenLong, comment = "15m🌙AR")
                alert("15m BREAK UP", freq = alert.freq_once_per_bar_close)
            if (shortCondition15) and AroonHitDown
                strategy.close_all("15m BREAK DOWN", immediately = true, alert_message = Alert_StopLosslong)
                alert("15m BREAK DOWN", freq = alert.freq_once_per_bar_close)
            if MAStrategy_MODE == true and MARepeat_Mode == false
                if BullMACross and AroonHitUp
                	strategy.entry("Long", strategy.long, comment="X🌙AR", alert_message = Alert_OpenLong)
                if BearMACross and AroonHitDown
                    strategy.close_all(immediately = true, comment="X👻AR", alert_message = Alert_StopLosslong)
            if (MAStrategy_MODE == true and MARepeat_Mode == true) or (MAStrategy_MODE == false and MARepeat_Mode == true)
                if BullMAPlus and AroonHitUp
                	strategy.entry("Long", strategy.long, comment="X-Re🌙AR", alert_message = Alert_OpenLong)
                if BearMAPlus and AroonHitDown
                    strategy.close_all(immediately = true, comment="X👻AR", alert_message = Alert_StopLosslong)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == false
                if macdTPl and AroonHitUp
                	strategy.entry("Long", strategy.long, comment="MACD🌙AR", alert_message = Alert_OpenLong)
                if macdTPs and AroonHitDown
                    strategy.close_all(immediately = true, comment="MACD👻AR", alert_message = Alert_StopLosslong)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == true
                if (macdTPl and AroonHitUp) or (MACDBull and AroonHitUp)
                	strategy.entry("Long", strategy.long, comment="MACD🌙AR", alert_message = Alert_OpenLong)
                if (macdTPs and AroonHitDown) or (MACDBear and AroonHitDown)
                    strategy.close_all(immediately = true, comment="MACD👻AR", alert_message = Alert_StopLosslong)
            if MACDStrategy_MODE == false and MACDStrategy_Repeat == true
                if (MACDBull and AroonHitUp)
                	strategy.entry("Long", strategy.long, comment="MACD🌙AR", alert_message = Alert_OpenLong)
                if (MACDBear and AroonHitDown)
                    strategy.close_all(immediately = true, comment="MACD👻AR", alert_message = Alert_StopLosslong)
        if MACDConfirm_MODE == false and RSIConfirm_MODE == false and MACross_MODE == false and IchiConfirm_MODE == false and AroonConfirm_MODE == false
            if BreakOut_MODE == true
                if not na(close[lengthBO])
                	strategy.entry("Long", strategy.long, stop=upBound + syminfo.mintick, comment="Break🌙", alert_message = Alert_OpenLong)
                strategy.exit("Long", qty_percent = 100,stop = downBound - syminfo.mintick,comment="Break👻", alert_message = Alert_StopLosslong)
            // ##### Consecutive Strategy #######
            if (Consecutive_MODE ? ups >= consecutiveBarsUp : na)
            	strategy.entry("Long", strategy.long, comment="Up🌙", alert_message = Alert_OpenLong)
            if (Consecutive_MODE ? dns >= consecutiveBarsDown : na)
            	strategy.close_all(immediately = true, comment="Down👻", alert_message = Alert_StopLosslong)
            // ##### 15m Strategy ######
            if (longCondition15)
                strategy.entry("Long", strategy.long, alert_message = Alert_OpenLong)
                alert("15m BREAK UP", freq = alert.freq_once_per_bar_close)
            if (shortCondition15)
                strategy.close_all("15m BREAK DOWN", immediately = true, alert_message = Alert_StopLosslong)
                alert("15m BREAK DOWN", freq = alert.freq_once_per_bar_close)
            if MAStrategy_MODE == true and MARepeat_Mode == false
                if BullMACross
                	strategy.entry("Long", strategy.long, comment="X🌙", alert_message = Alert_OpenLong)
                if BearMACross
                    strategy.close_all(immediately = true, comment="X👻", alert_message = Alert_StopLosslong)
            if (MAStrategy_MODE == true and MARepeat_Mode == true) or (MAStrategy_MODE == false and MARepeat_Mode == true)
                if BullMAPlus
                	strategy.entry("Long", strategy.long, comment="X-Re🌙", alert_message = Alert_OpenLong)
                if BearMAPlus
                    strategy.close_all(immediately = true, comment="X👻", alert_message = Alert_StopLosslong)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == false
                if macdTPl
                	strategy.entry("Long", strategy.long, comment="MACD🌙X", alert_message = Alert_OpenLong)
                if macdTPs
                    strategy.close_all(immediately = true, comment="MACD👻X", alert_message = Alert_StopLosslong)
            if MACDStrategy_MODE == true and MACDStrategy_Repeat == true
                if macdTPl or MACDBull
                	strategy.entry("Long", strategy.long, comment="MACD🌙X", alert_message = Alert_OpenLong)
                if macdTPs or MACDBear
                    strategy.close_all(immediately = true, comment="MACD👻X", alert_message = Alert_StopLosslong)
            if MACDStrategy_MODE == false and MACDStrategy_Repeat == true
                if MACDBull
                	strategy.entry("Long", strategy.long, comment="MACD🌙X", alert_message = Alert_OpenLong)
                if MACDBear
                    strategy.close_all(immediately = true, comment="MACD👻X", alert_message = Alert_StopLosslong)

////////////////////////////////////////////////////////////////////////////////////////////////////////////////    
if Spot_MODE == false
    if (strategy.position_size > 0)
        if sl > 0
            stoploss := calcStopLossPrice(sl)
            stoploss_l := stoploss
        else if sl <= 0
            stoploss := na
        if tp_l > 0
            takeprofit := tp_l
            takeprofit_ll := close + ((close/100)*tp_l)
            //takeprofit_s := na
        else if tp_l <= 0
            takeprofit := na
    if (strategy.position_size < 0)
        if sl > 0
            stoploss := calcStopLossPrice(sl)
            stoploss_s := stoploss
        else if sl <= 0
            stoploss := na
        if tp_s > 0
            takeprofit := tp_s
            takeprofit_ss := close - ((close/100)*tp_s)
            //takeprofit_l := na
        else if tp_s <= 0
            takeprofit := na
    else if strategy.position_size == 0
        stoploss := na
        takeprofit := na
if Spot_MODE == true
    if (strategy.position_size > 0)
        if sl > 0
            stoploss := calcStopLossPrice(sl)
            stoploss_l := stoploss
        else if sl <= 0
            stoploss := na
        if tp_l > 0
            takeprofit := tp_l
            takeprofit_ll := close + ((close/100)*tp_l)
            //takeprofit_s := na
        else if tp_l <= 0
            takeprofit := na
    else if strategy.position_size == 0
        stoploss := na
        takeprofit := na

if mode == true and BOTrail_MODE == false
    if Spot_MODE == false
        if strategy.position_size > 0
            //strategy.cancel_all()
            strategy.exit("Exit",'Long', qty_percent = 100 , profit = takeprofit, stop = stoploss, alert_message = Alert_StopLosslong, comment_profit = "TP💚L", comment_loss = "SL💚L")
        else if strategy.position_size < 0
            //strategy.cancel_all()
            strategy.exit("Exit",'Short', qty_percent = 100, profit = takeprofit, stop = stoploss, alert_message = Alert_StopLossshort, comment_profit = "TP❤️️S", comment_loss = "SL❤️️S")
    else if Spot_MODE == true
        if strategy.position_size > 0
            //strategy.cancel_all()
            strategy.exit("Exit",'Long', qty_percent = 100, profit = takeprofit, stop = stoploss, alert_message = Alert_StopLosslong, comment_profit = "TP💚L", comment_loss = "SL💚L")

else if BOTrail_MODE == true and mode == true
    if Spot_MODE == false
        if strategy.position_size > 0
            //strategy.cancel_all()
            strategy.exit("Exit",'Long', qty_percent = 100 , profit = takeprofit, loss = stoploss, alert_message = Alert_StopLosslong, comment_profit = "TP💚L", comment_loss = "SL💚L")
        //if strategy.position_size > 0
            //strategy.close("Long", qty_percent = 100, comment = "❇️CALLBACK❇️", immediately = true)
        //if SL_ShortBO and strategy.position_size < 0
        //if strategy.position_size < 0    
            //strategy.close("Short", qty_percent = 100, comment = "❇️CALLBACK❇️", immediately = true)
        if strategy.position_size > 0 and SL_LongBO
            strategy.close("Long", qty_percent = 100, comment = "❇️CALLBACK❇️", immediately = true)
        if strategy.position_size < 0
            //strategy.cancel_all()
            strategy.exit("Exit",'Short', qty_percent = 100, profit = takeprofit, loss = stoploss, alert_message = Alert_StopLossshort, comment_profit = "TP❤️️S", comment_loss = "SL❤️️S")
        if strategy.position_size < 0 and SL_ShortBO
            strategy.close("Short", qty_percent = 100, comment = "❇️CALLBACK❇️", immediately = true)
    else if Spot_MODE == true
        //if SL_LongBO and strategy.position_size > 0
        //if strategy.position_size > 0
        //    strategy.close("Long", qty_percent = 100, comment = "❇️CALLBACK❇️", immediately = true)
        if strategy.position_size > 0
            //strategy.cancel_all()
            strategy.exit("Exit",'Long', qty_percent = 100 , profit = takeprofit, loss = stoploss, alert_message = Alert_StopLosslong, comment_profit = "TP💚L", comment_loss = "SL💚L")
        if strategy.position_size > 0 and SL_LongBO
            strategy.close("Long", qty_percent = 100, comment = "❇️CALLBACK❇️", immediately = true)

else if BOTrail_MODE == true and mode == false
    if Spot_MODE == false
        if strategy.position_size > 0 and SL_LongBO
        //if strategy.position_size > 0
            strategy.cancel_all()
            strategy.close("Long", qty_percent = 100, comment = "❇️CALLBACK❇️", immediately = true)
            //strategy.exit("Exit",'Long', qty_percent = 100 , profit = SL_LongBOPrice, alert_message = Alert_StopLosslong, comment_profit = "TP💚L")
        //if strategy.position_size > 0
            //strategy.close("Long", qty_percent = 100, comment = "❇️CALLBACK❇️", immediately = true)
        //if SL_ShortBO and strategy.position_size < 0
        //if strategy.position_size < 0    
            //strategy.close("Short", qty_percent = 100, comment = "❇️CALLBACK❇️", immediately = true)
        if strategy.position_size < 0 and SL_ShortBO
        //if strategy.position_size < 0
            strategy.cancel_all()
            strategy.close("Short", qty_percent = 100, comment = "❇️CALLBACK❇️", immediately = true)
            //strategy.exit("Exit",'Short', qty_percent = 100, profit = SL_ShortBOPrice, alert_message = Alert_StopLossshort, comment_profit = "TP❤️️S")
    if Spot_MODE == true
        //if SL_LongBO and strategy.position_size > 0
        //if strategy.position_size > 0
        //    strategy.close("Long", qty_percent = 100, comment = "❇️CALLBACK❇️", immediately = true)
        if strategy.position_size > 0 and SL_LongBO
            strategy.cancel_all()
            //strategy.exit("Exit",'Long', qty_percent = 100 , profit = SL_LongBOPrice, alert_message = Alert_StopLosslong, comment_profit = "TP💚L")
            strategy.close("Long", qty_percent = 100, comment = "❇️CALLBACK❇️", immediately = true)

if pnl_mode == true
    if strategy.position_size > 0 and pnl_tp
        strategy.cancel_all()
        strategy.close_all(comment = "💵PNL TP💵", alert_message = Alert_StopLosslong)
    if strategy.position_size < 0 and pnl_tp
        strategy.cancel_all()
        strategy.close_all(comment = "💵PNL TP💵", alert_message = Alert_StopLossshort)

if BungToon_Mode == true
    if strategy.position_size > 0 and ticker_close_price <= entry_price
        strategy.close("Long", qty_percent = 100, comment = "🙏BangToon🙏", immediately = true)
    else if strategy.position_size < 0 and ticker_close_price >= entry_price
        strategy.close("Short", qty_percent = 100, comment = "🙏BangToon🙏", immediately = true)

//===================== เรียกใช้  library =========================
import X4815162342/X48_LibaryStrategyStatus/2 as fuLi 
//แสดงผล Backtest

show_Net = input.bool(true,'Monitor Profit&Loss', inline = 'Lnet', group = '= PNL MONITOR SETTING =')
position_ = input.string('bottom_center','Position', options = ['top_right','middle_right','bottom_right','top_center','middle_center','bottom_center','middle_left','bottom_left'] , inline = 'Lnet')
size_i = input.string('auto','size', options = ['auto','tiny','small','normal'] , inline = 'Lnet') 
color_Net = input.color(color.blue,"" , inline = 'Lnet')
fuLi.NetProfit_Show(show_Net , position_ , size_i,  color_Net )

