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
- 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
VerifiedSame 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)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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Short Length OBV | 1 | int · min 1 | shorta |
| Long Length OBV | 8 | int · min 1 | longa |
| PSAR START | 0.1 | float | SAR AF |
| PSAR INC | 0.05 | float | AF |
| PSAR MAX | 0.3 | float | AF |
| Length EMA | 200 | int · min 1 | out |
| Source | close | source | out |
| Fast Length MACD | 12 | int (written input.integer) | fast_ma |
| Slow Length MACD | 25 | int (written input.integer) | slow_ma |
| Source | close | source | fast_ma slow_ma |
| Signal Smoothing MACD | 9 | int (written input.integer) · min 1 · max 50 | signal |
| Simple MA (Oscillator) | true | bool | fast_ma slow_ma |
| Simple MA (Signal Line) | true | bool | signal |
| Long Entry (no label in the script) | true | bool | entry long close long line 174 |
| Short Entry (no label in the script) | true | bool | entry short close short line 177 |
What it calculates
- Lowest (
lowest,ta.lowestin v5)_colorNormLen_lowest · line 13 - Highest (
highest,ta.highestin v5)_colorNormLen_highest · line 14 - EMA (
ema,ta.emain v5)volume, Short Length OBV (1)shorta · line 20 - EMA (
ema,ta.emain v5)volume, Long Length OBV (8)longa · line 21 - EMA (
ema,ta.emain v5)Source (close), Length EMA (200)out · line 101 - SMA / EMA (
sma,ta.smain v5)Source (close), Fast Length MACD (12)fast_ma · line 109 - SMA / EMA (
sma,ta.smain v5)Source (close), Slow Length MACD (25)slow_ma · line 110 - SMA / EMA (
sma,ta.smain 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open long long | longConditionslong and not longOpeneds and entrys<100 | On | 175 |
| Close long | exitLongConditionslongOpeneds[1] and longExitSignals | On | 176 |
| Open short short | longConditionssshort and not longOpenedss and entry<100 | On | 178 |
| Close short | exitLongConditionsslongOpenedss[1] and longExitSignalss | On | 179 |
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.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −26.4% | +102.5% | 11 | 27% | 0.41 | 38.9% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −3.1% | +5.5% | 6 | 50% | 0.50 | 4.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −1.6% | +9.8% | 7 | 43% | 0.95 | 27.2% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +4.1% | +8.4% | 5 | 60% | 1.46 | 7.5% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +12.7% | +16.7% | 9 | 78% | 1.38 | 24.6% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −3.2% | +21.5% | 6 | 33% | 0.58 | 4.8% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −7.7% | +148.3% | 3 | 67% | 0.53 | 20.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +2.5% | +17.1% | 6 | 67% | 1.84 | 4.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 4 | 25% | $430.12 |
| Sideways market | 6 | 33% | −$2,399.29 |
| Falling market | 1 | 0% | −$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.
All 11 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 9 Nov 2024 76,509.80 | 12 Nov 2024 88,648.00 | 3 | $1,586.49 |
| long | 16 Dec 2024 104,464.00 | 20 Dec 2024 97,461.90 | 4 | −$776.63 |
| long | 6 Jan 2025 98,363.60 | 8 Jan 2025 96,954.60 | 2 | −$154.85 |
| short | 27 Feb 2025 84,250.10 | 2 May 2025 96,489.90 | 64 | −$1,547.96 |
| long | 30 Jun 2025 108,357.00 | 2 Jul 2025 105,681.00 | 2 | −$224.89 |
| long | 7 Sep 2025 110,188.00 | 8 Sep 2025 111,137.00 | 1 | $76.53 |
| long | 5 Oct 2025 122,391.00 | 11 Oct 2025 112,774.00 | 6 | −$703.90 |
| long | 29 Oct 2025 112,898.00 | 30 Oct 2025 110,021.00 | 1 | −$210.37 |
| short | 8 Nov 2025 103,339.00 | 11 Nov 2025 106,011.00 | 3 | −$208.00 |
| short | 16 Dec 2025 86,432.10 | 6 Jan 2026 93,859.70 | 21 | −$673.43 |
| short | 30 Jun 2026 60,260.20 | 1 Jul 2026 58,624.70 | 1 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Forex bot full strategy with risk management this page | — | v4 strategy | −26.4% | 11 | 38.9% |
| ATR + STC + MA by Romedius | ema lowest highest sma | v5 strategy | −1.2% | 15 | 3.3% |
| Bagheri IG Ether by Bagheri_IG | ema highest lowest sma | v4 strategy | +0.0% | 3 | 0.0% |
| Bagheri IG Ether v2 by Bagheri_IG | ema highest lowest sma | v4 strategy | −0.0% | 2 | 0.0% |
| Crunchster's Turtle and Trend System by Crunchster1 | lowest highest ema sma | v5 strategy | +18.0% | 31 | 16.7% |
| -NoSKi Hammer-Star -w angle of ema Backtester - by noski1 | ema sma highest lowest | v5 strategy | does not run in Zeal Terminal | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 40 ms | With a workaround 1,000 bars in 62 ms | Not measured |
| PineTS | No 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)