Zeal Terminal Open Zeal Terminal

Pine Script v5 · Strategy

VXD Supercycle

A Pine Script v5 strategy built on Supertrend (2.4, 12), EMA (close, 21) and SMA (close, 200). It has 10 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 50 settings; defaults include Lost per trade($) 10, Risk:Reward 3.00 and Equity % Take Profit 50.

Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.

Does VXD Supercycle repaint?
No
No repainting patterns were found in the source.
Does VXD Supercycle run in Pine Script v6?
Not tested
The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L33:C0: no source was supplied for the library 'PineCoders/ConditionalAverages/1'. Libraries cannot be fetched from TradingView; supply the source in the 'libraries' option. No libraries were supplied.), so this step could not be checked. The v6 version is shown for reference and is not offered as a download.
Does VXD Supercycle use a stop loss?
Yes
strategy.exit sets a stop on line 289, 295.
Does VXD Supercycle run in Zeal Terminal?
No
Not yet: it imports the library PineCoders/ConditionalAverages/1, whose source is not available here, so it does not run here
Does not run in Zeal Terminal yetIt imports the library PineCoders/ConditionalAverages/1, whose source is not available here, so it does not run here. The settings, logic and review below are read from the source, which does not need a run.

Review

What a careful reader of this script would point out, found by checking the source.

  • Likely bug

    ta.ema(SourceOpen, 25) ignores the settings line 73

    Line 73 hard-codes 25 where line 27 uses “Length”. Changing those settings moves one band but not this one.

    ta.ema(SourceOpen,25)ta.ema(SourceOpen, length)
  • Likely bug

    ta.ema(close, 2) ignores the settings line 86

    Line 86 hard-codes 2 where line 27 uses “Length”. Changing those settings moves one band but not this one.

    ta.ema(close,2)ta.ema(close, length)
  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Note

    2 settings have no label

    In the settings dialog length (line 76), smoothing (line 77) show an empty name. The labels on this page come from the variable names.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Strategy Setting
Open Buy?trueboolentry long2 line 282
Open Sell?trueboolentry Short2 line 285
Use RSI Condition?trueboolrsibuy1 rsibuy2 rsisell1 rsisell2
Use Filter Condition?Excute Order when subhag is following a trend.trueboolactionbull actionbear
Lost per trade($)เจ๊งได้เท่าไหร่?(ต่อ 1 ไม้นะ)10int · min 1lotsbull lotsbear
Use TP/SL?trueboolexit TPSLB exit TPSLB cancel TPSLB exit TPSLS exit TPSLS cancel TPSLS TP SL line 288 line 290 line 294 line 296
Colorcolor.new(color.orange,0)colorTP SL
Risk:Reward3.00float · min 1 · step 0.1takeProfitBull takeProfitBear
Equity % Take ProfitTake a snack and let profit run.50float · min 0.1 · step 5onetrade Alert_LongTP Alert_ShortTP exit TPSLB exit TPSLS
INPUT BACKTEST TIME RANGE
Starttimestamp("01 Jan 1945 00:00 +0000")timetimeCond
Endtimestamp("01 Jan 2074 23:59 +0000")timetimeCond
VWAP Setting
SourceThe source used to calculate the VWAP. The default is the average of the high, low and close prices.closesourcerollingVWAP
Min BarsThe minimum number of last values to keep in the moving window, even if these values are outside the time period. This avoids situations where a large time gap between two bars would cause the time window to be empty.21introllingVWAP
ATR Setting
ATR Period12intsupertrend direction
ATR Multiplier2.4float · step 0.1supertrend direction
RSI Setting
RSI25int · min 1rsibb
RSI-MARSI MA corss 50 Trigger Order14int · min 1rsiMA
MA Setting
Use VWAP?Use VWAP trend linetruebooltrendL
EMAAct as Trend line21int · min 1MA_1
EMA Slowcolor.new(color.yellow,0)colorEMA Slow
SMA200int · min 1MA_2
Subhag Setting
Length (no label in the script)100int · min 1linreg line 26 line 27 line 28 line 29 line 30
Smoothing (no label in the script)17int · min 1linreg
Pivots
Plot PivotstrueboolPivot Top Pivot Bottom
Pivot LookupMinimum = 1, Maximum = 85int · min 1 · max 8hih lol top bottom Pivot Top Pivot Bottom
Pivot bars back for sizingMinimum = 1, Maximum = 10050int · min 1 · max 100highest lowest
Plot When Pivot is DetectedfalseboolPivot Top Pivot Bottom
Pivot Top Colorcolor.new(color.lime,10)colorPivot Top
Pivot Bottom Colorcolor.new(color.red,10)colorPivot Bottom
Rejection Blocks
Plot RJBtrueboolline 172 line 176 line 183 line 190 line 194 line 201 line 207
Box Length ManuallyIf activated the BoS Boxes will not extend unitl crossed by price. Instead will extend by the amount of bars choosen in the "Set BoS Box Length Manually" optionfalseboolline 158
Box Length ManuallyIf "Set BoS Box Length Manually" is marked, choose by how many bars. Minimum = 1, Maximum = 53int · min 1 · max 5line 159 line 160
Bullish RJB Colorcolor.new(color.green,70)color_bullboxRJB
Bearish RJB Colorcolor.new(color.red, 70)color_bearboxRJB
RJB Box Border StyleTo disable border, set Border Width below to 0line.style_solidstring · options [line.style_dashed, line.style_dotted, line.style_solid]_bearboxRJB _bullboxRJB
RJB Border Box Transparency100int · min 0 · max 100_bearboxRJB _bullboxRJB
Maximum RJB Box DisplayedMinimum = 1, Maximum = 100100int · min 1 · max 100line 179 line 186 line 197 line 204
Custom Color Mitigated RJBtrueboolline 161
Mitigated RJB ColorSet to 100 to make mitigated RJB disappearcolor.new(color.gray, 90)colorline 166 line 167
High Volume Bar
Plot HVBA candle where the average volume is higher than last few bars.trueboolBullish HVB Bearish HVB
Bullish HVB Colorcolor.new(color.green,0)colorBullish HVB
Bearish HVB Colorcolor.new(color.orange,0)colorBearish HVB
Volume EMA Period6int · min 1volEma
Volume Multiplier1.2float · min 1 · max 100isHighVolume
Qualitative indicators
Plot PPDD OB'sPremium Premium Discount Discount (PPDD) is an OB formed after liquidity sweep. It will show up by default as a circle (Bull green / Bear red). Also PPDD1 (by deafult maked with a x-cross ⨯) which is a weak OB formed after liquidity sweep, that fails to completely engulf the high/low, but closes beyond the trapped candles open price.trueboolpremiumPremium discountDiscount premiumPremium1 discountDiscount1
Bullish PPDD OB's Colorcolor.new(color.green,0)colorplotshape
Bearish PPDD OB's Colorcolor.new(color.red,0)colorplotshape
Label Options
Plot RJB Labelfalsebool_bearboxRJB _bullboxRJB
Colorcolor.graycolor_bearboxRJB _bullboxRJB
Sizesize.tinystring · options [size.huge, size.large, size.small, size.tiny, size.auto, size.normal]_bearboxRJB _bullboxRJB

What it calculates

  • SupertrendATR Multiplier (2.4), ATR Period (12)supertrend · line 61
  • SupertrendATR Multiplier (2.4), ATR Period (12)direction · line 61
  • EMAclose, EMA (21)MA_1 · line 70
  • SMAclose, SMA (200)MA_2 · line 71
  • EMASourceOpen, 25Candleopen · line 73
  • EMA / Linregta.linreg(close, length, 0), Smoothing (17)linreg · line 79
  • CUMnz(volume)trendL · line 83
  • EMAclose, 2fastl · line 86
  • Pivothighhigh, Pivot Lookup (5), Pivot Lookup (5)hih · line 211
  • Pivotlowlow, Pivot Lookup (5), Pivot Lookup (5)lol · line 212
  • Valuewhenhih, high[pivotLookup], 0top · line 213
  • Valuewhenlol, low [pivotLookup], 0bottom · line 214
  • SMAvolume, Volume EMA Period (6)volEma · line 227
  • Highesttop, Pivot bars back for sizing (50)highest · line 237
  • Lowestbottom, Pivot bars back for sizing (50)lowest · line 238
  • RSIclose, RSI (25)rsibb · line 242
  • Changeactionbullchangetbull · line 256
  • Changeactionbearchangetbear · line 256

Signal flow

How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.

The script has 117 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Close long2(exitlong == true )On278
Close Short2(exitshort == true )On280
Open long2 long(uselong == true) and changetbull and (onetrade[1] != 1)On283
Open Short2 short(useshort == true) and changetbear and (onetrade[1] != -1)On286
Exit TPSLB stop(position_size > 0) and useSL and (low < buyprice)On289
Exit TPSLB limit(position_size > 0) and useSL and (low > buyprice)On291
cancel TPSLB(position_size > 0) and useSL and (low > buyprice)On293
Exit TPSLS stop(position_size < 0) and useSL and (high > sellprice)On295
Exit TPSLS limit(position_size < 0) and useSL and (high < sellprice)On297
cancel TPSLS(position_size < 0) and useSL and (high < sellprice)On299

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Does it repaint?

No

No repainting patterns in the source.

The live replay needs a run, and this script does not run in Zeal Terminal yet; the answer comes from the checks on the source alone.

  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
  • ClearOrder timingprocess_orders_on_close = true: orders fill at the signal bar's close.

The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.

Similar scripts

Indicators and strategies built from the same calculations.

ScriptSharesTypeNetTradesMax drawdown
X48 - Strategy - MA Type Cross + TPSL - Future&Spot - V.2 by X4815162342ema rsi sma highest lowest pivothigh pivotlow valuewhenv5 strategydoes not run in Zeal Terminal
MACD 5 iN 1 [Pro-Tool] by HamidBoxsma ema rsi pivotlow pivothigh highest lowestv4 strategyNo trades on this market
RSI Overbought Oversold Divergence Strategy w- Buy-Sell Signals by imal_maxema sma lowest highest rsi cum pivotlowv5 strategydoes not run in Zeal Terminal
TradePro's 2 EMA + Stoch RSI + ATR Strategy by PtGamblerema rsi sma pivothigh pivotlow valuewhenv5 strategy−2.7%1822.0%
TICK Scalping strategy, SPY 1 min by PtGamblerema sma pivotlow pivothigh rsi lowest highestv5 strategyNo trades on this market

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • 1 setting uses the untyped input() (line 101). It still compiles in v6; input.int, input.float or input.source state the type.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

Not verified

The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L33:C0: no source was supplied for the library 'PineCoders/ConditionalAverages/1'. Libraries cannot be fetched from TradingView; supply the source in the 'libraries' option. No libraries were supplied.), so this step could not be checked.

  • Line 101: input() → input.bool()
⋯pivotsizing             = input.int(defval=50, minval=1, maxval=100,title='Pivot bars back for sizing', group='═══════════ Pivots ═══════════', tooltip='Minimum = 1, Maximum = 100')-plotInThePast           = input(false, "Plot When Pivot is Detected" ,group='═══════════ Pivots ═══════════')+plotInThePast           = input.bool(false, "Plot When Pivot is Detected" ,group='═══════════ Pivots ═══════════')pvtTopColor             = input.color(defval=color.new(color.lime,10), title='Pivot Top Color', group='═══════════ Pivots ═══════════', inline='PVT Top Color')⋯

Does it run in Pine Script v6?

Not tested

The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L33:C0: no source was supplied for the library 'PineCoders/ConditionalAverages/1'. Libraries cannot be fetched from TradingView; supply the source in the 'libraries' option. No libraries were supplied.), so this step could not be checked. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © Vvaz_-//@version=5+//@version=6//This Strategy Combined the following indicators and conditioning by me⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2No It imports the library PineCoders/ConditionalAverages/1, whose source is not available here, so it does not run hereNot measured
PineTSNot testedNot testedNot measured

“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.

Source

Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © Vvaz_//@version=5//This Strategy Combined the following indicators and conditioning by me//Rolling VWAP , ATR , RSI , EMA , SMA //Subhag    form Subhag Ghosh//OB PPDD   Form Super OrderBlock / FVG / BoS Tools by makuchaku & eFestrategy("VXD Supercycle", "VXD", overlay=true , initial_capital=100 ,currency = currency.USD , pyramiding = 1 ,process_orders_on_close= true)// Strategy Settinguselong     = input.bool(title="Open Buy?", defval = true , group='═══════════ Strategy Setting ═══════════')useshort    = input.bool(title="Open Sell?", defval = true , group='═══════════ Strategy Setting ═══════════')useRSIC     =input.bool(title="Use RSI Condition?", defval = true , group='═══════════ Strategy Setting ═══════════')usefilter   =input.bool(title="Use Filter Condition?", defval = true , group='═══════════ Strategy Setting ═══════════', tooltip = 'Excute Order when subhag is following a trend.')riskPer     = input.int(10, "Lost per trade($)", minval = 1, group='═══════════ Strategy Setting ═══════════', tooltip = 'เจ๊งได้เท่าไหร่?(ต่อ 1 ไม้นะ)')useSL       = input.bool(title="Use TP/SL?", defval = true , inline='Set', group='═══════════ Strategy Setting ═══════════')usetpcl     = input.color(defval=color.new(color.orange,0), title='Color', inline='Set', group='═══════════ Strategy Setting ═══════════')rrPer       = input.float(3.00, "Risk:Reward", minval = 1, step=0.1, group='═══════════ Strategy Setting ═══════════')TPper       = input.float(50, "Equity % Take Profit", minval = 0.1, step=5, group='═══════════ Strategy Setting ═══════════', tooltip='Take a snack and let profit run.')// 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)i_endTime               = input.time(defval = timestamp("01 Jan 2074 23:59 +0000"), title = "End", inline="timeend", group=BTR1)timeCond                = (time > i_startTime) and (time < i_endTime)//////////////////////////////////// function MA //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////ma(source, length, type) =>    type == "SMA" ? ta.sma(source, length) :     type == "EMA" ? ta.ema(source, length) :     type == "SMMA (RMA)" ? ta.rma(source, length) :     type == "WMA" ? ta.wma(source, length) :     type == "VWMA" ? ta.vwma(source, length) :     na////////////////////////////////  RVWAP //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////import PineCoders/ConditionalAverages/1 as pcvar string GRP2       = '═══════════ VWAP Setting ═══════════'var string TT_MINBARS = "The minimum number of last values to keep in the moving window, even if these values are outside the time period. This avoids situations where a large time gap between two bars would cause the time window to be empty."int MS_IN_MIN   = 60 * 1000int MS_IN_HOUR  = MS_IN_MIN  * 60int MS_IN_DAY   = MS_IN_HOUR * 24float srcInput        = input.source(close, "Source", tooltip = "The source used to calculate the VWAP. The default is the average of the high, low and close prices.", group = GRP2)int  minBarsInput     = input.int(21, "Min Bars", group = GRP2, tooltip = TT_MINBARS)timeStep() =>    // @function    Determines a time period from the chart's timeframe.    // @returns     (int) A value of time in milliseconds that is appropriate for the current chart timeframe. To be used in the RVWAP calculation.    int tfInMs = timeframe.in_seconds() * 1000    float step =      switch        tfInMs <= MS_IN_MIN        => MS_IN_HOUR        tfInMs <= MS_IN_MIN * 5    => MS_IN_HOUR * 4        tfInMs <= MS_IN_HOUR       => MS_IN_DAY * 1        tfInMs <= MS_IN_HOUR * 4   => MS_IN_DAY * 3        tfInMs <= MS_IN_HOUR * 12  => MS_IN_DAY * 7        tfInMs <= MS_IN_DAY        => MS_IN_DAY * 30.4375        tfInMs <= MS_IN_DAY * 7    => MS_IN_DAY * 90        => MS_IN_DAY * 365    int result = int(step)// RVWAPfloat rollingVWAP = pc.totalForTimeWhen(srcInput * volume, timeStep(), true, minBarsInput) / pc.totalForTimeWhen(volume, timeStep(), true, minBarsInput)/////////////////////////  ATR  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Periods = input.int(title="ATR Period", defval=12 ,group='═══════════ ATR Setting ═══════════')Multiplier = input.float(title="ATR Multiplier", step=0.1, defval=2.4,group='═══════════ ATR Setting ═══════════')[supertrend, direction] = ta.supertrend(Multiplier, Periods)/////////////////////////  RSI  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////LengthRSI = input.int(25,'RSI', minval=1, group='═══════════ RSI Setting ═══════════')LengthRSIMA = input.int(14,'RSI-MA', minval=1, group='═══════════ RSI Setting ═══════════', tooltip = 'RSI MA corss 50 Trigger Order')/////////////////////////  MA  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////useMA = input.bool(title="Use VWAP?", defval = true , group='═══════════ MA Setting ═══════════', tooltip = 'Use VWAP trend line')LengthMA = input.int(21,'EMA', minval=1, group='═══════════ MA Setting ═══════════', tooltip = 'Act as Trend line')sma2cl          = input.color(defval=color.new(color.yellow,0), title='EMA Slow', group='═══════════ MA Setting ═══════════' ,inline = 'sma200')LengthMA2 = input.int(200,'SMA', minval=1, group='═══════════ MA Setting ═══════════' ,inline = 'sma200')float MA_1 = ta.ema(close, LengthMA)MA_2 = ta.sma(close, LengthMA2)SourceOpen = (open + close[1]) / 2Candleopen = ta.ema(SourceOpen,25)Bodycolor = Candleopen > Candleopen[1] ? color.green : color.red////////////////////////// Subhag form Subhag Ghosh //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////length = input.int(100, minval=1, group='═══════════ Subhag Setting ═══════════')smoothing = input.int(17, minval=1, group='═══════════ Subhag Setting ═══════════')// Regression Lineslinreg                  = ta.ema(ta.linreg(close, length, 0),smoothing)//COLOR of Regression LinehullColor = linreg > linreg[3] ? color.green :linreg < linreg[3] ? color.red : color.yellow///////////////////////////////  define trend  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////trendL      = useMA and ta.cum(nz(volume)) != 0 ? rollingVWAP : MA_1upTrend     = direction < 0 ? supertrend : linreg[3]downTrend   = direction < 0 ? linreg : supertrendfastl       = ta.ema(close,2)greenzone   = (fastl > trendL) and (direction < 0)  and (close > linreg) and (Bodycolor == color.green)redzone     = (fastl < trendL) and (direction > 0 )  and (close < linreg) and (Bodycolor == color.red)greenzoneB   = (fastl > trendL) and (direction < 0)  and (hullColor == color.green) and (Bodycolor == color.green)redzoneB     = (fastl < trendL) and (direction > 0 )  and (hullColor == color.red) and (Bodycolor == color.red)//plotMA and candlezonecl      = greenzone ? color.green : redzone ? color.red : color.yellowmain1       = plot(trendL , title="EMA Fast" , color=zonecl , linewidth=1)main2       = plot(MA_2 , title="EMA Slow" , color=sma2cl , linewidth=2)//-------------------------------NSDT HAMA Candelsplotbar(linreg[3], upTrend, downTrend, linreg, color=color.new(hullColor,60), title='Configure Bars')//////////////////////////////////  OB PPDD Form Super OrderBlock / FVG / BoS Tools by makuchaku & eFe  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////plotPVT                 = input.bool(defval=true, title='Plot Pivots', group='═══════════ Pivots ═══════════')pivotLookup             = input.int(defval=5, minval=1, maxval=8,title='Pivot Lookup', group='═══════════ Pivots ═══════════', tooltip='Minimum = 1, Maximum = 8')pivotsizing             = input.int(defval=50, minval=1, maxval=100,title='Pivot bars back for sizing', group='═══════════ Pivots ═══════════', tooltip='Minimum = 1, Maximum = 100')plotInThePast           = input(false, "Plot When Pivot is Detected" ,group='═══════════ Pivots ═══════════')pvtTopColor             = input.color(defval=color.new(color.lime,10), title='Pivot Top Color', group='═══════════ Pivots ═══════════', inline='PVT Top Color')pvtBottomColor          = input.color(defval=color.new(color.red,10), title='Pivot Bottom Color', group='═══════════ Pivots ═══════════', inline='PVT Top Color')plotRJB                 = input.bool(defval=true, title='Plot RJB', group='═══════════ Rejection Blocks ═══════════', inline='RJB sets')bosBoxFlag              = input.bool(title='Box Length Manually', defval=false, group='═══════════ Rejection Blocks ═══════════', tooltip='If activated the BoS Boxes will not extend unitl crossed by price. Instead will extend by the amount of bars choosen in the "Set BoS Box Length Manually" option')bosBoxLength            = input.int(title='Box Length Manually', defval=3, minval=1, maxval=5, group='═══════════ Rejection Blocks ═══════════', tooltip='If "Set BoS Box Length Manually" is marked, choose by how many bars. Minimum = 1, Maximum = 5')rjbBullColor            = input.color(defval=color.new(color.green,70), title='Bullish RJB Color', inline='Set Custom Color', group='═══════════ Rejection Blocks ═══════════')rjbBearColor            = input.color(defval=color.new(color.red, 70), title='Bearish RJB Color', inline='Set Custom Color', group='═══════════ Rejection Blocks ═══════════')rjbBoxBorder            = input.string(defval=line.style_solid, title='RJB Box Border Style', options=[line.style_dashed, line.style_dotted, line.style_solid], group='═══════════ Rejection Blocks ═══════════', tooltip='To disable border, set Border Width below to 0')rjbBorderTransparency   = input.int(defval=100, title='RJB Border Box Transparency', minval=0, maxval=100, group='═══════════ Rejection Blocks ═══════════')rjbMaxBoxSet            = input.int(defval=100, title='Maximum RJB Box Displayed', minval=1, maxval=100, group='═══════════ Rejection Blocks ═══════════', tooltip='Minimum = 1, Maximum = 100')filterMitRJB            = input.bool(defval=true, title='Custom Color Mitigated RJB', group='═══════════ Rejection Blocks ═══════════')mitRJBColor             = input.color(defval=color.new(color.gray, 90), title='Mitigated RJB Color', group='═══════════ Rejection Blocks ═══════════', inline='Set Custom Color Mit RJB', tooltip='Set to 100 to make mitigated RJB disappear')plotHVB                 = input.bool(defval=true, title='Plot HVB', group='═══════════ High Volume Bar ═══════════', tooltip='A candle where the average volume is higher than last few bars.')hvbBullColor            = input.color(defval=color.new(color.green,0), title='Bullish HVB Color', inline='Set Custom Color', group='═══════════ High Volume Bar ═══════════')hvbBearColor            = input.color(defval=color.new(color.orange,0), title='Bearish HVB Color', inline='Set Custom Color', group='═══════════ High Volume Bar ═══════════')hvbEMAPeriod            = input.int(defval=6, minval=1, title='Volume EMA Period', group='═══════════ High Volume Bar ═══════════')hvbMultiplier           = input.float(defval=1.2, title='Volume Multiplier', minval=1, maxval=100, group='═══════════ High Volume Bar ═══════════')plotPPDD                = input.bool(defval=true, title="Plot PPDD OB's", group='═══════════ Qualitative indicators ═══════════', tooltip='Premium Premium Discount Discount (PPDD) is an OB formed after liquidity sweep. It will show up by default as a circle (Bull green / Bear red). Also PPDD1 (by deafult maked with a x-cross ⨯) which is a weak OB formed after liquidity sweep, that fails to completely engulf the high/low, but closes beyond the trapped candles open price.')ppddBullColor           = input.color(defval=color.new(color.green,0), title="Bullish PPDD OB's Color", group='═══════════ Qualitative indicators ═══════════', inline='PPDD Bull')ppddBearColor           = input.color(defval=color.new(color.red,0), title="Bearish PPDD OB's Color", group='═══════════ Qualitative indicators ═══════════', inline='PPDD Bear')//labelsplotLabelRJB            = input.bool(defval=false, title='Plot RJB Label', inline='RJB label', group='═══════════ Label Options ═══════════')rjbLabelColor           = input.color(defval=color.gray, title='Color', inline='RJB label', group='═══════════ Label Options ═══════════')rjbLabelSize            = input.string(defval=size.tiny, title="Size", options=[size.huge, size.large, size.small, size.tiny, size.auto, size.normal], inline='RJB label', group='═══════════ Label Options ═══════════')//Box Typesvar int _rjb = 3var int _bos = 4//Box Labelsvar string _rjbLabel = "RJB"var string _plus     = "+"var string _minus    = "-"var string _empty    = ""//Box Arraysvar box[] _bearBoxesRJB = array.new_box()var box[] _bullBoxesRJB = array.new_box()//FunctionsisUp(index) =>    close[index] > open[index]isDown(index) =>    close[index] < open[index]isObUp(index) =>    isDown(index + 1) and isUp(index) and close[index] > high[index + 1]isObDown(index) =>    isUp(index + 1) and isDown(index) and close[index] < low[index + 1]isFvgUp(index) =>    (low[index] > high[index + 2])isFvgDown(index) =>    (high[index] < low[index + 2])//Function to Calculte Box Length_controlBox(_boxes, _high, _low, _type) =>    if array.size(_boxes) > 0        for i = array.size(_boxes) - 1 to 0 by 1            _box = array.get(_boxes, i)            _boxLow = box.get_bottom(_box)            _boxHigh = box.get_top(_box)            _boxRight = box.get_right(_box)            if bosBoxFlag and _type == _bos                if na or (bar_index + bosBoxLength - 1 == _boxRight and not((_high > _boxLow and _low < _boxLow) or (_high > _boxHigh and _low < _boxHigh)))                    box.set_right(_box, bar_index + bosBoxLength - 1)            else if (filterMitRJB and _type == _rjb)                if na or (bar_index == _boxRight and not((_high > _boxLow and _low < _boxLow) or (_high > _boxHigh and _low < _boxHigh)))                    box.set_right(_box, bar_index + 1)                else                    if _type == _rjb                        box.set_bgcolor(_box, mitRJBColor)                        box.set_border_color(_box, mitRJBColor)            else                if na or (bar_index == _boxRight and not((_high > _boxLow and _low < _boxLow) or (_high > _boxHigh and _low < _boxHigh)))                    box.set_right(_box, bar_index + 1)//////////////////// Rejection Block //////////////////if plotRJB    isDownRjbObCondition    = isObDown(1)    isDownRjb1              = isDownRjbObCondition and  (high[1] < (close[2] + 0.2*(high[2]-close[2]))) // RJB is on trapped's wick and <50% of the wick was covered by signal    isDownRjb2              = isDownRjbObCondition and (high[1] > high[2]) // RJB is on signal's wick    if isDownRjb1 and plotRJB        _bearboxRJB         = box.new(left=bar_index-2, top=high[2], right=bar_index, bottom=close[2], bgcolor=rjbBearColor, border_color=color.new(rjbBearColor, rjbBorderTransparency), border_style=rjbBoxBorder, border_width=1,         text   = plotLabelRJB ? _rjbLabel  + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=rjbLabelSize, text_color=rjbLabelColor)        if array.size(_bearBoxesRJB) > rjbMaxBoxSet            box.delete(array.shift(_bearBoxesRJB))        array.push(_bearBoxesRJB, _bearboxRJB)            if isDownRjb2 and plotRJB        _bearboxRJB         = box.new(left=bar_index-1, top=high[1], right=bar_index, bottom=open[1], bgcolor=rjbBearColor, border_color=color.new(rjbBearColor, rjbBorderTransparency), border_style=rjbBoxBorder, border_width=1,         text=plotLabelRJB ? _rjbLabel  + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=rjbLabelSize, text_color=rjbLabelColor)        if array.size(_bearBoxesRJB) > rjbMaxBoxSet            box.delete(array.shift(_bearBoxesRJB))        array.push(_bearBoxesRJB, _bearboxRJB)//Bullish RJB Box Plottingif plotRJB    isUpRjbObCondition      = isObUp(1)    isUpRjb1                = isUpRjbObCondition and (low[1] > (close[2] - 0.2*(close[2]-low[2]))) // RJB is on trapped's wick and <50% of the wick was covered by signal    isUpRjb2                = isUpRjbObCondition and (low[1] < low[2]) // RJB is on signal's wick    if isUpRjb1 and plotRJB        _bullboxRJB         = box.new(left=bar_index-2, top=close[2], right=bar_index, bottom=low[2], bgcolor=rjbBullColor, border_color=color.new(rjbBullColor, rjbBorderTransparency), border_style=rjbBoxBorder, border_width=1,         text  = plotLabelRJB ? _rjbLabel  + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=rjbLabelSize, text_color=rjbLabelColor)        if array.size(_bullBoxesRJB) > rjbMaxBoxSet            box.delete(array.shift(_bullBoxesRJB))        array.push(_bullBoxesRJB, _bullboxRJB)        if isUpRjb2 and plotRJB        _bullboxRJB = box.new(left=bar_index-1, top=open[1], right=bar_index, bottom=low[1], bgcolor=rjbBullColor, border_color=color.new(rjbBullColor, rjbBorderTransparency), border_style=rjbBoxBorder, border_width=1,          text=plotLabelRJB ? _rjbLabel  + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=rjbLabelSize, text_color=rjbLabelColor)        if array.size(_bullBoxesRJB) > rjbMaxBoxSet            box.delete(array.shift(_bullBoxesRJB))        array.push(_bullBoxesRJB, _bullboxRJB)if plotRJB    _controlBox(_bearBoxesRJB, high, low, _rjb)    _controlBox(_bullBoxesRJB, high, low, _rjb)//////////////////// Pivots //////////////////// hih     = ta.pivothigh(high, pivotLookup, pivotLookup)lol     = ta.pivotlow(low , pivotLookup, pivotLookup)top     = ta.valuewhen(hih, high[pivotLookup], 0)bottom  = ta.valuewhen(lol, low [pivotLookup], 0)pvtop = plot(top, offset=plotInThePast ? 0 : -pivotLookup , linewidth=1, color=(top != top[1] ? na : (plotPVT ? pvtTopColor : na)), title="Pivot Top")pvdow = plot(bottom, offset=plotInThePast ? 0 : -pivotLookup, linewidth=1, color=(bottom != bottom[1] ? na : (plotPVT ? pvtBottomColor : na)), title="Pivot Bottom")//////////////////// Premium Premium & Discount Discount //////////////////premiumPremium      = plotPPDD and isObDown(0) and ((math.max(high, high[1]) > top and close < top) or (math.max(high, high[1]) > top[1] and close < top[1]))discountDiscount    = plotPPDD and isObUp(0) and ((math.min(low, low[1]) < bottom and close > bottom) or (math.min(low, low[1]) < bottom[1] and close > bottom[1]))plotshape(premiumPremium, "Bearish PPDD OB", style=shape.circle , location=location.abovebar, color=ppddBearColor, size=size.tiny)plotshape(discountDiscount, "Bullish PPDD OB", style=shape.circle , location=location.belowbar, color=ppddBullColor, size=size.tiny)premiumPremium1     = plotPPDD and (isUp(1) and isDown(0) and close[0] < open[1]) and ((math.max(high, high[1]) > top and close < top) or (math.max(high, high[1]) > top[1] and close < top[1])) and not premiumPremiumdiscountDiscount1   = plotPPDD and (isDown(1) and isUp(0) and close[0] > open[1]) and ((math.min(low, low[1]) < bottom and close > bottom) or (math.min(low, low[1]) < bottom[1] and close > bottom[1])) and not discountDiscountplotshape(premiumPremium1, "Bearish PPDD Weak OB", style=shape.xcross, location=location.abovebar, color=ppddBearColor, size=size.tiny)plotshape(discountDiscount1, "Bullish PPDD Weak OB", style=shape.xcross, location=location.belowbar, color=ppddBullColor, size=size.tiny)////////////////// High Volume Bars //////////////////volEma          = ta.sma(volume, hvbEMAPeriod)isHighVolume    = volume > (hvbMultiplier * volEma)barcolor(plotHVB and isUp(0) and isHighVolume ? hvbBullColor : na, title="Bullish HVB")barcolor(plotHVB and isDown(0) and isHighVolume ? hvbBearColor : na, title="Bearish HVB")//////////////////////////////////   Strategy condition   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////openoncel       = strategy.opentrades == 0 or (strategy.opentrades.entry_id(0) == 'Short2')openonces       = strategy.opentrades == 0 or (strategy.opentrades.entry_id(0) == 'long2')exitshort       =  (fastl > trendL)     and (direction < 0) and (close > top) and (close > linreg)exitlong        =  (fastl < trendL)     and (direction > 0) and (close < bottom) and (close < linreg)//sizinghighest                     = ta.highest(top,pivotsizing)lowest                      = ta.lowest(bottom,pivotsizing)lotsbull                    = math.abs((riskPer ) / (close - lowest)) lotsbear                    = math.abs((riskPer ) / (highest - close))////condition for RSIrsibb           = ta.rsi(close,LengthRSI)rsiMA           = ma(rsibb, LengthRSIMA, "SMA")rsibuy1         = ta.crossover(rsiMA,50)    and  (rsibb > rsiMA)  and useRSIC and (close > top) and greenzone and timeCondrsibuy2         = ta.crossover(rsiMA,50)    and  (rsibb > rsiMA)  and useRSIC and (close > top) and greenzoneB and timeCondrsisell1        = ta.crossunder(rsiMA,50)   and  (rsibb < rsiMA)  and useRSIC and (close < bottom) and redzone and timeCondrsisell2        = ta.crossunder(rsiMA,50)   and  (rsibb < rsiMA)  and useRSIC and (close < bottom) and redzoneB and timeCond//condition for trendLongCondition   =   (close > supertrend)   and openoncel  and (close > top) and greenzone  and timeCondShortCondition  =   ( close < supertrend)  and openonces  and (close < bottom)    and redzone  and timeCondLongConditionB   =   (close > supertrend)   and openoncel  and (close > top) and greenzoneB  and timeCondShortConditionB  =   ( close < supertrend)  and openonces  and (close < bottom)    and redzoneB  and timeCondposition_size           = strategy.position_sizeactionbull              = usefilter == true ? (rsibuy2 or LongConditionB) : (rsibuy1 or LongCondition)actionbear              = usefilter == true ? (rsisell2 or ShortConditionB) : (ShortCondition or rsisell1)changetbull                 = ta.change(actionbull) ,changetbear             = ta.change(actionbear) ,buyprice                = 0.0 ,sellprice               = 0.0 ,mapast                  = 0.0 ,slprice                 = 0.0 ,openprice               = strategy.opentrades.entry_price(0),sl_percent_bear   = 0.0,sl_percent_bull   = 0.0 , onetrade = 0buyprice                    := position_size >= 0 ? changetbull ? openprice : buyprice[1] : nasellprice                   := position_size <= 0 ? changetbear ? openprice : sellprice[1] : namapast                      := changetbull ? MA_2 : changetbear ? MA_2 : mapast[1] onetrade                    := TPper == 100 ? (changetbull ? 1 : changetbear ? -1 :  onetrade[1]) : 0slprice                     := changetbull ? lowest : changetbear ? highest : slprice[1]sl_percent_bull             := changetbull ? (buyprice - lowest)/buyprice : (position_size > 0) ? sl_percent_bull[1] :(position_size < 0)  ? 0.0 : 0.0 takeProfitBull              = buyprice * (1 + (sl_percent_bull*rrPer))sl_percent_bear             := changetbear ? (highest - sellprice) / sellprice : (position_size < 0) ? sl_percent_bear[1] :(position_size > 0)  ? 0.0 : 0.0 takeProfitBear              = sellprice * (1 - (sl_percent_bear*rrPer))plot(useSL and changetbull ? takeProfitBull : useSL and changetbear ? takeProfitBear : na , 'TP',usetpcl,style=plot.style_linebr , linewidth=1 )plot(useSL and changetbull ? slprice : useSL and changetbear ? slprice : na , 'SL',usetpcl,style=plot.style_linebr , linewidth=1 )string Alert_OpenLong       ='Long Entry! on '+syminfo.ticker+'\n Buy@'+str.tostring(close)+'\n Size = '+str.tostring(lotsbull)+'\n SL = '+str.tostring(slprice)string Alert_OpenShort      ='Short Entry! on '+syminfo.ticker+'\n Sell@'+str.tostring(close)+'\n Size = '+str.tostring(lotsbear)+'\n SL = '+str.tostring(slprice)string Alert_LongTP         ='TP Long on '+syminfo.ticker+' @'+str.tostring(takeProfitBull)+' Size = '+str.tostring((position_size * (TPper/100)))string Alert_ShortTP        ='TP Short on '+syminfo.ticker+' @'+str.tostring(takeProfitBear)+' Size = '+str.tostring((position_size * (TPper/100)))var message_closelong       = 'Tailing Stop Long!!!'var message_closeshort      = 'Tailing Stop Short!!!'string Alert_StopLosslong   ='StopLoss Long! on '+syminfo.ticker+' @'+str.tostring(slprice)string Alert_StopLossshort  = 'StopLoss Short! on '+syminfo.ticker+' @'+str.tostring(slprice)// exit orderif (exitlong == true  )    strategy.close('long2', comment='TailingStop-L', alert_message=message_closelong)if (exitshort == true )    strategy.close('Short2', comment='TailingStop-S', alert_message=message_closeshort)// longif (uselong == true) and changetbull and (onetrade[1] != 1)    strategy.entry('long2', strategy.long   ,qty =lotsbull , comment='Long', alert_message=Alert_OpenLong)// Shortif (useshort == true) and changetbear and (onetrade[1] != -1)    strategy.entry('Short2', strategy.short   ,qty =lotsbear, comment='Short', alert_message=Alert_OpenShort)//TPSLif (position_size > 0) and useSL and (low < buyprice)    strategy.exit('TPSLB','long2', comment='SL', stop =slprice  , alert_message=Alert_StopLosslong)else if (position_size > 0) and useSL and (low > buyprice)    strategy.exit('TPSLB','long2', comment='TP',limit=takeProfitBull , alert_message=Alert_LongTP , qty_percent=TPper)else    strategy.cancel('TPSLB')if (position_size < 0) and useSL and  (high > sellprice)    strategy.exit('TPSLS','Short2',comment= 'SL', stop=slprice , alert_message=Alert_StopLossshort)else if (position_size < 0) and useSL and  (high < sellprice)    strategy.exit('TPSLS','Short2',comment= 'TP',limit=takeProfitBear  , alert_message=Alert_ShortTP, qty_percent=TPper)else    strategy.cancel('TPSLS')//////////////////////////////////   By Vvaz_   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////