Pine Script v5 · Strategy
Strategy Template - V2
A Pine Script v5 strategy built on SMA or EMA or HMA or RMA or VWMA or WMA (source, MALength). It has 18 order rules, 8 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.11% commission. 13 settings; defaults include Entry Type Stop, Donchian Length 40 and Higher Timeframe W.
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 Strategy Template - V2 repaint?
- Yes
- At least one pattern in the source can repaint: higher-timeframe data.
- How did Strategy Template - V2 do on BTCUSDT 1D with default settings?
- −24.85%
- From 26 Jan 2024 to 21 Oct 2026, over 9 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Strategy Template - V2 run in Pine Script v6?
- No
- The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 9 before, 26 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does Strategy Template - V2 use a stop loss?
- Yes
- strategy.exit sets a stop on line 150, 152.
- Does Strategy Template - V2 run in Zeal Terminal?
- Yes
- It compiles in 44 ms and runs 1,000 bars in 97 ms, in the browser.
BTCUSDT · 1D · default settings
- TOP
- BOTTOM
- MID
- HTOP
- HBOTTOM
- HMID
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −24.85%
- −$4,970.50
- Buy and hold
- +102.5%
- same period
- Closed trades
- 9
- 4 won · 5 lost
- Profitable
- 44.4%
- of closed trades
- Profit factor
- 0.58
- gross profit ÷ gross loss
- Max drawdown
- 38.90%
- −$7,779.97
One run with the author's default settings, $20,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.
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 |
|---|---|---|---|
| Entry Parameters | |||
| Entry Type | Stop | string · options ['Market', 'Stop', 'Limit', 'Stop-Limit'] | buyMarketCondition sellMarketCondition buySellStopCondition buyLimitCondition sellLimitCondition buyStopLimitCondition sellStopLimitCondition |
| Donchian Length | 40 | int · step 10 | top bottom mid hmid htop hbottom |
| Higher Timeframe | W | timeframe | hmid htop hbottom |
| Exit Parameters | |||
| Stop Type | Stop | string · options ['Market', 'Stop'] | closeBuyMarketCondition closeSellMarketCondition closeBuySellStopCondition |
| Take Initial Profit | false | bool | takeProfitBuyCondition takeProfitSellCondition |
| Risk/Reward (Take Profit) | 10 | float · step 0.5 | profitLong profitShort |
| Take Profit Percent | 30 | int · min 5 · max 100 · step 5 | exit ProfitLong exit ProfitShort |
| ATR MA Type (Stop-Limit) | sma | string · options ['sma', 'ema', 'hma', 'rma', 'vwma', 'wma'] | atrStop |
| ATR Length (Stop-Limit | 22 | int · step 5 | atrStop |
| ATR Multiplier (Stop-Limit) | 0.5 | float · step 0.5 | atrStop |
| Trade Filters | |||
| Trade Direction | strategy.direction.all | string · options [strategy.direction.all, strategy.direction.long, strategy.direction.short] | line 33 |
| Start Time | timestamp('01 Jan 2010 00:00 +0000') | time | inDateRange |
| End Time | timestamp('01 Jan 2099 00:00 +0000') | time | inDateRange |
What it calculates
- SMA / EMA / HMA / RMA / VWMA / WMAsource, MALength
ma · line 41
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 |
|---|---|---|---|
| cancel Short | longBias | On | 116 |
| Close Short | longBias | On | 117 |
| Open Long long | buyMarketCondition | On | 120 |
| Open Long long | buySellStopCondition | On | 122 |
| Open Long long | buyLimitCondition | On | 124 |
| Open Long long | buyStopLimitCondition | On | 126 |
| cancel Long | shortBias | On | 130 |
| Close Long | shortBias | On | 131 |
| Open Short short | sellMarketCondition | On | 134 |
| Open Short short | buySellStopCondition | On | 136 |
| Open Short short | sellLimitCondition | On | 138 |
| Open Short short | sellStopLimitCondition | On | 140 |
| Close Long | closeBuyCondition and closeBuyMarketCondition | On | 143 |
| Close Short | closeSellCondition and closeSellMarketCondition | On | 146 |
| Exit StopLong stop | closeBuyCondition | On | 150 |
| Exit StopShort stop | closeSellCondition | On | 152 |
| Exit ProfitLong limit | takeProfitBuyCondition | On | 155 |
| Exit ProfitShort limit | takeProfitSellCondition | On | 158 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
Yes
At least one pattern in the source can repaint; it is marked Check below.
- CheckHigher-timeframe data1 request.security call(s) use lookahead_on (line 39). Without a [1] offset this reads future bars in history.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
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 | −24.9% | +102.5% | 9 | 44% | 0.58 | 38.9% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +13.3% | +5.5% | 5 | 40% | 2.78 | 6.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +14.5% | +9.8% | 3 | 67% | 2.36 | 33.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +10.3% | +8.4% | 5 | 40% | 1.71 | 11.5% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −74.2% | +16.7% | 8 | 25% | 0.06 | 79.7% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +7.3% | +21.5% | 5 | 40% | 1.39 | 13.6% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +31.8% | +148.3% | 5 | 80% | 3.76 | 14.4% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −15.3% | +17.1% | 8 | 25% | 0.29 | 15.3% | 8 May 2026 – 21 Oct 2026 |
Higher-timeframe data for request.security(): BINANCE:BTCUSDT W (Binance BTCUSDT 1w), fetched from Binance's public market data for each market.
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 | 3 | 33% | −$5,478.28 |
| Sideways market | 5 | 40% | −$1,052.26 |
| Falling market | 1 | 100% | $1,560.05 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
52.9%
The 95th percentile of the worst drawdown when the same 9 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 29.3% to 52.9%; the tick is what actually happened, 38.8%. Order luck alone moves it this much.
All 9 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 20 May 2024 71,305.90 | 24 Jun 2024 61,319.50 | 35 | −$2,838.80 |
| long | 27 Jul 2024 68,474.60 | 5 Aug 2024 53,485.90 | 9 | −$3,785.93 |
| long | 28 Oct 2024 69,519.50 | 13 Jan 2025 90,500.00 | 77 | $3,998.29 |
| long | 20 Jan 2025 108,353.00 | 25 Feb 2025 91,231.00 | 36 | −$2,777.53 |
| long | 21 May 2025 109,588.00 | 22 Jun 2025 100,372.00 | 32 | −$1,256.82 |
| long | 9 Jul 2025 110,530.00 | 22 Aug 2025 111,920.00 | 44 | $138.05 |
| long | 1 Oct 2025 117,900.00 | 10 Oct 2025 107,255.00 | 9 | −$1,243.78 |
| short | 29 Jan 2026 86,074.70 | 17 Mar 2026 74,909.10 | 47 | $1,560.05 |
| short | 28 May 2026 73,724.30 | 19 Aug 2026 66,956.10 | 83 | $1,235.98 |
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 |
|---|---|---|---|---|---|
| Strategy Template - V2 this page | — | v5 strategy | −24.9% | 9 | 38.9% |
| Smoothed Heikin Ashi Trend on Chart - TraderHalai BACKTEST by TraderHalai | sma ema hma vwma rma | v5 strategy | +1.3% | 113 | 5.6% |
| High-Low Channel Multi averages Crypto Swing strategy by exlux99 | sma ema wma rma vwma | v4 strategy | No trades on this market | ||
| Ultra Moving Average Rating Trend Strategy by exlux99 | ema wma sma rma vwma hma | v5 strategy | +2.8% | 5 | 2.4% |
| VCP pivot buy by perrycc007 | sma ema rma vwma wma | v4 strategy | does not run in Zeal Terminal | ||
| Multi Trend Cross Strategy Template by TradeAutomation | ema hma rma sma vwma wma | v5 strategy | +33.0% | 3 | 7.3% |
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.
- No v6-only features. v6 is not needed to run this script.
Clean v5
VerifiedNothing to change.
Does it run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 9 before, 26 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯//-//@version=5+//@version=6//########################################### Strategy definition ######################################################/⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 44 ms | With a workaround 1,000 bars in 97 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/// © HeWhoMustNotBeNamed// __ __ __ __ __ __ __ __ __ __ __ _______ __ __ __ // / | / | / | _ / |/ | / \ / | / | / \ / | / | / \ / \ / | / |// $$ | $$ | ______ $$ | / \ $$ |$$ |____ ______ $$ \ /$$ | __ __ _______ _$$ |_ $$ \ $$ | ______ _$$ |_ $$$$$$$ | ______ $$ \ $$ | ______ _____ ____ ______ ____$$ |// $$ |__$$ | / \ $$ |/$ \$$ |$$ \ / \ $$$ \ /$$$ |/ | / | / |/ $$ | $$$ \$$ | / \ / $$ | $$ |__$$ | / \ $$$ \$$ | / \ / \/ \ / \ / $$ |// $$ $$ |/$$$$$$ |$$ /$$$ $$ |$$$$$$$ |/$$$$$$ |$$$$ /$$$$ |$$ | $$ |/$$$$$$$/ $$$$$$/ $$$$ $$ |/$$$$$$ |$$$$$$/ $$ $$< /$$$$$$ |$$$$ $$ | $$$$$$ |$$$$$$ $$$$ |/$$$$$$ |/$$$$$$$ |// $$$$$$$$ |$$ $$ |$$ $$/$$ $$ |$$ | $$ |$$ | $$ |$$ $$ $$/$$ |$$ | $$ |$$ \ $$ | __ $$ $$ $$ |$$ | $$ | $$ | __ $$$$$$$ |$$ $$ |$$ $$ $$ | / $$ |$$ | $$ | $$ |$$ $$ |$$ | $$ |// $$ | $$ |$$$$$$$$/ $$$$/ $$$$ |$$ | $$ |$$ \__$$ |$$ |$$$/ $$ |$$ \__$$ | $$$$$$ | $$ |/ |$$ |$$$$ |$$ \__$$ | $$ |/ |$$ |__$$ |$$$$$$$$/ $$ |$$$$ |/$$$$$$$ |$$ | $$ | $$ |$$$$$$$$/ $$ \__$$ |// $$ | $$ |$$ |$$$/ $$$ |$$ | $$ |$$ $$/ $$ | $/ $$ |$$ $$/ / $$/ $$ $$/ $$ | $$$ |$$ $$/ $$ $$/ $$ $$/ $$ |$$ | $$$ |$$ $$ |$$ | $$ | $$ |$$ |$$ $$ |// $$/ $$/ $$$$$$$/ $$/ $$/ $$/ $$/ $$$$$$/ $$/ $$/ $$$$$$/ $$$$$$$/ $$$$/ $$/ $$/ $$$$$$/ $$$$/ $$$$$$$/ $$$$$$$/ $$/ $$/ $$$$$$$/ $$/ $$/ $$/ $$$$$$$/ $$$$$$$/ // // ////@version=5//########################################### Strategy definition ######################################################/strategy('Strategy Template - V2', overlay=true, initial_capital=20000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, pyramiding=1, commission_value=0.11, max_lines_count=500, max_labels_count=500, max_boxes_count=500)//########################################### Entry and exit parameters ######################################################/i_entryType = input.string('Stop', title='Entry Type', options=['Market', 'Stop', 'Limit', 'Stop-Limit'], group='Entry Parameters')i_dcLength = input.int(40, step=10, title='Donchian Length', group='Entry Parameters')i_htfResolution = input.timeframe('W', title='Higher Timeframe', group='Entry Parameters')i_stopType = input.string('Stop', title='Stop Type', options=['Market', 'Stop'], group='Exit Parameters')i_takeProfit = input.bool(false, title='Take Initial Profit', group='Exit Parameters')i_takeProfitRR = input.float(10, step=0.5, title='Risk/Reward (Take Profit)', group='Exit Parameters')i_takeProfitQty = input.int(30, step=5, minval=5, maxval=100, title='Take Profit Percent', group='Exit Parameters')i_atrMaType = input.string('sma', title='ATR MA Type (Stop-Limit)', options=['sma', 'ema', 'hma', 'rma', 'vwma', 'wma'], group='Exit Parameters')i_atrLength = input.int(22, title='ATR Length (Stop-Limit', step=5, group='Exit Parameters')i_atrMultStop = input.float(0.5, step=0.5, title='ATR Multiplier (Stop-Limit)', group='Exit Parameters')//############################################ Generic Strategy Parameters ###################################################/i_tradeDirection = input.string(title='Trade Direction', defval=strategy.direction.all, options=[strategy.direction.all, strategy.direction.long, strategy.direction.short], group='Trade Filters')strategy.risk.allow_entry_in(i_tradeDirection)i_startTime = input.time(defval=timestamp('01 Jan 2010 00:00 +0000'), title='Start Time', group='Trade Filters')i_endTime = input.time(defval=timestamp('01 Jan 2099 00:00 +0000'), title='End Time', group='Trade Filters')inDateRange = time >= i_startTime and time <= i_endTime//################################################## Generic Methods #########################################################/f_secureSecurity(_symbol, _res, _src, _offset) => request.security(_symbol, _res, _src[_offset], lookahead=barmerge.lookahead_on)f_getMovingAverage(source, MAType, MALength) => ma = ta.sma(source, MALength) if MAType == 'ema' ma := ta.ema(source, MALength) ma if MAType == 'hma' ma := ta.hma(source, MALength) ma if MAType == 'rma' ma := ta.rma(source, MALength) ma if MAType == 'vwma' ma := ta.vwma(source, MALength) ma if MAType == 'wma' ma := ta.wma(source, MALength) ma maf_getCustomAtr(MAType, MALength) => f_getMovingAverage(ta.tr, MAType, MALength)f_get_donchian(dcLength, resolution) => top = resolution == '' ? ta.highest(dcLength) : f_secureSecurity(syminfo.tickerid, resolution, ta.highest(dcLength), 1) bottom = resolution == '' ? ta.lowest(dcLength) : f_secureSecurity(syminfo.tickerid, resolution, ta.lowest(dcLength), 1) mid = (top + bottom) / 2 [mid, top, bottom]//###################################################### Calculation and plot ##########################################################/[mid, top, bottom] = f_get_donchian(i_dcLength, '')[hmid, htop, hbottom] = f_get_donchian(i_dcLength, i_htfResolution)atrStop = f_getCustomAtr(i_atrMaType, i_atrLength) * i_atrMultStopp_top = plot(top, 'TOP', color=color.new(color.lime, 80))p_bottom = plot(bottom, 'BOTTOM', color=color.new(color.orange, 80))p_mid = plot(mid, 'MID', color=color.new(color.blue, 80))fill(p_top, p_mid, title='Upper', color=color.new(color.lime, 80))fill(p_bottom, p_mid, title='Lower', color=color.new(color.orange, 80))p_htop = plot(htop, 'HTOP', color=color.new(color.green, 80))p_hbottom = plot(hbottom, 'HBOTTOM', color=color.new(color.red, 80))p_hmid = plot(hmid, 'HMID', color=color.new(color.purple, 80))fill(p_htop, p_hmid, title='HTF Upper', color=color.new(color.green, 80))fill(p_hbottom, p_hmid, title='HTF Lower', color=color.new(color.red, 80))// ########################################### Trade conditions and levels ################################################/longBias = bottom > hmid and inDateRangeshortBias = top < hmid and inDateRangecloseBuyCondition = strategy.position_size > 0closeSellCondition = strategy.position_size < 0// Market order conditionsbuyMarketCondition = ta.crossover(high, top[1]) and i_entryType == 'Market'sellMarketCondition = ta.crossunder(low, bottom[1]) and i_entryType == 'Market'closeBuyMarketCondition = ta.crossunder(low, bottom[1]) and i_stopType == 'Market' and not longBiascloseSellMarketCondition = ta.crossover(high, top[1]) and i_stopType == 'Market' and not shortBias// Stop order conditionsbuySellStopCondition = i_entryType == 'Stop'closeBuySellStopCondition = i_stopType == 'Stop'// Limit and stoplimit conditionsbuyLimitCondition = i_entryType == 'Limit' and high > midsellLimitCondition = i_entryType == 'Limit' and low < midbuyStopLimitCondition = i_entryType == 'Stop-Limit' and ta.crossover(high, top[1])sellStopLimitCondition = i_entryType == 'Stop-Limit' and ta.crossunder(low, bottom[1])// Entry levels for long and short orders via Stop, Limit and Stop-LimitbuyLevel = topsellLevel = bottombuyStopLimit = top + atrStopsellStopLimit = bottom - atrStop// Exit levels for long and short - to be used in Stop orderscloseBuyStop = bottomcloseSellStop = top// Take profit conditions and levels for long and short - to be used in Take Profit exit orderstakeProfitBuyCondition = longBias and strategy.position_size > 0 and i_takeProfittakeProfitSellCondition = shortBias and strategy.position_size < 0 and i_takeProfitprofitLong = top + i_takeProfitRR * (top - bottom)profitShort = bottom - i_takeProfitRR * (top - bottom)profitLong := strategy.position_size <= 0 ? profitLong : high[1] > profitLong[1] ? profitLong[1] + i_takeProfitRR * (top - bottom) : profitLong[1]profitShort := strategy.position_size >= 0 ? profitShort : low[1] < profitShort[1] ? profitShort[1] - i_takeProfitRR * (top - bottom) : profitShort[1]// ########################################### Trade Statements Using If-Blocks ################################################///Entry for Long Ordersif longBias //Cancel short pending orders and close existing short trades strategy.cancel('Short') strategy.close('Short') //Long entry based on entry type - market, stop, limit or stop-limit if buyMarketCondition strategy.entry('Long', strategy.long, comment='Long-Market-Order') if buySellStopCondition strategy.entry('Long', strategy.long, stop=buyLevel, oca_name='oca_buy', oca_type=strategy.oca.cancel, comment='Long-Stop-Order') if buyLimitCondition strategy.entry('Long', strategy.long, limit=buyLevel, oca_name='oca_buy', oca_type=strategy.oca.cancel, comment='Long-Limit-Order') if buyStopLimitCondition strategy.entry('Long', strategy.long, limit=buyStopLimit, stop=buyLevel, oca_name='oca_buy', oca_type=strategy.oca.cancel, comment='Long-Stop-Limit-Order')//Entry for Short Ordersif shortBias //Cancel long pending orders and close existing long trades strategy.cancel('Long') strategy.close('Long') //Short entry based on entry type - market, stop, limit or stop-limit if sellMarketCondition strategy.entry('Short', strategy.short, comment='Short-Market-Order') if buySellStopCondition strategy.entry('Short', strategy.short, stop=sellLevel, oca_name='oca_sell', oca_type=strategy.oca.cancel, comment='Short-Stop-Order') if sellLimitCondition strategy.entry('Short', strategy.short, limit=sellLevel, oca_name='oca_sell', oca_type=strategy.oca.cancel, comment='Short-Limit-Order') if sellStopLimitCondition strategy.entry('Short', strategy.short, limit=sellStopLimit, stop=sellLevel, oca_name='oca_sell', oca_type=strategy.oca.cancel, comment='Short-Stop-Limit-Order')//Exit Long order market conditionif closeBuyCondition and closeBuyMarketCondition strategy.close('Long', comment='Close-Long-Market')//Exit Short order by market conditionif closeSellCondition and closeSellMarketCondition strategy.close('Short', comment='Close-Short-Market')//Exit by stoploss - Set stoploss beforehandif closeBuySellStopCondition if closeBuyCondition strategy.exit('StopLong', 'Long', stop=closeBuyStop, comment='Close-Buy-Stop') if closeSellCondition strategy.exit('StopShort', 'Short', stop=closeSellStop, comment='Close-Sell-Stop')// Take Profit for Long Orderif takeProfitBuyCondition strategy.exit('ProfitLong', 'Long', limit=profitLong, qty_percent=i_takeProfitQty, comment='Close-Buy-Profit')// Take Profit for Short Orderif takeProfitSellCondition strategy.exit('ProfitShort', 'Short', limit=profitShort, qty_percent=i_takeProfitQty, comment='Close-Sell-Profit')// ########################################### Trade Statements Using When - Alternative method ################################################/// //Cancen pending orders when market changes its bias// strategy.cancel("Long", when=shortBias)// strategy.cancel("Short", when=longBias)// //Close existing trades when market changes its bias// strategy.close("Long", when=shortBias)// strategy.close("Short", when=longBias)// //Market orders when Entry Type = Market// strategy.entry("Long", strategy.long, when=longBias and buyMarketCondition, comment = "Long-Market-Order")// strategy.entry("Short", strategy.short, when=shortBias and sellMarketCondition, comment = "Short-Market-Order")// //Stop orders when Entry Type = Stop (Buy at higher price and sell at lower price) - suitable for trend following methods// strategy.entry("Long", strategy.long, when=longBias and buySellStopCondition, stop=buyLevel,// oca_name="oca_buy", oca_type=strategy.oca.cancel, comment = "Long-Stop-Order")// strategy.entry("Short", strategy.short, when=shortBias and buySellStopCondition, stop=sellLevel,// oca_name="oca_sell", oca_type=strategy.oca.cancel, comment = "Short-Stop-Order")// //Limit orders when Entry Type = Limit// strategy.entry("Long", strategy.long, when=longBias and buyLimitCondition, limit=buyLevel,// oca_name="oca_buy", oca_type=strategy.oca.cancel, comment = "Long-Limit-Order")// strategy.entry("Short", strategy.short, when=shortBias and sellLimitCondition, stop=sellLevel,// oca_name="oca_sell", oca_type=strategy.oca.cancel, comment = "Short-Limit-Order")// //Stop-limit orders when Entry Type = Stop-Limit (Buy at higher price and sell at lower price but with protection) - suitable for trend following methods// strategy.entry("Long", strategy.long, when=longBias and buyStopLimitCondition, limit=buyStopLimit, stop=buyLevel,// oca_name="oca_buy", oca_type=strategy.oca.cancel, comment = "Long-Stop-Limit-Order")// strategy.entry("Short", strategy.short, when=shortBias and sellStopLimitCondition, limit=sellStopLimit, stop=sellLevel,// oca_name="oca_sell", oca_type=strategy.oca.cancel, comment = "Short-Stop-Limit-Order")// // Stoploss - Exit by market// strategy.close("Long", when=closeBuyCondition and closeBuyMarketCondition, comment="Close-Long-Market")// strategy.close("Short", when=closeSellCondition and closeSellMarketCondition, comment="Close-Short-Market")// // Stoploss - Exit by stop// strategy.exit("StopLong", "Long", stop=closeBuyStop, when=closeBuyCondition and closeBuySellStopCondition, comment="Close-Buy-Stop")// strategy.exit("StopShort", "Short", stop=closeSellStop, when=closeSellCondition and closeBuySellStopCondition, comment="Close-Sell-Stop")// // Take Profit// strategy.exit("ProfitLong", "Long", limit=profitLong, when=takeProfitBuyCondition, qty_percent=i_takeProfitQty, comment="Close-Buy-Profit")// strategy.exit("ProfitShort", "Short", limit=profitShort, when=takeProfitSellCondition, qty_percent=i_takeProfitQty, comment="Close-Sell-Profit")