Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

High-low crypto strategy with MACD-PSAR-ATR-EWave

A Pine Script v4 strategy built on SMA or EMA (close, 12), 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 use a stop loss and a profit target. Each trade is one contract and pays no commission. 19 settings; defaults include Fast Length 12, Slow Length 26 and Source close.

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 High-low crypto strategy with MACD-PSAR-ATR-EWave repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 4 of 4 trades.
How did High-low crypto strategy with MACD-PSAR-ATR-EWave do on BTCUSDT 1D with default settings?
+15.93%
From 26 Jan 2024 to 21 Oct 2026, over 17 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can High-low crypto strategy with MACD-PSAR-ATR-EWave 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.
Does High-low crypto strategy with MACD-PSAR-ATR-EWave use a stop loss?
Yes
strategy.exit sets a stop on line 121, 123.
Does High-low crypto strategy with MACD-PSAR-ATR-EWave run in Zeal Terminal?
Yes
It compiles in 40 ms and runs 1,000 bars in 62 ms, in the browser.

BTCUSDT · 1D · default settings

  • SMA
  • SMA
  • SMA
  • SMA
  • SMA
  • SMA
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (19)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOctCCI$115,933$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. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference. Zeal Terminal's engine currently reads an order side written as 1, 0 as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 119, 120) so the engine trades the way the script says.
Net profit
+15.93%
$15,932.60
Buy and hold
+102.5%
same period
Closed trades
17
2 won · 15 lost
Profitable
11.8%
of closed trades
Profit factor
3.44
gross profit ÷ gross loss
Max drawdown
3.16%
−$3,777.93

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 commission

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

  • Note

    7 settings have no label

    In the settings dialog start (line 12), increment (line 13), maximum (line 14), CCI (line 80), ATR (line 81), sma1length (line 108), sma2length (line 109) 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 119, 120. The upgraded version below moves each call inside an if block.

  • Note

    Uses iff(), which v5 removed line 111

    iff() on line 111. v5 writes it as the ternary c ? a : b.

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 max → math.max, min → math.min, sma → ta.sma, ema → ta.ema, cci → ta.cci.
  • 2 strategy calls use the when = argument (line 119, 120). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

Same 17 trades and the same P&L on BTCUSDT 1D, 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.integer) → input.int()
  • Line 7: input(type = input.source) → input.source()
  • Line 8: input(type = input.integer) → input.int()
  • Line 9: input(type = input.bool) → input.bool()
28 more edits
  • Line 10: input(type = input.bool) → input.bool()
  • Line 46: max → math.max
  • Line 53: min → math.min
  • Line 60: min → math.min
  • Line 64: min → math.min
  • Line 66: min → math.min
  • Line 68: min → math.min
  • Line 70: max → math.max
  • Line 72: max → math.max
  • Line 75: sma → ta.sma
  • Line 75: ema → ta.ema
  • Line 76: sma → ta.sma
  • Line 76: ema → ta.ema
  • Line 78: sma → ta.sma
  • Line 78: ema → ta.ema
  • Line 84: cci → ta.cci
  • Line 86: sma → ta.sma
  • Line 86: tr → ta.tr
  • Line 87: sma → ta.sma
  • Line 87: tr → ta.tr
  • Line 110: input(type = input.bool) → input.bool()
  • Line 111: iff(c, a, b) → (c ? a : b)
  • Line 111: sma → ta.sma
  • Line 111: sma → ta.sma
  • Line 111: sma → ta.sma
  • Line 111: sma → ta.sma
  • Line 119: strategy.entry(…, 1) → strategy.entry(…, strategy.long)
  • Line 120: strategy.entry(…, 0) → strategy.entry(…, strategy.short)
⋯// © SoftKill21-//@version=4+//@version=5strategy("Crypto strategy high/low", overlay=true)-fast_length = input(title="Fast Length", type=input.integer, defval=12)+fast_length = input.int(title="Fast Length", defval=12)-slow_length = input(title="Slow Length", type=input.integer, defval=26)+slow_length = input.int(title="Slow Length", defval=26)-src = input(title="Source", type=input.source, defval=close)+src = input.source(title="Source", defval=close)-signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)+signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9)-sma_source = input(title="Simple MA(Oscillator)", type=input.bool, defval=true)+sma_source = input.bool(title="Simple MA(Oscillator)", defval=true)-sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=false)+sma_signal = input.bool(title="Simple MA(Signal Line)", defval=false)//sar⋯            uptrend := false-            SAR := max(EP, high)+            SAR := math.max(EP, high)            EP := low⋯            uptrend := true-            SAR := min(EP, low)+            SAR := math.min(EP, low)            EP := high⋯                EP := high-                AF := min(AF + increment, maximum)+                AF := math.min(AF + increment, maximum)        else⋯                EP := low-                AF := min(AF + increment, maximum)+                AF := math.min(AF + increment, maximum)    if uptrend-        SAR := min(SAR, low[1])+        SAR := math.min(SAR, low[1])        if bar_index > 1-            SAR := min(SAR, low[2])+            SAR := math.min(SAR, low[2])    else-        SAR := max(SAR, high[1])+        SAR := math.max(SAR, high[1])        if bar_index > 1-            SAR := max(SAR, high[2])+            SAR := math.max(SAR, high[2])    nextBarSAR := SAR + AF * (EP - SAR)// Calculating-fast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length)+fast_ma = sma_source ? ta.sma(src, fast_length) : ta.ema(src, fast_length)-slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)+slow_ma = sma_source ? ta.sma(src, slow_length) : ta.ema(src, slow_length)macd = fast_ma - slow_ma-signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)+signal = sma_signal ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)hist = macd - signal⋯original=input(true,title='original coloring')-thisCCI = cci(close, CCI)+thisCCI = ta.cci(close, CCI)lastCCI = nz(thisCCI[1])-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) ⋯sma2length = input(35)-UsePercent = input(title="Show Dif as percent of current Candle", type=input.bool, defval=true)+UsePercent = input.bool(title="Show Dif as percent of current Candle", defval=true)-smadif=iff(UsePercent,(sma(srce, sma1length) - sma(srce, sma2length)) / srce * 100, sma(srce, sma1length) - sma(srce, sma2length))+smadif=(UsePercent ? (ta.sma(srce, sma1length) - ta.sma(srce, sma2length)) / srce * 100 : ta.sma(srce, sma1length) - ta.sma(srce, sma2length))col=smadif <= 0 ? color.red : color.green⋯sl=input(0.005, title="sl")-strategy.entry("long",1,when=longC)+strategy.entry("long",strategy.long,when=longC)-strategy.entry("short",0,when=shortC)+strategy.entry("short",strategy.short,when=shortC)strategy.exit("x_long", "long" ,loss = close * sl / syminfo.mintick, profit = close * tp / syminfo.mintick , alert_message = "closelong")⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 12: input() → input.float()
  • Line 13: input() → input.float()
  • Line 14: input() → input.float()
  • Line 80: input() → input.int()
  • Line 81: input() → input.int()
  • Line 82: input() → input.int()
8 more edits
  • Line 83: input() → input.bool()
  • Line 107: input() → input.source()
  • Line 108: input() → input.int()
  • Line 109: input() → input.int()
  • Line 117: input() → input.float()
  • Line 118: input() → input.float()
  • Line 119: when = longC → if block
  • Line 120: when = shortC → if block
⋯//sar-start = input(0.02)+start = input.float(0.02)-increment = input(0.02)+increment = input.float(0.02)-maximum = input(0.2)+maximum = input.float(0.2)var bool uptrend = na⋯hist = macd - signal-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(true,title='original coloring')+original=input.bool(true,title='original coloring')thisCCI = ta.cci(close, CCI)⋯//elliot wave-srce = input(close, title="source")+srce = input.source(close, title="source")-sma1length = input(5)+sma1length = input.int(5)-sma2length = input(35)+sma2length = input.int(35)UsePercent = input.bool(title="Show Dif as percent of current Candle", defval=true)⋯//shortC = low < low[1] and low[1] < low[2] and low[2] < low[3] and low[3] < low[4] and close[4] < low[5]-tp=input(0.15, title="tp")+tp=input.float(0.15, title="tp")-sl=input(0.005, title="sl")+sl=input.float(0.005, title="sl")-strategy.entry("long",strategy.long,when=longC)+if longC+    strategy.entry("long",strategy.long)-strategy.entry("short",strategy.short,when=shortC)+if shortC+    strategy.entry("short",strategy.short)strategy.exit("x_long", "long" ,loss = close * sl / syminfo.mintick, profit = close * tp / syminfo.mintick , alert_message = "closelong")⋯

Does it run in Pine Script v6?

No

The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L15:C0: a 'bool' cannot be 'na' in Pine Script v6 — declare it as true or false. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © SoftKill21-//@version=5+//@version=6strategy("Crypto strategy high/low", 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
Fast Length12int (written input.integer)fast_ma
Slow Length26int (written input.integer)slow_ma
Sourceclosesourcefast_ma slow_ma
Signal Smoothing9int (written input.integer) · min 1 · max 50signal
Simple MA(Oscillator)trueboolfast_ma slow_ma
Simple MA(Signal Line)falseboolsignal
Start (no label in the script)0.02floatSAR AF
Increment (no label in the script)0.02floatAF
Maximum (no label in the script)0.2floatAF
CCI (no label in the script)20intthisCCI
ATR (no label in the script)5intbufferDn bufferUp
ATR Multiplier1intbufferDn bufferUp
original coloringtrueboolswap4
sourceclosesourcesmadif
Sma1length (no label in the script)5intsmadif
Sma2length (no label in the script)35intsmadif
Show Dif as percent of current Candletrueboolsmadif
tp0.15floatexit x_long exit x_short
sl0.005floatexit x_long exit x_short

What it calculates

  • SMA / EMA (sma, ta.sma in v5)Source (close), Fast Length (12)fast_ma · line 75
  • SMA / EMA (sma, ta.sma in v5)Source (close), Slow Length (26)slow_ma · line 76
  • SMA / EMA (sma, ta.sma in v5)macd, Signal Smoothing (9)signal · line 78
  • CCI (cci, ta.cci in v5)close, CCI (20)thisCCI · line 84
  • SMA (sma, ta.sma in v5)tr, ATR (5)bufferDn · line 86
  • SMA (sma, ta.sma in v5)tr, ATR (5)bufferUp · line 87
  • SMA (sma, ta.sma in v5)source (close), Sma1length (5)smadif · line 111

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 datafast_lengthFast Lengthsetting · 12slow_lengthSlow Lengthsetting · 26signal_lengthSignal Smoothingsetting · 9CCICCIsetting · 20highhighprice dataMultiplierATR Multipliersetting · 1ATRATRsetting · 5lowlowprice datasma1lengthSma1lengthsetting · 5sma2lengthSma2lengthsetting · 35startStartsetting · 0.02incrementIncrementsetting · 0.02maximumMaximumsetting · 0.2fast_maSMA / EMA→ fast_maslow_maSMA / EMA→ slow_masignalSMA / EMA→ signalthisCCICCI→ thisCCIbufferDnSMA→ bufferDnbufferUpSMA→ bufferUpsmadifSMA→ smadifEP, prevEPEP · prevEP2 valuesSARSARvalueAFAFvaluenextBarSARnextBarSARvalueprevSARprevSARvaluelowPrevlowPrevvaluehighPrevhighPrevvaluecloseCur, closePrevcloseCur · closePrev2 valuesmacdmacdvaluehisthistvaluelastCCIlastCCIvaluexxvalueswapswapvalueswap4swap4valueswap2, swap3, col, longC, shortCColourswap2 · swap3 +3entry:longOpen longstrategy.entryentry:shortOpen shortstrategy.entryexit:x_longexit x_longstrategy.exitexit:x_shortexit x_shortstrategy.exit

Order rules

OrderFires whenBy defaultLine
Open long longlongCOn119
Open short shortshortCOn120
Exit x_long stop and limitevery barOn121
Exit x_short stop and limitevery barOn123

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, and the live replay matched history.

4/4trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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 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

The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+15.9%+102.5%1712%3.443.2%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+8.0%+5.5%1315%2.962.2%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−0.2%+9.8%120%0.000.2%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.1%+8.4%80%0.000.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−0.0%+16.7%190%0.000.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%100%0.000.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.1%+148.3%180%0.000.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.0%+17.1%120%0.000.0%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market813%$10,393.40
Sideways market617%$6,892.11
Falling market30%−$1,352.82

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

5.2%

The 95th percentile of the worst drawdown when the same 17 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 2.4% to 5.2%; the tick is what actually happened, 3.2%. Order luck alone moves it this much.

0%6%
All 17 trades
SideEntryExitBarsP&L
long16 Jul 2024 64,724.1016 Jul 2024 64,400.400−$323.63
long17 Jul 2024 65,044.0017 Jul 2024 64,718.800−$325.22
short2 Aug 2024 65,354.005 Aug 2024 56,629.903$8,724.15
short3 Oct 2024 60,649.303 Oct 2024 60,952.500−$303.25
short4 Oct 2024 60,752.704 Oct 2024 61,056.500−$303.77
short21 Dec 2024 97,805.4021 Dec 2024 98,294.500−$489.03
long17 Jan 2025 99,987.3027 Jan 2025 99,474.2010−$513.10
short3 Feb 2025 97,700.603 Feb 2025 98,189.100−$488.51
short4 Feb 2025 101,329.0025 Feb 2025 87,595.6021$13,732.90
short1 Jun 2025 104,592.001 Jun 2025 105,115.000−$522.96
short3 Aug 2025 112,546.003 Aug 2025 113,109.000−$562.74
long11 Sep 2025 113,960.0022 Sep 2025 113,384.0011−$576.17
long10 Dec 2025 92,678.8010 Dec 2025 92,215.400−$463.40
short21 Jan 2026 88,427.7021 Jan 2026 88,869.800−$442.14
short22 Jan 2026 89,454.7022 Jan 2026 89,902.000−$447.28
short19 May 2026 77,001.9019 May 2026 77,386.900−$385.01
short16 Sep 2026 75,644.5016 Sep 2026 76,022.700−$378.23

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
High-low crypto strategy with MACD-PSAR-ATR-EWave this page—v4 strategy+15.9%173.2%
Momentum Explosion 2CCI RSI by capamema sma cciv4 strategy+24.1%642.3%
MACD Long Strat by TheGrindTodayema smav4 strategy+24.0%7920.1%
Stock trending strategy by exlux99ema smav4 strategy+35.3%2114.7%
4-Hour Stochastic EMA Trend by slymnturkogluema smav4 strategyNo trades on this market
4X EMA and volume strategy by SoftKill21ema smav4 strategy+1.8%325.8%

Where it runs

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

Zeal Terminal's engine currently reads an order side written as 1, 0 as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 119, 120) 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/// © SoftKill21//@version=4strategy("Crypto strategy high/low", overlay=true)fast_length = input(title="Fast Length", type=input.integer, defval=12)slow_length = input(title="Slow Length", type=input.integer, defval=26)src = input(title="Source", type=input.source, defval=close)signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)sma_source = input(title="Simple MA(Oscillator)", type=input.bool, defval=true)sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=false)//sarstart = input(0.02)increment = input(0.02)maximum = input(0.2)var bool uptrend = navar float EP = navar float SAR = navar float AF = startvar float nextBarSAR = naif bar_index > 0    firstTrendBar = false    SAR := nextBarSAR    if bar_index == 1        float prevSAR = na        float prevEP = na        lowPrev = low[1]        highPrev = high[1]        closeCur = close        closePrev = close[1]        if closeCur > closePrev            uptrend := true            EP := high            prevSAR := lowPrev            prevEP := high        else            uptrend := false            EP := low            prevSAR := highPrev            prevEP := low        firstTrendBar := true        SAR := prevSAR + start * (prevEP - prevSAR)    if uptrend        if SAR > low            firstTrendBar := true            uptrend := false            SAR := max(EP, high)            EP := low            AF := start    else        if SAR < high            firstTrendBar := true            uptrend := true            SAR := min(EP, low)            EP := high            AF := start    if not firstTrendBar        if uptrend            if high > EP                EP := high                AF := min(AF + increment, maximum)        else            if low < EP                EP := low                AF := min(AF + increment, maximum)    if uptrend        SAR := min(SAR, low[1])        if bar_index > 1            SAR := min(SAR, low[2])    else        SAR := max(SAR, high[1])        if bar_index > 1            SAR := max(SAR, high[2])    nextBarSAR := SAR + AF * (EP - SAR)// Calculatingfast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length)slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)macd = fast_ma - slow_masignal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)hist = macd - signalCCI = input(20)ATR = input(5)Multiplier=input(1,title='ATR Multiplier')original=input(true,title='original coloring')thisCCI = cci(close, CCI)lastCCI = nz(thisCCI[1])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.0x:=thisCCI >= 0 ?bufferUp:thisCCI <= 0 ?bufferDn:x[1]swap=0.0swap:=x>x[1]?1:x<x[1]?-1:swap[1]swap2=swap==1?color.lime:color.redswap3=thisCCI >=0 ?color.lime:color.redswap4=original?swap3:swap2//elliot wavesrce = input(close, title="source")sma1length = input(5)sma2length = input(35)UsePercent = input(title="Show Dif as percent of current Candle", type=input.bool, defval=true)smadif=iff(UsePercent,(sma(srce, sma1length) - sma(srce, sma2length)) / srce * 100, sma(srce, sma1length) - sma(srce, sma2length))col=smadif <= 0 ? color.red : color.greenlongC = high > high[1] and high[1] > high[2] and close[2] > high[3] and hist > 0 and uptrend and smadif < 0 and swap4==color.lime //longC = high > high[1] and high[1] > high[2] and high[2] > high[3] and high[3] > high[4] and close[4] > high[5]shortC = low < low[1] and low[1] < low[2] and close[2] < low[3] and hist < 0 and not uptrend and  smadif > 0 and swap4==color.red //shortC = low < low[1] and low[1] < low[2] and low[2] < low[3] and low[3] < low[4] and close[4] < low[5]tp=input(0.15, title="tp")sl=input(0.005, title="sl")strategy.entry("long",1,when=longC)strategy.entry("short",0,when=shortC)strategy.exit("x_long", "long" ,loss = close * sl / syminfo.mintick, profit = close * tp / syminfo.mintick , alert_message = "closelong")//strategy.entry("short",0, when= loss = close * sl / syminfo.mintick)strategy.exit("x_short", "short" , loss = close * sl / syminfo.mintick, profit  = close * tp / syminfo.mintick,alert_message = "closeshort")//strategy.entry("long",1, when = loss = close * sl / syminfo.mintick)//strategy.close("long",when= hist < 0)//strategy.close("short", when= hist > 0)