Pine Script v5 · Strategy
OTT-Stoch-TP-SL
A Pine Script v5 strategy built on EMA (zxEMAData, length), Linreg (close, length) and SMA or EMA or WMA (close, length). It has 12 order rules, 4 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays 0.05% commission. 22 settings; defaults include OTT source close, Stoch OTT source close and OTT Fast Percent(%): 3.0.
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 OTT-Stoch-TP-SL repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did OTT-Stoch-TP-SL 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 code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- Does OTT-Stoch-TP-SL run in Pine Script v6?
- Not tested
- Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download.
- Does OTT-Stoch-TP-SL use a stop loss?
- Yes
- strategy.exit sets a stop on line 203, 205, 214, 216.
- Does OTT-Stoch-TP-SL run in Zeal Terminal?
- Yes
- It compiles in 58 ms and runs 1,000 bars in 140 ms, in the browser.
BTCUSDT · 1D · default settings
- OTT Fast
- OTT Slow
- Winning trade
- Losing trade
- Equity
- Buy and hold
- 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, $1,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
Every trade uses all the equity
default_qty_value is 100% of equity.
-
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 178, 182, 186, 187, 193, 194. The upgraded version below moves each call inside an if block.
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 |
|---|---|---|---|
| OTT source | close | source | vud1 vdd1 VAR WWMA zxEMAData lrc lrc1 TSF ma MAvg1 MAvg2 |
| Stoch OTT source | close | source | vud11 vdd11 VAR1 |
| OTT Fast Percent(%): | 3.0 | float · min 0.1 · max 30.0 · step 0.1 | fark1 OTTFast |
| OTT Slow Percent(%): | 10.0 | float · min 0.1 · max 30.0 · step 0.1 | fark2 OTTSlow |
| OTT Fast Length: | 1 | int · min 1 | MAvg1 |
| OTT Slow Length: | 1 | int · min 1 | MAvg2 |
| %K Length | 500 | int · min 1 · step 10 | k |
| %K Smoothing | 200 | int · min 1 · step 10 | k |
| Stoch OTT Period | 2 | int · min 1 | VAR1 VAR2 MAvg3 |
| Stoch OTT Percent | 0.5 | float · min 0 · step 0.1 | fark3 OTTStoch |
| Moving Average Type | SMA | string · options ["SMA", "EMA", "WMA", "TMA", "VAR", "WWMA", "ZLEMA", "TSF"] | line 72 line 75 line 78 line 81 line 84 line 87 line 90 line 93 |
| Take Profit: | 0.0 | float · min 0.0 · max 100.0 · step 0.1 | longProfitPrice shortProfitPrice line 201 line 206 |
| Stop Loss: | 0.0 | float · min 0.0 · max 100.0 · step 0.1 | longStopPrice shortStopPrice line 201 line 212 |
| evaluate Stoch OTT | false | bool | line 169 |
| Long Entry | true | bool | entry LONG close LONG line 176 line 185 |
| Short Entry | true | bool | entry SHORT close SHORT line 176 line 192 |
| From Day | 1 | int · min 1 · max 31 | start |
| From Month | 1 | int · min 1 · max 12 | start |
| From Year | 2021 | int · min 2010 | start |
| To Day | 30 | int · min 1 · max 31 | finish |
| To Month | 12 | int · min 1 · max 12 | finish |
| To Year | 2022 | int · min 2010 | finish |
What it calculates
- EMAzxEMAData, length
ZLEMA · line 60 - LinregOTT source (close), length, 0
lrc · line 64 - LinregOTT source (close), length, 1
lrc1 · line 65 - LinregOTT source (close), length, 0
TSF · line 67 - SMA / EMA / WMAOTT source (close), length
ma · line 73 - Stochclose, high, low, %K Length (500)
k · line 135
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 81 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open LONG long | buySignallwindow() and long and (not stoppedOutLong) ⟶ window() and long and (not stoppedOutLong) and ( k1 > OTTStoch ) | On | 178 |
| Open SHORT short | sellSignallwindow() and (not long) and (not stoppedOutShort) ⟶ window() and (not long) and (not stoppedOutShort) and ( k1 < OTTStoch ) | On | 182 |
| Open LONG long | buySignallwindow() and long and (not stoppedOutLong) ⟶ window() and long and (not stoppedOutLong) and ( k1 > OTTStoch ) | On | 186 |
| Close LONG | sellSignallwindow() and (not long) and (not stoppedOutShort) ⟶ window() and (not long) and (not stoppedOutShort) and ( k1 < OTTStoch ) | On | 187 |
| Open SHORT short | sellSignallwindow() and (not long) and (not stoppedOutShort) ⟶ window() and (not long) and (not stoppedOutShort) and ( k1 < OTTStoch ) | On | 193 |
| Close SHORT | buySignallwindow() and long and (not stoppedOutLong) ⟶ window() and long and (not stoppedOutLong) and ( k1 > OTTStoch ) | On | 194 |
| Exit LONG stop and limit | ( strategy.position_size > 0 ) | On | 203 |
| Exit SHORT stop and limit | ( strategy.position_size < 0 ) | On | 205 |
| Exit LONG limit | ( strategy.position_size > 0 ) | On | 208 |
| Exit SHORT limit | ( strategy.position_size < 0 ) | On | 210 |
| Exit LONG stop | ( strategy.position_size > 0 ) | On | 214 |
| Exit SHORT stop | ( strategy.position_size < 0 ) | On | 216 |
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.
- 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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.
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 | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Settings heatmap
Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (%K Length 250, %K Smoothing 100) made 0.0% before 26 Dec 2025 and 0.0% after it, against 0.0% for the defaults. 0% of the 64 combinations made money in-sample and 0% out-of-sample.
| %K Smoothing ↓ · %K Length → | 250 | 300 | 350 | 425 | 500 | 600 | 700 | 850 |
|---|---|---|---|---|---|---|---|---|
| 100 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 120 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 140 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 170 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 200 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 240 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 280 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 340 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| %K Smoothing ↓ · %K Length → | 250 | 300 | 350 | 425 | 500 | 600 | 700 | 850 |
|---|---|---|---|---|---|---|---|---|
| 100 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 120 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 140 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 170 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 200 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 240 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 280 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 340 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. Backtests are simulations on historical data and are not investment advice.
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 |
|---|---|---|---|---|---|
| OTT-Stoch-TP-SL this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| MACD ReLoaded STRATEGY by KivancOzbilgic | ema linreg wma sma | v5 strategy | +7.8% | 31 | 5.1% |
| Linear Regression MA - Strategy by lazy_capitalist | sma linreg ema | v5 strategy | −1,240.4% | 10 | 318.7% |
| Forex SWING Trader by SoftKill21 | wma ema sma | v4 strategy | No trades on this market | ||
| High-Low Channel Multi averages Crypto Swing strategy by exlux99 | sma ema wma linreg | v4 strategy | No trades on this market | ||
| DRSI DMA Scalping Strategy No Repaint by allenlk | sma wma ema | v4 strategy | −99.5% | 44 | 137.7% |
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 6 strategy calls use the when = argument (line 178, 182, 186, 187, 193, 194). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 2 settings use the untyped input() (line 11, 12). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 11: input() → input.source()
- Line 12: input() → input.source()
- Line 178: when = buySignall → if block
- Line 182: when = sellSignall → if block
- Line 186: when = buySignall → if block
- Line 187: when = sellSignall → if block
- Line 193: when = sellSignall → if block
- Line 194: when = buySignall → if block
⋯//-------------- fetch user inputs -------------------src = input(defval=close, title='OTT source')+src = input.source(defval=close, title='OTT source')-src1 = input(defval=close, title="Stoch OTT source")+src1 = input.source(defval=close, title="Stoch OTT source")ottFastPercent = input.float(title='OTT Fast Percent(%):', defval=3.0, minval=0.1, maxval=30.0, step=0.1)⋯ if long - strategy.entry("LONG", strategy.long, when = buySignall, comment = "ENTER LONG")+ if buySignall+ strategy.entry("LONG", strategy.long, comment = "ENTER LONG") stoppedOutLong := true⋯ else - strategy.entry("SHORT", strategy.short, when = sellSignall, comment = "ENTER SHORT")+ if sellSignall+ strategy.entry("SHORT", strategy.short, comment = "ENTER SHORT") stoppedOutLong := false⋯else if(longEntry)- strategy.entry("LONG", strategy.long, when = buySignall)+ if buySignall+ strategy.entry("LONG", strategy.long)- strategy.close("LONG", when = sellSignall)+ if sellSignall+ strategy.close("LONG") if long ⋯else if(shortEntry)- strategy.entry("SHORT", strategy.short, when = sellSignall)+ if sellSignall+ strategy.entry("SHORT", strategy.short)- strategy.close("SHORT", when = buySignall)+ if buySignall+ strategy.close("SHORT") if not long⋯Does it run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © BigCoinHunter-//@version=5+//@version=6strategy(title='OTT-Stoch-TP/SL', overlay=true, ⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 58 ms | With a workaround 1,000 bars in 140 ms | Not measured |
| PineTS | Not tested | Not tested | 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.
“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.
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/// © BigCoinHunter//@version=5strategy(title='OTT-Stoch-TP/SL', overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=1000, currency=currency.USD, commission_value=0.05, commission_type=strategy.commission.percent, process_orders_on_close=true)//-------------- fetch user inputs ------------------src = input(defval=close, title='OTT source')src1 = input(defval=close, title="Stoch OTT source")ottFastPercent = input.float(title='OTT Fast Percent(%):', defval=3.0, minval=0.1, maxval=30.0, step=0.1)ottSlowPercent = input.float(title='OTT Slow Percent(%):', defval=10.0, minval=0.1, maxval=30.0, step=0.1)ottFastLength = input.int(title="OTT Fast Length:", defval=1, minval=1)ottSlowLength = input.int(title="OTT Slow Length:", defval=1, minval=1)periodK = input.int(defval=500, title="%K Length", minval=1, step=10)smoothK = input.int(defval=200, title="%K Smoothing", minval=1, step=10)stochLength=input.int(defval=2, title="Stoch OTT Period", minval=1)stochPercent=input.float(defval=0.5, title="Stoch OTT Percent", step=0.1, minval=0)mav = input.string(title="Moving Average Type", defval="SMA", options=["SMA", "EMA", "WMA", "TMA", "VAR", "WWMA", "ZLEMA", "TSF"])tp = input.float(title="Take Profit:", defval=0.0, minval=0.0, maxval=100.0, step=0.1) * 0.01sl = input.float(title="Stop Loss: ", defval=0.0, minval=0.0, maxval=100.0, step=0.1) * 0.01//showsupport = input.bool(title="Show Support Line?", defval=true)stoch = input.bool(title="evaluate Stoch OTT", defval=false)longEntry = input.bool(defval=true, title= 'Long Entry', inline="11")shortEntry = input.bool(defval=true, title='Short Entry', inline="11")//---------- backtest range setup ------------fromDay = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)fromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12)fromYear = input.int(defval = 2021, title = "From Year", minval = 2010)toDay = input.int(defval = 30, title = "To Day", minval = 1, maxval = 31)toMonth = input.int(defval = 12, title = "To Month", minval = 1, maxval = 12)toYear = input.int(defval = 2022, title = "To Year", minval = 2010)//------------ time interval setup -----------start = timestamp(fromYear, fromMonth, fromDay, 00, 00) // backtest start windowfinish = timestamp(toYear, toMonth, toDay, 23, 59) // backtest finish windowwindow() => time >= start and time <= finish ? true : false // create function "within window of time"//-------- calculate the OTT lines ----------Var_Func(src,length)=> valpha=2/(length+1) vud1=src>src[1] ? src-src[1] : 0 vdd1=src<src[1] ? src[1]-src : 0 vUD=math.sum(vud1,9) vDD=math.sum(vdd1,9) vCMO=nz((vUD-vDD)/(vUD+vDD)) VAR=0.0 VAR:=nz(valpha*math.abs(vCMO)*src)+(1-valpha*math.abs(vCMO))*nz(VAR[1]) //VAR=Var_Func(src,length)Wwma_Func(src,length)=> wwalpha = 1/ length WWMA = 0.0 WWMA := wwalpha*src + (1-wwalpha)*nz(WWMA[1]) //WWMA=Wwma_Func(src,length)Zlema_Func(src,length)=> zxLag = length/2==math.round(length/2) ? length/2 : (length - 1) / 2 zxEMAData = (src + (src - src[zxLag])) ZLEMA = ta.ema(zxEMAData, length) //ZLEMA=Zlema_Func(src,length)Tsf_Func(src,length)=> lrc = ta.linreg(src, length, 0) lrc1 = ta.linreg(src,length,1) lrs = (lrc-lrc1) TSF = ta.linreg(src, length, 0)+lrs //TSF=Tsf_Func(src,length)getMA(src, length) => ma = 0.0 if mav == "SMA" ma := ta.sma(src, length) ma if mav == "EMA" ma := ta.ema(src, length) ma if mav == "WMA" ma := ta.wma(src, length) ma if mav == "TMA" ma := ta.sma(ta.sma(src, math.ceil(length / 2)), math.floor(length / 2) + 1) ma if mav == "VAR" ma := Var_Func(src,length) ma if mav == "WWMA" ma := Wwma_Func(src,length) ma if mav == "ZLEMA" ma := Zlema_Func(src,length) ma if mav == "TSF" ma := Tsf_Func(src,length) ma ma//-------- OTT line calculation --------MAvg1=getMA(src, ottFastLength)fark1=MAvg1*ottFastPercent*0.01longStop1 = MAvg1 - fark1longStopPrev1 = nz(longStop1[1], longStop1)longStop1 := MAvg1 > longStopPrev1 ? math.max(longStop1, longStopPrev1) : longStop1shortStop1 = MAvg1 + fark1shortStopPrev1 = nz(shortStop1[1], shortStop1)shortStop1 := MAvg1 < shortStopPrev1 ? math.min(shortStop1, shortStopPrev1) : shortStop1dir1 = 1dir1 := nz(dir1[1], dir1)dir1 := dir1 == -1 and MAvg1 > shortStopPrev1 ? 1 : dir1 == 1 and MAvg1 < longStopPrev1 ? -1 : dir1MT1 = dir1==1 ? longStop1: shortStop1OTTFast=MAvg1>MT1 ? MT1*(200+ottFastPercent)/200 : MT1*(200-ottFastPercent)/200MAvg2=getMA(src, ottSlowLength)fark2=MAvg2*ottSlowPercent*0.01longStop2 = MAvg2 - fark2longStopPrev2 = nz(longStop2[1], longStop2)longStop2 := MAvg2 > longStopPrev2 ? math.max(longStop2, longStopPrev2) : longStop2shortStop2 = MAvg2 + fark2shortStopPrev2 = nz(shortStop2[1], shortStop2)shortStop2 := MAvg2 < shortStopPrev2 ? math.min(shortStop2, shortStopPrev2) : shortStop2dir2 = 1dir2 := nz(dir2[1], dir2)dir2 := dir2 == -1 and MAvg2 > shortStopPrev2 ? 1 : dir2 == 1 and MAvg2 < longStopPrev2 ? -1 : dir2MT2 = dir2==1 ? longStop2: shortStop2OTTSlow=MAvg2>MT2 ? MT2*(200+ottSlowPercent)/200 : MT2*(200-ottSlowPercent)/200//-------- Stoch OTT calculation ----------Var_Func1(src1,length)=> valpha1=2/(length+1) vud11=src1>src1[1] ? src1-src1[1] : 0 vdd11=src1<src1[1] ? src1[1]-src1 : 0 vUD1=math.sum(vud11,9) vDD1=math.sum(vdd11,9) vCMO1=nz((vUD1-vDD1)/(vUD1+vDD1)) VAR1=0.0 VAR1:=nz(valpha1*math.abs(vCMO1)*src1)+(1-valpha1*math.abs(vCMO1))*nz(VAR1[1])VAR1=Var_Func1(src1,stochLength)k = Var_Func1(ta.stoch(close, high, low, periodK), smoothK)k1=k+1000VAR2=Var_Func(k1,stochLength)MAvg3=Var_Func(k1, stochLength)fark3=MAvg3*stochPercent*0.01longStop3 = MAvg3 - fark3longStopPrev3 = nz(longStop3[1], longStop3)longStop3 := MAvg3 > longStopPrev3 ? math.max(longStop3, longStopPrev3) : longStop3shortStop3 = MAvg3 + fark3shortStopPrev3 = nz(shortStop3[1], shortStop3)shortStop3 := MAvg3 < shortStopPrev3 ? math.min(shortStop3, shortStopPrev3) : shortStop3dir3 = 1dir3 := nz(dir3[1], dir3)dir3 := dir3 == -1 and MAvg3 > shortStopPrev3 ? 1 : dir3 == 1 and MAvg3 < longStopPrev3 ? -1 : dir3MT3 = dir3==1 ? longStop3: shortStop3OTTStoch=MAvg3>MT3 ? MT3*(200+stochPercent)/200 : MT3*(200-stochPercent)/200 //------- define the global variables ------var bool long = truevar bool stoppedOutLong = falsevar bool stoppedOutShort = false//-------- determine the market direction --------if OTTFast > OTTSlow long := trueelse if OTTFast < OTTSlow long := false //--------- calculate the input/output points -----------longProfitPrice = strategy.position_avg_price * (1 + tp) // tp -> take profit percentagelongStopPrice = strategy.position_avg_price * (1 - sl) // sl -> stop loss percentageshortProfitPrice = strategy.position_avg_price * (1 - tp)shortStopPrice = strategy.position_avg_price * (1 + sl)//------------------- determine buy and sell points ---------------------buySignall = falsesellSignall = falseif stoch == false buySignall := window() and long and (not stoppedOutLong) sellSignall := window() and (not long) and (not stoppedOutShort)else buySignall := window() and long and (not stoppedOutLong) and ( k1 > OTTStoch ) sellSignall := window() and (not long) and (not stoppedOutShort) and ( k1 < OTTStoch )//---------- execute the strategy -----------------if(longEntry and shortEntry) if long strategy.entry("LONG", strategy.long, when = buySignall, comment = "ENTER LONG") stoppedOutLong := true stoppedOutShort := false else strategy.entry("SHORT", strategy.short, when = sellSignall, comment = "ENTER SHORT") stoppedOutLong := false stoppedOutShort := trueelse if(longEntry) strategy.entry("LONG", strategy.long, when = buySignall) strategy.close("LONG", when = sellSignall) if long stoppedOutLong := true else stoppedOutLong := falseelse if(shortEntry) strategy.entry("SHORT", strategy.short, when = sellSignall) strategy.close("SHORT", when = buySignall) if not long stoppedOutShort := true else stoppedOutShort := false //----------------- take profit and stop loss -----------------if(tp>0.0 and sl>0.0) if ( strategy.position_size > 0 ) strategy.exit(id="LONG", limit=longProfitPrice, stop=longStopPrice, comment="Long TP/SL Trigger") else if ( strategy.position_size < 0 ) strategy.exit(id="SHORT", limit=shortProfitPrice, stop=shortStopPrice, comment="Short TP/SL Trigger")else if(tp>0.0) if ( strategy.position_size > 0 ) strategy.exit(id="LONG", limit=longProfitPrice, comment="Long TP Trigger") else if ( strategy.position_size < 0 ) strategy.exit(id="SHORT", limit=shortProfitPrice, comment="Short TP Trigger") else if(sl>0.0) if ( strategy.position_size > 0 ) strategy.exit(id="LONG", stop=longStopPrice, comment="Long SL Trigger") else if ( strategy.position_size < 0 ) strategy.exit(id="SHORT", stop=shortStopPrice, comment="Short SL Trigger") //------------- plot charts ---------------------lineColor1 = long ? color.green : color.redlineColor2 = long ? color.aqua : color.fuchsialight_green=#08ff12light_red=#fe0808plot(nz(OTTFast), color=light_green, linewidth=3, title="OTT Fast")plot(nz(OTTSlow), color=light_red, linewidth=3, title="OTT Slow")