Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Zweig Market Breadth Thrust Indicator Strategy

A Pine Script v4 strategy built on RSI (close, 5). It has 6 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 20% of equity and pays no commission. 9 settings; defaults include MA type EMA, MA Length 65 and Mkt NYSE.

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 Zweig Market Breadth Thrust Indicator Strategy repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did Zweig Market Breadth Thrust Indicator Strategy do on BTCUSDT 1D with default settings?
Not measured
It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its entry conditions never all held on this data. It closed no trades on the other markets either. A backtest, not investment advice.
Can Zweig Market Breadth Thrust Indicator Strategy be converted to Pine Script v5?
Not tested
The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
Does Zweig Market Breadth Thrust Indicator Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Zweig Market Breadth Thrust Indicator Strategy run in Zeal Terminal?
Yes
It compiles in 16 ms and runs 1,000 bars in 57 ms, in the browser.

BTCUSDT · 1D · default settings

  • OS
  • OB
  • DummyOS
  • DummyOB
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctOS$10,000$20,253Equity from $10,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. Zeal Terminal's engine currently reads an order side written as long = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 47) so the engine trades the way the script says. The live re-run is not offered here: the script requests ADVN D, DECN D, which this page cannot load in your browser.

Needs ADVN D data, not available: not a Binance spot market Needs DECN D data, not available: not a Binance spot market Values that depend on it are empty on this chart.

Net profit
0.00%
$0.00
Buy and hold
+102.5%
same period
Closed trades
0
0 won · 0 lost
Profitable
0.0%
of closed trades
Profit factor
—
gross profit ÷ gross loss
Max drawdown
0.00%
$0.00

One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.

Review

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

  • Likely bug

    crossunder(zmbti, 0.6) ignores the settings line 56

    Line 56 hard-codes 0.6 where line 59 uses “Buy Entry At”. Changing those settings moves one band but not this one.

    crossunder(zmbti, 0.6)crossunder(zmbti, buyEntryAt)
  • Likely bug

    crossunder(myRsi, 90) ignores the settings line 57

    Line 57 hard-codes 90 where line 59 uses “Buy Entry At”. Changing those settings moves one band but not this one.

    crossunder(myRsi, 90)crossunder(myRsi, buyEntryAt)
  • Check

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • Check

    No commission

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

  • Note

    3 settings have no label

    In the settings dialog ma_type (line 5), mkt (line 7), buyEntryAt (line 8) 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.

  • Note

    Uses an argument v6 removed

    when = on line 47, 56, 57, 59, 61, 62. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 39

    transp = on line 39, 40. v5 folds the transparency into the colour with color.new(c, transp).

  • Note

    Uses long =, which v5 renamed line 47

    long = on line 47. v5 writes it as direction = strategy.long or strategy.short.

Upgrade and export

Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.

  • Upgrading to v5 renames sma → ta.sma, ema → ta.ema, wma → ta.wma, security → request.security, rsi → ta.rsi, crossover → ta.crossover, max → math.max, crossunder → ta.crossunder.
  • 6 strategy calls use the when = argument (line 47, 56, 57, 59, 61, 62). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 3: //@version=4 → //@version=5
  • Line 15: sma → ta.sma
  • Line 15: ema → ta.ema
  • Line 15: wma → ta.wma
  • Line 15: sma → ta.sma
  • Line 24: security → request.security
10 more edits
  • Line 25: security → request.security
  • Line 30: rsi → ta.rsi
  • Line 39: transp = 60 → color.new(color.green, 60)
  • Line 40: transp = 60 → color.new(color.red, 60)
  • Line 47: long = true → direction = strategy.long
  • Line 47: crossover → ta.crossover
  • Line 51: max → math.max
  • Line 56: crossunder → ta.crossunder
  • Line 57: crossunder → ta.crossunder
  • Line 59: crossunder → ta.crossunder
⋯// © mohanee-//@version=4+//@version=5strategy("Zweig Market Breadth Thrust Indicator Strategy", overlay=false, pyramiding=3 , default_qty_type=strategy.percent_of_equity,  default_qty_value=20,  initial_capital=10000, currency=currency.USD)⋯//function-getMAval(s,l, ma_type) => ma_type== "SMA" ? sma(s,l):  ma_type== "EMA" ? ema(s,l)   : ma_type=="WMA" ?   wma(s,l) : sma(s,l)+getMAval(s,l, ma_type) => ma_type== "SMA" ? ta.sma(s,l):  ma_type== "EMA" ? ta.ema(s,l)   : ma_type=="WMA" ?   ta.wma(s,l) : ta.sma(s,l)//calculate Zweig Market Breadth Thrust⋯decc="(DECN+DECQ+DECA)/3.0"-adv= security(mkt=="COMBINED" ? advc:mkt == "NYSE" ? advn: mkt == "NASDAQ" ? advnq : mkt == "AMEX" ? advna:na, res, close)   //res+adv= request.security(mkt=="COMBINED" ? advc:mkt == "NYSE" ? advn: mkt == "NASDAQ" ? advnq : mkt == "AMEX" ? advna:na, res, close)   //res-dec= security(mkt=="COMBINED" ? decc:mkt == "NYSE" ? decn:mkt == "NASDAQ" ? decnq :  mkt == "AMEX" ? decna:na, res, close)+dec= request.security(mkt=="COMBINED" ? decc:mkt == "NYSE" ? decn:mkt == "NASDAQ" ? decnq :  mkt == "AMEX" ? decna:na, res, close)zmbti = getMAval(adv/(adv+dec), ma_length, ma_type)⋯/////////////////////////////////////////////////////////////-myRsi = rsi(close, 5)+myRsi = ta.rsi(close, 5)//Plot⋯fill(osl,obl,color.purple, title="RegionFill")-fill(osl, osd, color.green, transp=60, title="OSFill")+fill(osl, osd, color.new(color.green, 60), title="OSFill")-fill(obl, obd, color.red, transp=60, title="OBFill")+fill(obl, obd, color.new(color.red, 60), title="OBFill")plot(zmbti, color=color.blue, linewidth=2, title="BreadthThrust(advances)")⋯/////////////////////////////////////////////////////////////-strategy.entry(id="zmbtiLong" , long=true, when=crossover(zmbti, buyEntryAt) )+strategy.entry(id="zmbtiLong" , direction = strategy.long, when=ta.crossover(zmbti, buyEntryAt) )////// Calculate trailing SL⋯trailing_sl = 0.0-trailing_sl :=   strategy.position_size>=1 ?  max(low  - sl_val, nz(trailing_sl[1])) :  na+trailing_sl :=   strategy.position_size>=1 ?  math.max(low  - sl_val, nz(trailing_sl[1])) :  nastopLossVal = strategy.position_size>=1 ?  strategy.position_avg_price * ( 1 - (stopLoss / 100) )  : 0.00⋯//exit partial  position when zmbti crossing down OB level-strategy.close(id="zmbtiLong" , comment="Partial close ZWEIG" ,  qty=strategy.position_size/3 , when=strategy.position_size>=1 and partialCloseIndicator=="ZWEIG" and close>strategy.position_avg_price and crossunder(zmbti, 0.6) )+strategy.close(id="zmbtiLong" , comment="Partial close ZWEIG" ,  qty=strategy.position_size/3 , when=strategy.position_size>=1 and partialCloseIndicator=="ZWEIG" and close>strategy.position_avg_price and ta.crossunder(zmbti, 0.6) )-strategy.close(id="zmbtiLong" , comment="Partial close RSI" ,  qty=strategy.position_size/3 , when=strategy.position_size>=1 and  partialCloseIndicator=="RSI" and close>strategy.position_avg_price and crossunder(myRsi, 90) )+strategy.close(id="zmbtiLong" , comment="Partial close RSI" ,  qty=strategy.position_size/3 , when=strategy.position_size>=1 and  partialCloseIndicator=="RSI" and close>strategy.position_avg_price and ta.crossunder(myRsi, 90) )//exit whole position when zmbti  turns back to OS Level-strategy.close(id="zmbtiLong" , comment="close all" ,   when=strategy.position_size>=1 and  close >strategy.position_avg_price and  crossunder(zmbti , buyEntryAt)  )  +strategy.close(id="zmbtiLong" , comment="close all" ,   when=strategy.position_size>=1 and  close >strategy.position_avg_price and  ta.crossunder(zmbti , buyEntryAt)  )  //exit whole position when stop loss hits⋯

Clean v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 5: input() → input.string()
  • Line 6: input() → input.int()
  • Line 7: input() → input.string()
  • Line 8: input() → input.float()
  • Line 9: input() → input.int()
  • Line 10: input() → input.bool()
9 more edits
  • Line 11: input() → input.string()
  • Line 12: input() → input.bool()
  • Line 13: input() → input.bool()
  • Line 47: when = ta.crossover(zmbti, buyEntryAt) → if block
  • Line 56: when = strategy.position_size>=1 and partialCloseIndicator=="ZWEIG" and close>strategy.position_avg_price and ta.crossunder(zmbti, 0.6) → if block
  • Line 57: when = strategy.position_size>=1 and partialCloseIndicator=="RSI" and close>strategy.position_avg_price and ta.crossunder(myRsi, 90) → if block
  • Line 59: when = strategy.position_size>=1 and close >strategy.position_avg_price and ta.crossunder(zmbti , buyEntryAt) → if block
  • Line 61: when = strategy.position_size>=1 and trailingStop==true and close < trailing_sl → if block
  • Line 62: when = strategy.position_size>=1 and close < stopLossVal → if block
⋯strategy("Zweig Market Breadth Thrust Indicator Strategy", overlay=false, pyramiding=3 , default_qty_type=strategy.percent_of_equity,  default_qty_value=20,  initial_capital=10000, currency=currency.USD)-ma_type   = input("EMA", options=["SMA","EMA","WMA"] )+ma_type   = input.string("EMA", options=["SMA","EMA","WMA"] )-ma_length = input(defval=65, minval=1, title="MA Length")+ma_length = input.int(defval=65, minval=1, title="MA Length")-mkt = input ("NYSE" , options=["NYSE","NASDAQ", "AMEX", "COMBINED"] )+mkt = input.string ("NYSE" , options=["NYSE","NASDAQ", "AMEX", "COMBINED"] )-buyEntryAt = input(0.40, minval=0.10, maxval=0.60)+buyEntryAt = input.float(0.40, minval=0.10, maxval=0.60)-stopLoss = input(title="Stop Loss%", defval=5, minval=1)+stopLoss = input.int(title="Stop Loss%", defval=5, minval=1)-trailingStop        = input(false, title="Trailing Stop")+trailingStop        = input.bool(false, title="Trailing Stop")-partialCloseIndicator = input("RSI", title="Partial Close using Indicator ", options=["ZWEIG", "RSI"])+partialCloseIndicator = input.string("RSI", title="Partial Close using Indicator ", options=["ZWEIG", "RSI"])-colorOBOS        = input(true, title="Color OB/OS")+colorOBOS        = input.bool(true, title="Color OB/OS")-showDecLineThrust= input(false, title="show DecLine Thrust")+showDecLineThrust= input.bool(false, title="show DecLine Thrust")//function⋯/////////////////////////////////////////////////////////////-strategy.entry(id="zmbtiLong" , direction = strategy.long, when=ta.crossover(zmbti, buyEntryAt) )+if ta.crossover(zmbti, buyEntryAt)+    strategy.entry(id="zmbtiLong" , direction = strategy.long )////// Calculate trailing SL⋯//exit partial  position when zmbti crossing down OB level-strategy.close(id="zmbtiLong" , comment="Partial close ZWEIG" ,  qty=strategy.position_size/3 , when=strategy.position_size>=1 and partialCloseIndicator=="ZWEIG" and close>strategy.position_avg_price and ta.crossunder(zmbti, 0.6) )+if strategy.position_size>=1 and partialCloseIndicator=="ZWEIG" and close>strategy.position_avg_price and ta.crossunder(zmbti, 0.6)+    strategy.close(id="zmbtiLong" , comment="Partial close ZWEIG" ,  qty=strategy.position_size/3  )-strategy.close(id="zmbtiLong" , comment="Partial close RSI" ,  qty=strategy.position_size/3 , when=strategy.position_size>=1 and  partialCloseIndicator=="RSI" and close>strategy.position_avg_price and ta.crossunder(myRsi, 90) )+if strategy.position_size>=1 and  partialCloseIndicator=="RSI" and close>strategy.position_avg_price and ta.crossunder(myRsi, 90)+    strategy.close(id="zmbtiLong" , comment="Partial close RSI" ,  qty=strategy.position_size/3  )//exit whole position when zmbti  turns back to OS Level-strategy.close(id="zmbtiLong" , comment="close all" ,   when=strategy.position_size>=1 and  close >strategy.position_avg_price and  ta.crossunder(zmbti , buyEntryAt)  )  +if strategy.position_size>=1 and  close >strategy.position_avg_price and  ta.crossunder(zmbti , buyEntryAt)+    strategy.close(id="zmbtiLong" , comment="close all"   )  //exit whole position when stop loss hits-strategy.close(id="zmbtiLong" , comment="TSL", when=strategy.position_size>=1 and trailingStop==true and close < trailing_sl )  //if trailing stop is set+if strategy.position_size>=1 and trailingStop==true and close < trailing_sl+    strategy.close(id="zmbtiLong" , comment="TSL" )  //if trailing stop is set-strategy.close(id="zmbtiLong" , comment="SL", when=strategy.position_size>=1 and close < stopLossVal )  //if trailing stop is NOT set+if strategy.position_size>=1 and close < stopLossVal+    strategy.close(id="zmbtiLong" , comment="SL" )  //if trailing stop is NOT set

Does it run in Pine Script v6?

No

The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L36:C83: 'linewidth' must be at least 1 in Pine Script v6. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © mohanee-//@version=5+//@version=6strategy("Zweig Market Breadth Thrust Indicator Strategy", overlay=false, pyramiding=3 , default_qty_type=strategy.percent_of_equity,  default_qty_value=20,  initial_capital=10000, currency=currency.USD)⋯

Settings

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

SettingDefaultType and rangeFeeds
MA type (no label in the script)EMAstring · options ["SMA","EMA","WMA"]zmbti zmbtr line 15
MA Length65int · min 1zmbti zmbtr
Mkt (no label in the script)NYSEstring · options ["NYSE","NASDAQ", "AMEX", "COMBINED"]adv dec
Buy Entry At (no label in the script)0.40float · min 0.10 · max 0.60OS DummyOS entry zmbtiLong close zmbtiLong
Stop Loss%5int · min 1sl_val stopLossVal
Trailing Stopfalseboolclose zmbtiLong
Partial Close using Indicator RSIstring · options ["ZWEIG", "RSI"]close zmbtiLong
Color OB/OStrueboolDummyOS DummyOB
show DecLine ThrustfalseboolBreadthThrust(declines)

What it calculates

  • RSI (rsi, ta.rsi in v5)close, 5myRsi · line 30

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.

closecloseprice datamktMktsetting · NYSEma_lengthMA Lengthsetting · 65ma_typeMA typesetting · EMAstopLossStop Loss%setting · 5lowlowprice databuyEntryAtBuy Entry Atsetting · 0.40partialCloseIndicatorPartial Close using Ind…setting · RSImyRsiRSI→ myRsiadv, decadv · dec2 valueszmbti, zmbtrzmbti · zmbtr2 valuessl_valsl_valvaluetrailing_sltrailing_slvaluestopLossValstopLossValvalueentry:zmbtiLongOpen zmbtiLongstrategy.entryclose:zmbtiLongClose zmbtiLongstrategy.closeplot:33OSplotplot:35OBplotplot:36DummyOSplotplot:37DummyOBplotfill:RegionFillRegionFillfillfill:OSFillOSFillfillfill:OBFillOBFillfillplot:41BreadthThrust(advances)plotplot:42BreadthThrust(declines)plot

Order rules

OrderFires whenBy defaultLine
Open zmbtiLong longcrossover(zmbti, buyEntryAt)On47
Close zmbtiLongstrategy.position_size>=1 and partialCloseIndicator=="ZWEIG" and close>strategy.position_avg_price and crossunder(zmbti, 0.6)On56
Close zmbtiLongstrategy.position_size>=1 and partialCloseIndicator=="RSI" and close>strategy.position_avg_price and crossunder(myRsi, 90)On57
Close zmbtiLongstrategy.position_size>=1 and close >strategy.position_avg_price and crossunder(zmbti , buyEntryAt)On59
Close zmbtiLongstrategy.position_size>=1 and trailingStop==true and close < trailing_slOn61
Close zmbtiLongstrategy.position_size>=1 and close < stopLossValOn62

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • ClearHigher-timeframe data2 security call(s), none with lookahead on.
  • 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 timingOrders fill at the next bar's open, after the signal bar has closed.

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

Other markets

Not run on other markets: the script requests ADVN D, DECN D, and that data is not available here (not a Binance spot market; not a Binance spot market). Its results would rest on empty values.

Similar scripts

Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.

ScriptSharesTypeNetTradesMax drawdown
Zweig Market Breadth Thrust Indicator Strategy this page—v4 strategy0.0%00.0%
Triple RSI strategy by Trade_by_DBrsiv5 strategy+3.2%23.3%
Hobbiecode - RSI + Close previous day by hobbiecodersiv5 strategy+1.2%634.2%
dirt cheap yet elegant RSI Strategy by SparkyFlaryrsiv4 strategy−11.4%820.5%
RSI Classic Strategy (by Coinrule) by Coinrulersiv4 strategy+7.5%67.2%
RSITrendStrategy by email_analystsrsiv4 strategy+69.2%2238.6%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 16 msWith a workaround 1,000 bars in 57 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as long = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 47) so the engine trades the way the script says.

“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. PineTS runs Pine Script v5 and v6 only.

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/// © mohanee//@version=4strategy("Zweig Market Breadth Thrust Indicator Strategy", overlay=false, pyramiding=3 , default_qty_type=strategy.percent_of_equity,  default_qty_value=20,  initial_capital=10000, currency=currency.USD)ma_type   = input("EMA", options=["SMA","EMA","WMA"] )ma_length = input(defval=65, minval=1, title="MA Length")mkt = input ("NYSE" , options=["NYSE","NASDAQ", "AMEX", "COMBINED"] )buyEntryAt = input(0.40, minval=0.10, maxval=0.60)stopLoss = input(title="Stop Loss%", defval=5, minval=1)trailingStop        = input(false, title="Trailing Stop")partialCloseIndicator = input("RSI", title="Partial Close using Indicator ", options=["ZWEIG", "RSI"])colorOBOS        = input(true, title="Color OB/OS")showDecLineThrust= input(false, title="show DecLine Thrust")//functiongetMAval(s,l, ma_type) => ma_type== "SMA" ? sma(s,l):  ma_type== "EMA" ? ema(s,l)   : ma_type=="WMA" ?   wma(s,l) : sma(s,l)//calculate Zweig Market Breadth Thrust/////////////////////////////////////////////////////////////res = "D"advn="ADVN", decn="DECN" // NYSEadvnq="ADVQ", decnq="DECQ" // NASDAQadvna="ADVA", decna="DECA" // AMEXadvc="(ADVN+ADVQ+ADVA)/3.0"decc="(DECN+DECQ+DECA)/3.0"adv= security(mkt=="COMBINED" ? advc:mkt == "NYSE" ? advn: mkt == "NASDAQ" ? advnq : mkt == "AMEX" ? advna:na, res, close)   //resdec= security(mkt=="COMBINED" ? decc:mkt == "NYSE" ? decn:mkt == "NASDAQ" ? decnq :  mkt == "AMEX" ? decna:na, res, close)zmbti = getMAval(adv/(adv+dec), ma_length, ma_type)zmbtr = getMAval(dec/(adv+dec), ma_length, ma_type)//calculate Zweig Market Breadth Thrust/////////////////////////////////////////////////////////////myRsi = rsi(close, 5)//Plot/////////////////////////////////////////////////////////////osl=plot(buyEntryAt, color=color.gray, style=plot.style_linebr, title="OS")//osl1=plot(0.45, color=color.blue, style=plot.style_circles, linewidth=2 , title="OS1")obl=plot(0.615, color=color.gray, style=plot.style_linebr, title="OB")osd=plot(colorOBOS?(zmbti<buyEntryAt?zmbti:buyEntryAt):na, style=plot.style_linebr,linewidth=0, title="DummyOS")obd=plot(colorOBOS?(zmbti>0.615?zmbti:0.615):na, style=plot.style_linebr, linewidth=0, title="DummyOB")fill(osl,obl,color.purple, title="RegionFill")fill(osl, osd, color.green, transp=60, title="OSFill")fill(obl, obd, color.red, transp=60, title="OBFill")plot(zmbti, color=color.blue, linewidth=2, title="BreadthThrust(advances)")plot(showDecLineThrust == true ? zmbtr : na, color=color.red, linewidth=2, title="BreadthThrust(declines)")//plot///////////////////////////////////////////////////////////////Strategy/////////////////////////////////////////////////////////////strategy.entry(id="zmbtiLong" , long=true, when=crossover(zmbti, buyEntryAt) )////// Calculate trailing SLsl_val =  close * stopLoss / 100 trailing_sl = 0.0trailing_sl :=   strategy.position_size>=1 ?  max(low  - sl_val, nz(trailing_sl[1])) :  nastopLossVal = strategy.position_size>=1 ?  strategy.position_avg_price * ( 1 - (stopLoss / 100) )  : 0.00//draw initil stop loss//plot(strategy.position_size>=1 ? trailing_sl : na, color = color.blue , style=plot.style_linebr,  linewidth = 2, title = "stop loss")//exit partial  position when zmbti crossing down OB levelstrategy.close(id="zmbtiLong" , comment="Partial close ZWEIG" ,  qty=strategy.position_size/3 , when=strategy.position_size>=1 and partialCloseIndicator=="ZWEIG" and close>strategy.position_avg_price and crossunder(zmbti, 0.6) )strategy.close(id="zmbtiLong" , comment="Partial close RSI" ,  qty=strategy.position_size/3 , when=strategy.position_size>=1 and  partialCloseIndicator=="RSI" and close>strategy.position_avg_price and crossunder(myRsi, 90) )//exit whole position when zmbti  turns back to OS Levelstrategy.close(id="zmbtiLong" , comment="close all" ,   when=strategy.position_size>=1 and  close >strategy.position_avg_price and  crossunder(zmbti , buyEntryAt)  )  //exit whole position when stop loss hitsstrategy.close(id="zmbtiLong" , comment="TSL", when=strategy.position_size>=1 and trailingStop==true and close < trailing_sl )  //if trailing stop is setstrategy.close(id="zmbtiLong" , comment="SL", when=strategy.position_size>=1 and close < stopLossVal )  //if trailing stop is NOT set