Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

sa-strategy with HTF-TSL

A Pine Script v4 strategy built on Supertrend (2, 4), CCI (close, 20) and SMA (tr, 5). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 10 settings; defaults include ATR Period 4, ATR Multiplier 2 and Higher Time Frame 240.

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 sa-strategy with HTF-TSL repaint?
Yes
At least one pattern in the source can repaint: higher-timeframe data.
How did sa-strategy with HTF-TSL 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 sa-strategy with HTF-TSL be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
What alerts does sa-strategy with HTF-TSL have?
1
Intraday Session Close Time.
Does sa-strategy with HTF-TSL use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.

BTCUSDT · 1D · default settings

  • CTF
  • ST
  • EMA 20
  • HMA 15
  • EMA 15
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$100,000$202,527Equity from $100,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. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market. Data the page supplies at the chart's own timeframe (another symbol, or Heikin-Ashi) reaches the script one bar later in Zeal Terminal's engine than on TradingView. The live re-run is not offered here: the script requests heikinashi:SYMBOL D, heikinashi:SYMBOL 30, heikinashi:BINANCE:BTCUSDT D, heikinashi:BINANCE:BTCUSDT 30, BINANCE:BTCUSDT 240, which this page cannot load in your browser.

Needs heikinashi:SYMBOL 30 data, not available: a lower timeframe than the chart; the engine does not evaluate intrabar data Needs heikinashi:BINANCE:BTCUSDT 30 data, not available: a lower timeframe than the chart; the engine does not evaluate intrabar data Needs BINANCE:BTCUSDT 240 data, not available: a lower timeframe than the chart; the engine does not evaluate intrabar data 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, $100,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.

  • 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

    2 settings have no label

    In the settings dialog CCI (line 16), ATR (line 17) 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 121, 122. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 50

    transp = on line 50, 53, 111. v5 folds the transparency into the colour with color.new(c, transp).

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 supertrend → ta.supertrend, security → request.security, heikinashi → ticker.heikinashi, cci → ta.cci, sma → ta.sma, atr → ta.atr, max → math.max, min → math.min, crossunder → ta.crossunder, crossover → ta.crossover, ema → ta.ema, hma → ta.hma, cross → ta.cross, rsi → ta.rsi, floor → math.floor.
  • 2 strategy calls use the when = argument (line 121, 122). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

Same 62 trades and the same P&L on BTCUSDT 4h, 1,000 bars, in Zeal Terminal's engine.

  • Line 3: //@version=4 → //@version=5
  • Line 5: input(type = input.integer) → input.int()
  • Line 6: input(type = input.float) → input.float()
  • Line 7: supertrend → ta.supertrend
  • Line 8: security → request.security
  • Line 8: heikinashi → ticker.heikinashi
49 more edits
  • Line 9: security → request.security
  • Line 9: heikinashi → ticker.heikinashi
  • Line 10: security → request.security
  • Line 10: heikinashi → ticker.heikinashi
  • Line 11: security → request.security
  • Line 11: heikinashi → ticker.heikinashi
  • Line 12: security → request.security
  • Line 12: heikinashi → ticker.heikinashi
  • Line 15: input(type = input.resolution) → input.timeframe()
  • Line 20: cci → ta.cci
  • Line 23: sma → ta.sma
  • Line 23: tr → ta.tr
  • Line 24: sma → ta.sma
  • Line 24: tr → ta.tr
  • Line 50: transp = 0 → color.new(swap4, 0)
  • Line 51: security → request.security
  • Line 52: security → request.security
  • Line 53: transp = 0 → color.new(htfswap4, 0)
  • Line 56: atr → ta.atr
  • Line 57: atr → ta.atr
  • Line 60: max → math.max
  • Line 62: min → math.min
  • Line 75: crossunder → ta.crossunder
  • Line 75: crossunder → ta.crossunder
  • Line 75: crossunder → ta.crossunder
  • Line 76: crossover → ta.crossover
  • Line 76: crossover → ta.crossover
  • Line 76: crossover → ta.crossover
  • Line 78: ema → ta.ema
  • Line 79: hma → ta.hma
  • Line 80: ema → ta.ema
  • Line 81: hma → ta.hma
  • Line 81: hma → ta.hma
  • Line 81: ema → ta.ema
  • Line 81: ema → ta.ema
  • Line 82: hma → ta.hma
  • Line 82: hma → ta.hma
  • Line 82: ema → ta.ema
  • Line 82: ema → ta.ema
  • Line 85: cross → ta.cross
  • Line 88: rsi → ta.rsi
  • Line 89: cross → ta.cross
  • Line 103: input(type = input.integer) → input.int()
  • Line 104: input(type = input.integer) → input.int()
  • Line 105: input(type = input.bool) → input.bool()
  • Line 106: floor → math.floor
  • Line 111: transp = 40 → color.new(exitTime and not exitTime[1] and bgc ? #445566 : na, 40)
  • Line 121: cross → ta.cross
  • Line 122: cross → ta.cross
⋯// © ringashish-//@version=4+//@version=5strategy("sa-strategy with HTF-TSL", overlay=true)-Pd = input(title="ATR Period", type=input.integer, defval=4)+Pd = input.int(title="ATR Period", defval=4)-Factor = input(title="ATR Multiplier", type=input.float, step=0.1, defval=2)+Factor = input.float(title="ATR Multiplier", step=0.1, defval=2)-ST= supertrend(Factor, Pd)+ST= ta.supertrend(Factor, Pd)-heikinashi_close = security(heikinashi(syminfo.tickerid), timeframe.period, close)+heikinashi_close = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close)-heikinashi_low = security(heikinashi(syminfo.tickerid), timeframe.period, low)+heikinashi_low = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, low)-heikinashi_open = security(heikinashi(syminfo.tickerid), timeframe.period, open)+heikinashi_open = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, open)-heikinashi_high = security(heikinashi(syminfo.tickerid), timeframe.period, high)+heikinashi_high = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, high)-heikinashi_close30 = security(heikinashi(syminfo.tickerid), "30", close)+heikinashi_close30 = request.security(ticker.heikinashi(syminfo.tickerid), "30", close)//res1 = input("30", type=input.resolution, title="higher Timeframe")//CCI TSL-res = input("240",type=input.resolution,title = "Higher Time Frame")+res = input.timeframe("240",title = "Higher Time Frame")CCI = input(20)⋯original=input(false,title='original coloring')-thisCCI = cci(close, CCI)+thisCCI = ta.cci(close, CCI)lastCCI = nz(thisCCI[1])calcx()=> -    bufferDn= high + Multiplier * sma(tr,ATR)+    bufferDn= high + Multiplier * ta.sma(ta.tr,ATR)-    bufferUp= low - Multiplier * sma(tr,ATR)+    bufferUp= low - Multiplier * ta.sma(ta.tr,ATR)    if (thisCCI >= 0 and lastCCI < 0) ⋯//display current timeframe's Trend-plot(tempx,"CTF",color=swap4,transp=0,linewidth=2, style = plot.style_stepline)+plot(tempx,"CTF",color=color.new(swap4, 0),linewidth=2, style = plot.style_stepline)-htfx = security(syminfo.tickerid,res,tempx[1],lookahead = barmerge.lookahead_on)+htfx = request.security(syminfo.tickerid,res,tempx[1],lookahead = barmerge.lookahead_on)-htfswap4 = security(syminfo.tickerid,res,swap4[1],lookahead = barmerge.lookahead_on)+htfswap4 = request.security(syminfo.tickerid,res,swap4[1],lookahead = barmerge.lookahead_on)-plot(htfx,"HTF",color=htfswap4,transp=0,linewidth=3,style = plot.style_stepline)+plot(htfx,"HTF",color=color.new(htfswap4, 0),linewidth=3,style = plot.style_stepline)//supertrendSupertrend(Factor, Pd) =>-    Up=hl2-(Factor*atr(Pd))+    Up=hl2-(Factor*ta.atr(Pd))-    Dn=hl2+(Factor*atr(Pd))+    Dn=hl2+(Factor*ta.atr(Pd))        TrendUp = 0.0-    TrendUp := heikinashi_close[1]>TrendUp[1] ? max(Up,TrendUp[1]) : Up+    TrendUp := heikinashi_close[1]>TrendUp[1] ? math.max(Up,TrendUp[1]) : Up    TrendDown = 0.0-    TrendDown := heikinashi_close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn+    TrendDown := heikinashi_close[1]<TrendDown[1]? math.min(Dn,TrendDown[1]) : Dn    Trend = 0.0⋯//plot(ST1_Trend_MTF, "higher ST") -crossdn = crossunder(heikinashi_close,Tsl) or crossunder(heikinashi_close[1],Tsl) or crossunder(heikinashi_close[2],Tsl) or heikinashi_close < Tsl+crossdn = ta.crossunder(heikinashi_close,Tsl) or ta.crossunder(heikinashi_close[1],Tsl) or ta.crossunder(heikinashi_close[2],Tsl) or heikinashi_close < Tsl-crossup = crossover(heikinashi_close,Tsl) or crossover(heikinashi_close[1],Tsl) or crossover(heikinashi_close[2],Tsl) or heikinashi_close > Tsl+crossup = ta.crossover(heikinashi_close,Tsl) or ta.crossover(heikinashi_close[1],Tsl) or ta.crossover(heikinashi_close[2],Tsl) or heikinashi_close > Tslplot(Tsl,"ST",color = color.black,linewidth =2)-plot(ema(heikinashi_close,20),"EMA 20",color=color.red)+plot(ta.ema(heikinashi_close,20),"EMA 20",color=color.red)-plot(hma(heikinashi_close,15),"HMA 15",color=color.green)+plot(ta.hma(heikinashi_close,15),"HMA 15",color=color.green)-plot(ema(heikinashi_close,15),"EMA 15",color=color.black)+plot(ta.ema(heikinashi_close,15),"EMA 15",color=color.black)-closedown = (heikinashi_close < hma(heikinashi_close,15) and heikinashi_high > hma(heikinashi_close,15)) or(heikinashi_close < ema(heikinashi_close,20) and heikinashi_high > ema(heikinashi_close,20))+closedown = (heikinashi_close < ta.hma(heikinashi_close,15) and heikinashi_high > ta.hma(heikinashi_close,15)) or(heikinashi_close < ta.ema(heikinashi_close,20) and heikinashi_high > ta.ema(heikinashi_close,20))-closeup = (heikinashi_close > hma(heikinashi_close,15) and heikinashi_low < hma(heikinashi_close,15)) or (heikinashi_close > ema(heikinashi_close,20) and heikinashi_low < ema(heikinashi_close,20))+closeup = (heikinashi_close > ta.hma(heikinashi_close,15) and heikinashi_low < ta.hma(heikinashi_close,15)) or (heikinashi_close > ta.ema(heikinashi_close,20) and heikinashi_low < ta.ema(heikinashi_close,20))buy = heikinashi_open == heikinashi_low and closeup and crossup  and close > htfx//buy = heikinashi_open == heikinashi_low and heikinashi_close > ema(close,20) and heikinashi_low < ema(close,20) and crossup-buyexit = cross(close,tempx) //heikinashi_open == heikinashi_high //and heikinashi_close < ema(close,15) and heikinashi_high > ema(close,15)+buyexit = ta.cross(close,tempx) //heikinashi_open == heikinashi_high //and heikinashi_close < ema(close,15) and heikinashi_high > ema(close,15)//if heikinashi_close30[1] < ST1_Trend_MTF//sell = heikinashi_open == heikinashi_high and heikinashi_close < ema(close,20) and heikinashi_high > ema(close,20) and rsi(close,14)<60 and crossdn-sell = heikinashi_open == heikinashi_high and closedown and rsi(close,14)<55 and crossdn  and close < htfx+sell = heikinashi_open == heikinashi_high and closedown and ta.rsi(close,14)<55 and crossdn  and close < htfx-sellexit = cross(close,tempx) //heikinashi_open == heikinashi_low //and heikinashi_close > ema(close,15) and heikinashi_low < ema(close,15)+sellexit = ta.cross(close,tempx) //heikinashi_open == heikinashi_low //and heikinashi_close > ema(close,15) and heikinashi_low < ema(close,15)rg = 0⋯//Exit at particular time-ExitHour = input(title="Exit Hour Of Day", type=input.integer, defval=15, step = 5, maxval = 24, minval = 0)+ExitHour = input.int(title="Exit Hour Of Day", defval=15, step = 5, maxval = 24, minval = 0)-ExitMint = input(title="Exit Minute Of Day", type=input.integer, defval=15, step = 5, maxval = 24, minval = 0)+ExitMint = input.int(title="Exit Minute Of Day", defval=15, step = 5, maxval = 24, minval = 0)-bgc = input(title="Highlight Background Color?", type=input.bool, defval=true)+bgc = input.bool(title="Highlight Background Color?", defval=true)-mRound(num,rem) => (floor(num/rem)*rem)+mRound(num,rem) => (math.floor(num/rem)*rem)exitTime = (hour(time) >= ExitHour and (minute == mRound(ExitMint, timeframe.multiplier))) ? 1 : 0⋯alertcondition(exitTime and not exitTime[1], title="Intraday Session Close Time", message="Close All Positions")-bgcolor(exitTime and not exitTime[1] and bgc ? #445566 : na, transp =40)+bgcolor(color.new(exitTime and not exitTime[1] and bgc ? #445566 : na, 40))longCondition = longLogic⋯    -strategy.close("short", when =cross(close,tempx)  or MarketClose)+strategy.close("short", when =ta.cross(close,tempx)  or MarketClose)-strategy.close( "long", when =cross(close,tempx) or MarketClose )+strategy.close( "long", when =ta.cross(close,tempx) or MarketClose )

Clean v5

VerifiedDownload the v5 script

Same 62 trades and the same P&L on BTCUSDT 4h, 1,000 bars, in Zeal Terminal's engine.

  • Line 16: input() → input.int()
  • Line 17: input() → input.int()
  • Line 18: input() → input.int()
  • Line 19: input() → input.bool()
  • Line 121: when = ta.cross(close,tempx) or MarketClose → if block
  • Line 122: when = ta.cross(close,tempx) or MarketClose → if block
⋯res = input.timeframe("240",title = "Higher Time Frame")-CCI = input(20)+CCI = input.int(20)-ATR = input(5)+ATR = input.int(5)-Multiplier=input(1,title='ATR Multiplier')+Multiplier=input.int(1,title='ATR Multiplier')-original=input(false,title='original coloring')+original=input.bool(false,title='original coloring')thisCCI = ta.cci(close, CCI)⋯    -strategy.close("short", when =ta.cross(close,tempx)  or MarketClose)+if ta.cross(close,tempx)  or MarketClose+    strategy.close("short")-strategy.close( "long", when =ta.cross(close,tempx) or MarketClose )+if ta.cross(close,tempx) or MarketClose+    strategy.close( "long" )

Does it run in Pine Script v6?

No

The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 62 before, 43 after on BTCUSDT 4h, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © ringashish-//@version=5+//@version=6strategy("sa-strategy with HTF-TSL", overlay=true)⋯

Settings

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

SettingDefaultType and rangeFeeds
ATR Period4int (written input.integer)ST Up Dn Trend Tsl
ATR Multiplier2float · step 0.1ST Up Dn Trend Tsl
Higher Time Frame240timeframe (written input.resolution)htfx htfswap4
CCI (no label in the script)20intthisCCI
ATR (no label in the script)5intbufferDn bufferUp
ATR Multiplier1intbufferDn bufferUp
original coloringfalseboolswap4
Exit Hour Of Day15int (written input.integer) · min 0 · max 24 · step 5exitTime
Exit Minute Of Day15int (written input.integer) · min 0 · max 24 · step 5exitTime
Highlight Background Color?trueboolbgcolor

What it calculates

  • Supertrend (supertrend, ta.supertrend in v5)ATR Multiplier (2), ATR Period (4)ST · line 7
  • CCI (cci, ta.cci in v5)close, CCI (20)thisCCI · line 20
  • SMA (sma, ta.sma in v5)tr, ATR (5)bufferDn · line 23
  • SMA (sma, ta.sma in v5)tr, ATR (5)bufferUp · line 24
  • ATR (atr, ta.atr in v5)ATR Period (4)Up · line 56
  • ATR (atr, ta.atr in v5)ATR Period (4)Dn · line 57
  • Cross (cross, ta.cross in v5)close, tempxbuyexit · line 85
  • Cross (cross, ta.cross in v5)close, tempxsellexit · line 89

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 63 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open long long(longCondition)On114
Open short short(shortCondition)On119
Close shortcross(close,tempx) or MarketCloseOn121
Close longcross(close,tempx) or MarketCloseOn122

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

Alerts

AlertCallMessageLine
Intraday Session Close TimealertconditionClose All Positions110

Does it repaint?

Yes

At least one pattern in the source can repaint; it is marked Check below.

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.
  • CheckHigher-timeframe data2 security call(s) use lookahead_on (line 51, 52). Without a [1] offset this reads future bars in history.
  • 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 heikinashi:SYMBOL 30, heikinashi:BINANCE:BTCUSDT 30, BINANCE:BTCUSDT 240, and that data is not available here (a lower timeframe than the chart; the engine does not evaluate intrabar data; a lower timeframe than the chart; the engine does not evaluate intrabar data; a lower timeframe than the chart; the engine does not evaluate intrabar data). 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
sa-strategy with HTF-TSL this page—v4 strategy0.0%00.0%
Super Scalp 007 by MA_Seifisma atr crossv4 strategy−23.2%1238.1%
Golden Swing Strategy - Souradeep Dey by rajm14sma atr supertrendv5 strategy−0.0%110.0%
AlignedMA and Cumulative HighLow Strategy V2 by Trendoscopesma atr supertrendv4 strategy−40.8%1650.9%
3x Supertrend and Stoch RSI by M3RZIsupertrend sma atrv4 strategy−128.7%24207.6%
Moving Average Crossover Strategy by Decam9sma atr crossv5 strategy+0.0%754.3%

Where it runs

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

The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market. Data the page supplies at the chart's own timeframe (another symbol, or Heikin-Ashi) reaches the script one bar later in Zeal Terminal's engine than on TradingView.

“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/// © ringashish//@version=4strategy("sa-strategy with HTF-TSL", overlay=true)Pd = input(title="ATR Period", type=input.integer, defval=4)Factor = input(title="ATR Multiplier", type=input.float, step=0.1, defval=2)ST= supertrend(Factor, Pd)heikinashi_close = security(heikinashi(syminfo.tickerid), timeframe.period, close)heikinashi_low = security(heikinashi(syminfo.tickerid), timeframe.period, low)heikinashi_open = security(heikinashi(syminfo.tickerid), timeframe.period, open)heikinashi_high = security(heikinashi(syminfo.tickerid), timeframe.period, high)heikinashi_close30 = security(heikinashi(syminfo.tickerid), "30", close)//res1 = input("30", type=input.resolution, title="higher Timeframe")//CCI TSLres = input("240",type=input.resolution,title = "Higher Time Frame")CCI = input(20)ATR = input(5)Multiplier=input(1,title='ATR Multiplier')original=input(false,title='original coloring')thisCCI = cci(close, CCI)lastCCI = nz(thisCCI[1])calcx()=>     bufferDn= high + Multiplier * sma(tr,ATR)    bufferUp= low - Multiplier * sma(tr,ATR)    if (thisCCI >= 0 and lastCCI < 0)         bufferUp := bufferDn[1]    if (thisCCI <= 0 and lastCCI > 0)         bufferDn := bufferUp[1]    if (thisCCI >= 0)        if (bufferUp < bufferUp[1])            bufferUp := bufferUp[1]    else        if (thisCCI <= 0)            if (bufferDn > bufferDn[1])                bufferDn := bufferDn[1]       x = 0.0    x := thisCCI >= 0 ?bufferUp:thisCCI <= 0 ?bufferDn:x[1]    xtempx = calcx()calcswap() =>    swap = 0.0    swap := tempx>tempx[1]?1:tempx<tempx[1]?-1:swap[1]    swaptempswap = calcswap()swap2=tempswap==1?color.blue:color.orangeswap3=thisCCI >=0 ?color.blue:color.orangeswap4=original?swap3:swap2//display current timeframe's Trendplot(tempx,"CTF",color=swap4,transp=0,linewidth=2, style = plot.style_stepline)htfx = security(syminfo.tickerid,res,tempx[1],lookahead = barmerge.lookahead_on)htfswap4 = security(syminfo.tickerid,res,swap4[1],lookahead = barmerge.lookahead_on)plot(htfx,"HTF",color=htfswap4,transp=0,linewidth=3,style = plot.style_stepline)//supertrendSupertrend(Factor, Pd) =>    Up=hl2-(Factor*atr(Pd))    Dn=hl2+(Factor*atr(Pd))        TrendUp = 0.0    TrendUp := heikinashi_close[1]>TrendUp[1] ? max(Up,TrendUp[1]) : Up    TrendDown = 0.0    TrendDown := heikinashi_close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn    Trend = 0.0    Trend := heikinashi_close > TrendDown[1] ? 1: heikinashi_close< TrendUp[1]? -1: nz(Trend[1],1)    Tsl = Trend==1? TrendUp: TrendDown        S_Buy = Trend == 1 ? 1 : 0    S_Sell = Trend != 1 ? 1 : 0        [Trend, Tsl][Trend,Tsl] = Supertrend(Factor, Pd)// Security//ST1_Trend_MTF = security(syminfo.tickerid, res1, Tsl,barmerge.lookahead_on)//plot(ST1_Trend_MTF, "higher ST") crossdn = crossunder(heikinashi_close,Tsl) or crossunder(heikinashi_close[1],Tsl) or crossunder(heikinashi_close[2],Tsl) or heikinashi_close < Tslcrossup = crossover(heikinashi_close,Tsl) or crossover(heikinashi_close[1],Tsl) or crossover(heikinashi_close[2],Tsl) or heikinashi_close > Tslplot(Tsl,"ST",color = color.black,linewidth =2)plot(ema(heikinashi_close,20),"EMA 20",color=color.red)plot(hma(heikinashi_close,15),"HMA 15",color=color.green)plot(ema(heikinashi_close,15),"EMA 15",color=color.black)closedown = (heikinashi_close < hma(heikinashi_close,15) and heikinashi_high > hma(heikinashi_close,15)) or(heikinashi_close < ema(heikinashi_close,20) and heikinashi_high > ema(heikinashi_close,20))closeup = (heikinashi_close > hma(heikinashi_close,15) and heikinashi_low < hma(heikinashi_close,15)) or (heikinashi_close > ema(heikinashi_close,20) and heikinashi_low < ema(heikinashi_close,20))buy = heikinashi_open == heikinashi_low and closeup and crossup  and close > htfx//buy = heikinashi_open == heikinashi_low and heikinashi_close > ema(close,20) and heikinashi_low < ema(close,20) and crossupbuyexit = cross(close,tempx) //heikinashi_open == heikinashi_high //and heikinashi_close < ema(close,15) and heikinashi_high > ema(close,15)//if heikinashi_close30[1] < ST1_Trend_MTF//sell = heikinashi_open == heikinashi_high and heikinashi_close < ema(close,20) and heikinashi_high > ema(close,20) and rsi(close,14)<60 and crossdnsell = heikinashi_open == heikinashi_high and closedown and rsi(close,14)<55 and crossdn  and close < htfxsellexit = cross(close,tempx) //heikinashi_open == heikinashi_low //and heikinashi_close > ema(close,15) and heikinashi_low < ema(close,15)rg = 0rg := buy ? 1 : buyexit ? 2 : nz(rg[1])longLogic = rg != rg[1] and rg == 1 longExit = rg != rg[1] and rg == 2 //plotshape(longExit,"exit buy",style = shape.arrowup,location = location.belowbar,color = color.red, text ="buy exit", textcolor = color.red)//plotshape(longLogic,"BUY",style = shape.arrowup,location = location.belowbar,color = color.green, text ="buy", textcolor= color.green)nm = 0nm := sell ? 1 : sellexit ? 2 : nz(nm[1])shortLogic = nm != nm[1] and nm == 1 shortExit = nm != nm[1] and nm == 2 //plotshape(shortExit,"exit sell",style = shape.arrowup,location = location.belowbar,color = color.red, text ="sell exit", textcolor = color.red)//plotshape(shortLogic,"SELL",style = shape.arrowup,location = location.belowbar,color = color.green, text ="sell", textcolor= color.green)//Exit at particular timeExitHour = input(title="Exit Hour Of Day", type=input.integer, defval=15, step = 5, maxval = 24, minval = 0)ExitMint = input(title="Exit Minute Of Day", type=input.integer, defval=15, step = 5, maxval = 24, minval = 0)bgc = input(title="Highlight Background Color?", type=input.bool, defval=true)mRound(num,rem) => (floor(num/rem)*rem)exitTime = (hour(time) >= ExitHour and (minute == mRound(ExitMint, timeframe.multiplier))) ? 1 : 0exitTime := exitTime == 0 ? (hour(time) >= ExitHour and (minute + timeframe.multiplier >= ExitMint)) ? 1 : 0 : exitTimeMarketClose =  exitTime and not exitTime[1]alertcondition(exitTime and not exitTime[1], title="Intraday Session Close Time", message="Close All Positions")bgcolor(exitTime and not exitTime[1] and bgc ? #445566 : na, transp =40)longCondition = longLogicif (longCondition)    strategy.entry("long", strategy.long)     shortCondition = shortLogicif (shortCondition)    strategy.entry("short", strategy.short)    strategy.close("short", when =cross(close,tempx)  or MarketClose)strategy.close( "long", when =cross(close,tempx) or MarketClose )