Zeal Terminal Open in Zeal Terminal

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
25,00050,00075,000100,000125,000AprJulOct2025AprJulOct2026AprJulOct$15,030$40,505Equity from $20,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. 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. The live re-run is not offered here: the script requests BINANCE:BTCUSDT W, which this page cannot load in your browser.
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.

SettingDefaultType and rangeFeeds
Entry Parameters
Entry TypeStopstring · options ['Market', 'Stop', 'Limit', 'Stop-Limit']buyMarketCondition sellMarketCondition buySellStopCondition buyLimitCondition sellLimitCondition buyStopLimitCondition sellStopLimitCondition
Donchian Length40int · step 10top bottom mid hmid htop hbottom
Higher TimeframeWtimeframehmid htop hbottom
Exit Parameters
Stop TypeStopstring · options ['Market', 'Stop']closeBuyMarketCondition closeSellMarketCondition closeBuySellStopCondition
Take Initial ProfitfalsebooltakeProfitBuyCondition takeProfitSellCondition
Risk/Reward (Take Profit)10float · step 0.5profitLong profitShort
Take Profit Percent30int · min 5 · max 100 · step 5exit ProfitLong exit ProfitShort
ATR MA Type (Stop-Limit)smastring · options ['sma', 'ema', 'hma', 'rma', 'vwma', 'wma']atrStop
ATR Length (Stop-Limit22int · step 5atrStop
ATR Multiplier (Stop-Limit)0.5float · step 0.5atrStop
Trade Filters
Trade Directionstrategy.direction.allstring · options [strategy.direction.all, strategy.direction.long, strategy.direction.short]line 33
Start Timetimestamp('01 Jan 2010 00:00 +0000')timeinDateRange
End Timetimestamp('01 Jan 2099 00:00 +0000')timeinDateRange

What it calculates

  • SMA / EMA / HMA / RMA / VWMA / WMAsource, MALengthma · 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.

i_dcLengthDonchian Lengthsetting · 40i_htfResolutionHigher Timeframesetting · Wi_atrMaTypeATR MA Type (Stop-Limit)setting · smai_atrLengthATR Length (Stop-Limitsetting · 22i_atrMultStopATR Multiplier (Stop-Li…setting · 0.5highhighprice datai_takeProfitRRRisk/Reward (Take Profi…setting · 10lowlowprice datai_entryTypeEntry Typesetting · Stopi_stopTypeStop Typesetting · Stoptimetimeprice datai_startTimeStart Timesetting · timestamp('01 Jan 2…i_endTimeEnd Timesetting · timestamp('01 Jan 2…maSMA / EMA / HMA / RMA /…→ matop, bottom, midtop · bottom +13 valueshmid, htop, hbottomhmid · htop +13 valuesatrStopatrStopvaluebuyLevel, closeSellStopbuyLevel · closeSellStop2 valuessellLevel, closeBuyStopsellLevel · closeBuyStop2 valuesbuyStopLimitbuyStopLimitvaluesellStopLimitsellStopLimitvalueprofitLongprofitLongvalueprofitShortprofitShortvaluelongBiaslongBiasconditionshortBiasshortBiasconditioncloseBuyConditioncloseBuyConditionconditioncloseSellConditioncloseSellConditionconditionbuyMarketConditionbuyMarketConditionconditionsellMarketConditionsellMarketConditionconditioncloseBuyMarketConditioncloseBuyMarketConditionconditioncloseSellMarketConditioncloseSellMarketConditionconditionbuySellStopConditionbuySellStopConditionconditionbuyLimitConditionbuyLimitConditionconditionsellLimitConditionsellLimitConditionconditionbuyStopLimitConditionbuyStopLimitConditionconditionsellStopLimitConditionsellStopLimitConditionconditiontakeProfitBuyConditiontakeProfitBuyConditionconditiontakeProfitSellConditiontakeProfitSellConditionconditioninDateRangeinDateRangeconditioncloseBuySellStopConditioncloseBuySellStopConditi…conditioncancel:Shortcancel Shortstrategy.cancelclose:ShortClose Shortstrategy.closeentry:LongOpen Longstrategy.entrycancel:Longcancel Longstrategy.cancelclose:LongClose Longstrategy.closeentry:ShortOpen Shortstrategy.entryexit:StopLongexit StopLongstrategy.exitexit:StopShortexit StopShortstrategy.exitexit:ProfitLongexit ProfitLongstrategy.exitexit:ProfitShortexit ProfitShortstrategy.exitplot:69TOPplotplot:70BOTTOMplotplot:71MIDplotfill:UpperUpperfillfill:LowerLowerfillplot:74HTOPplotplot:75HBOTTOMplotplot:76HMIDplotfill:HTF UpperHTF Upperfillfill:HTF LowerHTF Lowerfill

Order rules

OrderFires whenBy defaultLine
cancel ShortlongBiasOn116
Close ShortlongBiasOn117
Open Long longbuyMarketConditionOn120
Open Long longbuySellStopConditionOn122
Open Long longbuyLimitConditionOn124
Open Long longbuyStopLimitConditionOn126
cancel LongshortBiasOn130
Close LongshortBiasOn131
Open Short shortsellMarketConditionOn134
Open Short shortbuySellStopConditionOn136
Open Short shortsellLimitConditionOn138
Open Short shortsellStopLimitConditionOn140
Close LongcloseBuyCondition and closeBuyMarketConditionOn143
Close ShortcloseSellCondition and closeSellMarketConditionOn146
Exit StopLong stopcloseBuyConditionOn150
Exit StopShort stopcloseSellConditionOn152
Exit ProfitLong limittakeProfitBuyConditionOn155
Exit ProfitShort limittakeProfitSellConditionOn158

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.

2/2trades 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.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−24.9%+102.5%944%0.5838.9%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+13.3%+5.5%540%2.786.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+14.5%+9.8%367%2.3633.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+10.3%+8.4%540%1.7111.5%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−74.2%+16.7%825%0.0679.7%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+7.3%+21.5%540%1.3913.6%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+31.8%+148.3%580%3.7614.4%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−15.3%+17.1%825%0.2915.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 barsTradesWonP&L
Rising market333%−$5,478.28
Sideways market540%−$1,052.26
Falling market1100%$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.

0%61%
All 9 trades
SideEntryExitBarsP&L
long20 May 2024 71,305.9024 Jun 2024 61,319.5035−$2,838.80
long27 Jul 2024 68,474.605 Aug 2024 53,485.909−$3,785.93
long28 Oct 2024 69,519.5013 Jan 2025 90,500.0077$3,998.29
long20 Jan 2025 108,353.0025 Feb 2025 91,231.0036−$2,777.53
long21 May 2025 109,588.0022 Jun 2025 100,372.0032−$1,256.82
long9 Jul 2025 110,530.0022 Aug 2025 111,920.0044$138.05
long1 Oct 2025 117,900.0010 Oct 2025 107,255.009−$1,243.78
short29 Jan 2026 86,074.7017 Mar 2026 74,909.1047$1,560.05
short28 May 2026 73,724.3019 Aug 2026 66,956.1083$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.

ScriptSharesTypeNetTradesMax drawdown
Strategy Template - V2 this page—v5 strategy−24.9%938.9%
Smoothed Heikin Ashi Trend on Chart - TraderHalai BACKTEST by TraderHalaisma ema hma vwma rmav5 strategy+1.3%1135.6%
High-Low Channel Multi averages Crypto Swing strategy by exlux99sma ema wma rma vwmav4 strategyNo trades on this market
Ultra Moving Average Rating Trend Strategy by exlux99ema wma sma rma vwma hmav5 strategy+2.8%52.4%
VCP pivot buy by perrycc007sma ema rma vwma wmav4 strategydoes not run in Zeal Terminal
Multi Trend Cross Strategy Template by TradeAutomationema hma rma sma vwma wmav5 strategy+33.0%37.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

Verified

Nothing 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 44 msWith a workaround 1,000 bars in 97 msNot measured
PineTSNot testedNot testedNot 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")