Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Forex bot full strategy with risk management

A Pine Script v4 strategy built on Lowest (_colorNormLen), Highest (_colorNormLen) and EMA (volume, 1). 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 commits 100% of equity and pays 0.00005 commission. 15 settings; defaults include Short Length OBV 1, Long Length OBV 8 and PSAR START 0.1.

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 Forex bot full strategy with risk management repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 1 of 1 trades.
How did Forex bot full strategy with risk management do on BTCUSDT 1D with default settings?
−26.43%
From 26 Jan 2024 to 21 Oct 2026, over 11 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Forex bot full strategy with risk management 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 Forex bot full strategy with risk management use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Forex bot full strategy with risk management 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

  • 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 (15)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$7,357$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. 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 175, 178) so the engine trades the way the script says.
Net profit
−26.43%
−$2,642.60
Buy and hold
+102.5%
same period
Closed trades
11
3 won · 8 lost
Profitable
27.3%
of closed trades
Profit factor
0.41
gross profit ÷ gross loss
Max drawdown
38.91%
−$4,507.77

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.

  • Check

    No stop loss

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

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    2 settings have no label

    In the settings dialog longEntry (line 172), shortEntry (line 173) show an empty name. The labels on this page come from the variable names.

  • Note

    Uses an argument v6 removed

    when = on line 175, 176, 178, 179. The upgraded version below moves each call inside an if block.

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 lowest → ta.lowest, highest → ta.highest, sign → math.sign, ema → ta.ema, max → math.max, min → math.min, sma → ta.sma, crossover → ta.crossover, crossunder → ta.crossunder.
  • 4 strategy calls use the when = argument (line 175, 176, 178, 179). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 13: lowest → ta.lowest
  • Line 14: highest → ta.highest
  • Line 19: sign → math.sign
  • Line 20: ema → ta.ema
  • Line 21: ema → ta.ema
31 more edits
  • Line 59: max → math.max
  • Line 66: min → math.min
  • Line 73: min → math.min
  • Line 77: min → math.min
  • Line 79: min → math.min
  • Line 81: min → math.min
  • Line 83: max → math.max
  • Line 85: max → math.max
  • Line 101: ema → ta.ema
  • Line 102: input(type = input.integer) → input.int()
  • Line 103: input(type = input.integer) → input.int()
  • Line 104: input(type = input.source) → input.source()
  • Line 105: input(type = input.integer) → input.int()
  • Line 106: input(type = input.bool) → input.bool()
  • Line 107: input(type = input.bool) → input.bool()
  • Line 109: sma → ta.sma
  • Line 109: ema → ta.ema
  • Line 110: sma → ta.sma
  • Line 110: ema → ta.ema
  • Line 112: sma → ta.sma
  • Line 112: ema → ta.ema
  • Line 131: crossover → ta.crossover
  • Line 131: crossover → ta.crossover
  • Line 132: crossunder → ta.crossunder
  • Line 132: crossunder → ta.crossunder
  • Line 160: crossunder → ta.crossunder
  • Line 160: crossunder → ta.crossunder
  • Line 161: crossover → ta.crossover
  • Line 161: crossover → ta.crossover
  • Line 175: strategy.entry(…, 1) → strategy.entry(…, strategy.long)
  • Line 178: strategy.entry(…, 0) → strategy.entry(…, strategy.short)
⋯// © exlux99-//@version=4+//@version=5strategy("Scalping FOrex full strategy with risk management",overlay=true,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.cash_per_contract ,commission_value=0.00005)⋯    _mult = 0.0-    _lowest = lowest(_colorNormLen)+    _lowest = ta.lowest(_colorNormLen)-    _highest = highest(_colorNormLen)+    _highest = ta.highest(_colorNormLen)    _diff1 = close - _lowest⋯        _mult := _diff1 / _diff2 * 100-    color.from_gradient(sign(_series) * _mult, _dnValue, 100, _dnColor, _upColor)+    color.from_gradient(math.sign(_series) * _mult, _dnValue, 100, _dnColor, _upColor)-shorta = ema(volume, shortlen)+shorta = ta.ema(volume, shortlen)-longa = ema(volume, longlen)+longa = ta.ema(volume, longlen)osc = 100 * (shorta - longa) / longa⋯            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)⋯srca = input(close, title="Source")-out = ema(srca, lena)+out = ta.ema(srca, lena)-fast_length = input(title="Fast Length MACD", type=input.integer, defval=12)+fast_length = input.int(title="Fast Length MACD", defval=12)-slow_length = input(title="Slow Length MACD", type=input.integer, defval=25)+slow_length = input.int(title="Slow Length MACD", defval=25)-src = input(title="Source", type=input.source, defval=close)+src = input.source(title="Source", defval=close)-signal_length = input(title="Signal Smoothing MACD", type=input.integer, minval = 1, maxval = 50, defval = 9)+signal_length = input.int(title="Signal Smoothing MACD", 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=true)+sma_signal = input.bool(title="Simple MA (Signal Line)", defval=true)// 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⋯    entrys:=entrys+1-tpLongTrigger = (longOpeneds[1] and (crossover(close, tpLong) or crossover( high,tpLong)))+tpLongTrigger = (longOpeneds[1] and (ta.crossover(close, tpLong) or ta.crossover( high,tpLong)))-slLongTrigger = (longOpeneds[1] and (crossunder(close, slLong) or crossunder( low,slLong)))+slLongTrigger = (longOpeneds[1] and (ta.crossunder(close, slLong) or ta.crossunder( low,slLong)))longExitSignals =  slLongTrigger or tpLongTrigger  or short⋯ -tpLongTriggers = (longOpenedss[1] and ( crossunder(close, tpLongs) or crossunder( low,tpLongs)))+tpLongTriggers = (longOpenedss[1] and ( ta.crossunder(close, tpLongs) or ta.crossunder( low,tpLongs)))-slLongTriggers = (longOpenedss[1] and (crossover(close, slLongs) or crossover( high,slLongs)))+slLongTriggers = (longOpenedss[1] and (ta.crossover(close, slLongs) or ta.crossover( high,slLongs)))longExitSignalss =  slLongTriggers or tpLongTriggers  or long⋯if(longEntry)-    strategy.entry("long",1,when=longConditions)+    strategy.entry("long",strategy.long,when=longConditions)    strategy.close('long',when=exitLongConditions)if(shortEntry)-    strategy.entry("short",0,when=longConditionss)+    strategy.entry("short",strategy.short,when=longConditionss)    strategy.close("short",when=exitLongConditionss)

Clean v5

VerifiedDownload the v5 script

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

  • Line 6: input() → input.int()
  • Line 7: input() → input.int()
  • Line 23: input() → input.float()
  • Line 24: input() → input.float()
  • Line 25: input() → input.float()
  • Line 99: input() → input.int()
7 more edits
  • Line 100: input() → input.source()
  • Line 172: input() → input.bool()
  • Line 173: input() → input.bool()
  • Line 175: when = longConditions → if block
  • Line 176: when = exitLongConditions → if block
  • Line 178: when = longConditionss → if block
  • Line 179: when = exitLongConditionss → if block
⋯//VOLUME o-shortlen = input(1, minval=1, title = "Short Length OBV")+shortlen = input.int(1, minval=1, title = "Short Length OBV")-longlen = input(8, minval=1, title = "Long Length OBV")+longlen = input.int(8, minval=1, title = "Long Length OBV")upColor = #2196F3//input(#2196F3, "Color Up")⋯osc = 100 * (shorta - longa) / longa-start = input(0.1, title="PSAR START")+start = input.float(0.1, title="PSAR START")-increment = input(0.05,title="PSAR INC")+increment = input.float(0.05,title="PSAR INC")-maximum = input(0.3, title="PSAR MAX")+maximum = input.float(0.3, title="PSAR MAX")// multitp=input(1)⋯ -lena = input(200, minval=1, title="Length EMA")+lena = input.int(200, minval=1, title="Length EMA")-srca = input(close, title="Source")+srca = input.source(close, title="Source")out = ta.ema(srca, lena)⋯    -longEntry=input(true)+longEntry=input.bool(true)-shortEntry=input(true)+shortEntry=input.bool(true)if(longEntry)-    strategy.entry("long",strategy.long,when=longConditions)+    if longConditions+        strategy.entry("long",strategy.long)-    strategy.close('long',when=exitLongConditions)+    if exitLongConditions+        strategy.close('long')if(shortEntry)-    strategy.entry("short",strategy.short,when=longConditionss)+    if longConditionss+        strategy.entry("short",strategy.short)-    strategy.close("short",when=exitLongConditionss)+    if exitLongConditionss+        strategy.close("short")

Does it run in Pine Script v6?

No

The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L28: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.

⋯// © exlux99-//@version=5+//@version=6strategy("Scalping FOrex full strategy with risk management",overlay=true,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.cash_per_contract ,commission_value=0.00005)⋯

Settings

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

SettingDefaultType and rangeFeeds
Short Length OBV1int · min 1shorta
Long Length OBV8int · min 1longa
PSAR START0.1floatSAR AF
PSAR INC0.05floatAF
PSAR MAX0.3floatAF
Length EMA200int · min 1out
Sourceclosesourceout
Fast Length MACD12int (written input.integer)fast_ma
Slow Length MACD25int (written input.integer)slow_ma
Sourceclosesourcefast_ma slow_ma
Signal Smoothing MACD9int (written input.integer) · min 1 · max 50signal
Simple MA (Oscillator)trueboolfast_ma slow_ma
Simple MA (Signal Line)trueboolsignal
Long Entry (no label in the script)trueboolentry long close long line 174
Short Entry (no label in the script)trueboolentry short close short line 177

What it calculates

  • Lowest (lowest, ta.lowest in v5)_colorNormLen_lowest · line 13
  • Highest (highest, ta.highest in v5)_colorNormLen_highest · line 14
  • EMA (ema, ta.ema in v5)volume, Short Length OBV (1)shorta · line 20
  • EMA (ema, ta.ema in v5)volume, Long Length OBV (8)longa · line 21
  • EMA (ema, ta.ema in v5)Source (close), Length EMA (200)out · line 101
  • SMA / EMA (sma, ta.sma in v5)Source (close), Fast Length MACD (12)fast_ma · line 109
  • SMA / EMA (sma, ta.sma in v5)Source (close), Slow Length MACD (25)slow_ma · line 110
  • SMA / EMA (sma, ta.sma in v5)macd, Signal Smoothing MACD (9)signal · line 112

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.

volumevolumeprice datashortlenShort Length OBVsetting · 1longlenLong Length OBVsetting · 8closecloseprice datalenaLength EMAsetting · 200fast_lengthFast Length MACDsetting · 12slow_lengthSlow Length MACDsetting · 25signal_lengthSignal Smoothing MACDsetting · 9lowlowprice datahighhighprice datastartPSAR STARTsetting · 0.1incrementPSAR INCsetting · 0.05maximumPSAR MAXsetting · 0.3timetimeprice data_lowestLowest→ _lowest_highestHighest→ _highestshortaEMA→ shortalongaEMA→ longaoutEMA→ outfast_maSMA / EMA→ fast_maslow_maSMA / EMA→ slow_masignalSMA / EMA→ signal_dnValue_dnValuevalue_mult_multvalue_diff1_diff1value_diff2_diff2valueoscoscvalueEP, prevEPEP · prevEP2 valuesSARSARvalueAFAFvaluenextBarSARnextBarSARvalueprevSARprevSARvaluelowPrevlowPrevvaluehighPrevhighPrevvaluecloseCur, closePrevcloseCur · closePrev2 valuespsarshort, psarlongpsarshort · psarlong2 valuesmacdmacdvaluehisthistvaluetimeOfBuys, timeOfBuysstimeOfBuys · timeOfBuyss2 valuestpLong, slLongtpLong · slLong2 valuesentrysentrysvaluetpLongs, slLongstpLongs · slLongs2 valueslongConditionslongConditionsconditionexitLongConditionsexitLongConditionsconditionlongConditionsslongConditionssconditionexitLongConditionssexitLongConditionssconditionlong, shortlong · short2 conditionstpLongTriggertpLongTriggerconditionslLongTriggerslLongTriggerconditionlongExitSignalslongExitSignalsconditiontpLongTriggerstpLongTriggersconditionslLongTriggersslLongTriggersconditionlongExitSignalsslongExitSignalssconditionupColor, dnColorColourupColor · dnColorentry:longOpen longstrategy.entryclose:longClose longstrategy.closeentry:shortOpen shortstrategy.entryclose:shortClose shortstrategy.close

Order rules

OrderFires whenBy defaultLine
Open long longlongConditionslong and not longOpeneds and entrys<100On175
Close longexitLongConditionslongOpeneds[1] and longExitSignalsOn176
Open short shortlongConditionssshort and not longOpenedss and entry<100On178
Close shortexitLongConditionsslongOpenedss[1] and longExitSignalssOn179

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.

1/1trades 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−26.4%+102.5%1127%0.4138.9%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−3.1%+5.5%650%0.504.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−1.6%+9.8%743%0.9527.2%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+4.1%+8.4%560%1.467.5%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+12.7%+16.7%978%1.3824.6%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−3.2%+21.5%633%0.584.8%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−7.7%+148.3%367%0.5320.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+2.5%+17.1%667%1.844.3%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 market425%$430.12
Sideways market633%−$2,399.29
Falling market10%−$673.43

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

How bad could the drawdown be?

38.2%

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

0%44%
All 11 trades
SideEntryExitBarsP&L
long9 Nov 2024 76,509.8012 Nov 2024 88,648.003$1,586.49
long16 Dec 2024 104,464.0020 Dec 2024 97,461.904−$776.63
long6 Jan 2025 98,363.608 Jan 2025 96,954.602−$154.85
short27 Feb 2025 84,250.102 May 2025 96,489.9064−$1,547.96
long30 Jun 2025 108,357.002 Jul 2025 105,681.002−$224.89
long7 Sep 2025 110,188.008 Sep 2025 111,137.001$76.53
long5 Oct 2025 122,391.0011 Oct 2025 112,774.006−$703.90
long29 Oct 2025 112,898.0030 Oct 2025 110,021.001−$210.37
short8 Nov 2025 103,339.0011 Nov 2025 106,011.003−$208.00
short16 Dec 2025 86,432.106 Jan 2026 93,859.7021−$673.43
short30 Jun 2026 60,260.201 Jul 2026 58,624.701$194.41

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
Forex bot full strategy with risk management this page—v4 strategy−26.4%1138.9%
ATR + STC + MA by Romediusema lowest highest smav5 strategy−1.2%153.3%
Bagheri IG Ether by Bagheri_IGema highest lowest smav4 strategy+0.0%30.0%
Bagheri IG Ether v2 by Bagheri_IGema highest lowest smav4 strategy−0.0%20.0%
Crunchster's Turtle and Trend System by Crunchster1lowest highest ema smav5 strategy+18.0%3116.7%
-NoSKi Hammer-Star -w angle of ema Backtester - by noski1ema sma highest lowestv5 strategydoes not run in Zeal Terminal

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 175, 178) 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/// © exlux99//@version=4strategy("Scalping FOrex full strategy with risk management",overlay=true,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.cash_per_contract ,commission_value=0.00005)//VOLUME oshortlen = input(1, minval=1, title = "Short Length OBV")longlen = input(8, minval=1, title = "Long Length OBV")upColor = #2196F3//input(#2196F3, "Color Up")dnColor = #6B1599//input(#6B1599, "Color Down")f_normGradientColor(_series, _crossesZero, _colorNormLen, _dnColor, _upColor) =>    _dnValue = _crossesZero?-100:0    _mult = 0.0    _lowest = lowest(_colorNormLen)    _highest = highest(_colorNormLen)    _diff1 = close - _lowest    _diff2 = _highest - _lowest    if _diff2 > 0        _mult := _diff1 / _diff2 * 100    color.from_gradient(sign(_series) * _mult, _dnValue, 100, _dnColor, _upColor)shorta = ema(volume, shortlen)longa = ema(volume, longlen)osc = 100 * (shorta - longa) / longastart = input(0.1, title="PSAR START")increment = input(0.05,title="PSAR INC")maximum = input(0.3, title="PSAR MAX")// multitp=input(1)// multisl=input(1)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)//    if barstate.isconfirmed    //         if uptrend//             strategy.entry("ParSE", strategy.short, stop=nextBarSAR, comment="ParSE")//             strategy.cancel("ParLE")//         else//             strategy.entry("ParLE", strategy.long, stop=nextBarSAR, comment="ParLE")//             strategy.cancel("ParSE")//plot(SAR, style=plot.style_cross, linewidth=3, color=color.orange)psarshort = close- SARpsarlong= SAR-close lena = input(200, minval=1, title="Length EMA")srca = input(close, title="Source")out = ema(srca, lena)fast_length = input(title="Fast Length MACD", type=input.integer, defval=12)slow_length = input(title="Slow Length MACD", type=input.integer, defval=25)src = input(title="Source", type=input.source, defval=close)signal_length = input(title="Signal Smoothing MACD", 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=true)// 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 - signallong = hist[1]<0 and hist > 0 and close > out and uptrend and osc < 0short = hist[1]>0 and hist< 0 and close < out and not uptrend and osc >0// ------------------------- Strategy Logic --------------------------------- //var longOpeneds = falsevar shortOpeneds = falsevar int timeOfBuys = navar float tpLong = navar float slLong = navar int entrys = na longConditions = long and not longOpeneds and entrys<100if longConditions    longOpeneds := true    timeOfBuys := time    tpLong := close+ (psarshort) //* multitp)    slLong := close- (psarshort)//*multisl)    entrys:=entrys+1tpLongTrigger = (longOpeneds[1] and (crossover(close, tpLong) or crossover( high,tpLong)))slLongTrigger = (longOpeneds[1] and (crossunder(close, slLong) or crossunder( low,slLong)))longExitSignals =  slLongTrigger or tpLongTrigger  or shortexitLongConditions = longOpeneds[1] and longExitSignalsif exitLongConditions    longOpeneds := false    timeOfBuys := na    tpLong := na    slLong := na    if(short)    entrys:=0//short// ------------------------- Strategy Logic --------------------------------- //var longOpenedss = false// var shortOpeneds = falsevar int timeOfBuyss = navar float tpLongs = navar float slLongs = navar int entry = na longConditionss = short and not longOpenedss and entry<100if longConditionss    longOpenedss := true    timeOfBuyss := time    tpLongs := close- (psarlong)//*multitp )    slLongs := close+ (psarlong)//*multisl)    entry:=1 tpLongTriggers = (longOpenedss[1] and ( crossunder(close, tpLongs) or crossunder( low,tpLongs)))slLongTriggers = (longOpenedss[1] and (crossover(close, slLongs) or crossover( high,slLongs)))longExitSignalss =  slLongTriggers or tpLongTriggers  or longexitLongConditionss = longOpenedss[1] and longExitSignalssif exitLongConditionss    longOpenedss := false    timeOfBuyss := na    tpLongs := na    slLongs := naif(long)    entry:=0    longEntry=input(true)shortEntry=input(true)if(longEntry)    strategy.entry("long",1,when=longConditions)    strategy.close('long',when=exitLongConditions)if(shortEntry)    strategy.entry("short",0,when=longConditionss)    strategy.close("short",when=exitLongConditionss)