Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

COT + ema + aux ticker

A Pine Script v4 strategy built on EMA (close, 4). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade commits 10% of equity and pays no commission. 18 settings; defaults include Start Date 1, Start Month 1 and Start Year 2010.

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 COT + ema + aux ticker repaint?
Yes
At least one pattern in the source can repaint: higher-timeframe data.
How did COT + ema + aux ticker 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.
Can COT + ema + aux ticker be converted to Pine Script v5?
Not tested
The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
Does COT + ema + aux ticker use a stop loss?
Yes
strategy.exit sets a stop on line 122, 126.
Does COT + ema + aux ticker run in Zeal Terminal?
Yes
It compiles in 26 ms and runs 1,000 bars in 62 ms, in the browser.

BTCUSDT · 1D · default settings

  • EMA
  • EMA
  • EMA
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$100,000$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference. 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 DELL W, QUANDL:CFTC/099741_F_L_ALL|5 W, QUANDL:CFTC/099741_F_L_ALL|4 W, which this page cannot load in your browser.

Needs DELL W data, not available: not a Binance spot market Needs QUANDL:CFTC/099741_F_L_ALL|5 W data, not available: not a Binance spot market Needs QUANDL:CFTC/099741_F_L_ALL|4 W data, not available: not a Binance spot market Values that depend on it are empty on this chart.

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, $100,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 commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

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 ema → ta.ema, security → request.security.

v4 → v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 3: //@version=4 → //@version=5
  • Line 7: input(type = input.integer) → input.int()
  • Line 9: input(type = input.integer) → input.int()
  • Line 11: input(type = input.integer) → input.int()
  • Line 15: input(type = input.string) → input.string()
  • Line 16: input(type = input.string) → input.string()
17 more edits
  • Line 17: input(type = input.bool) → input.bool()
  • Line 18: input(type = input.bool) → input.bool()
  • Line 22: ema → ta.ema
  • Line 23: input(type = input.bool) → input.bool()
  • Line 24: input(type = input.bool) → input.bool()
  • Line 26: input(type = input.symbol) → input.symbol()
  • Line 27: security → request.security
  • Line 28: ema → ta.ema
  • Line 29: input(type = input.bool) → input.bool()
  • Line 30: input(type = input.bool) → input.bool()
  • Line 32: input(type = input.symbol) → input.symbol()
  • Line 33: security → request.security
  • Line 34: ema → ta.ema
  • Line 79: security → request.security
  • Line 80: security → request.security
  • Line 87: security → request.security
  • Line 88: security → request.security
⋯// © Noldo-//@version=4+//@version=5strategy("COT + ema + aux ticker", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)⋯bFX = false -startDate = input(title="Start Date", type=input.integer,+startDate = input.int(title="Start Date",     defval=1, minval=1, maxval=31)-startMonth = input(title="Start Month", type=input.integer,+startMonth = input.int(title="Start Month",     defval=1, minval=1, maxval=12)-startYear = input(title="Start Year", type=input.integer,+startYear = input.int(title="Start Year",     defval=2010, minval=1800, maxval=2100)⋯     startYear, startMonth, startDate, 0, 0))-string ticket00 = input(defval='EUR', type=input.string, options=["AUD","GBP","CAD","EUR","JPY","CHF","NZD","USD"], title='1st', group='Tickets:', inline='T0')+string ticket00 = input.string(defval='EUR', options=["AUD","GBP","CAD","EUR","JPY","CHF","NZD","USD"], title='1st', group='Tickets:', inline='T0')-string ticket01 = input(defval='EUR', type=input.string, options=["AUD","GBP","CAD","EUR","JPY","CHF","NZD","USD"],title='2nd', group='Tickets:', inline='T0')+string ticket01 = input.string(defval='EUR', options=["AUD","GBP","CAD","EUR","JPY","CHF","NZD","USD"],title='2nd', group='Tickets:', inline='T0')-usecot = input(title="COT ON/OFF", type=input.bool, defval=true)+usecot = input.bool(title="COT ON/OFF", defval=true)-useema = input(title="EMA ON/OFF", type=input.bool, defval=true)+useema = input.bool(title="EMA ON/OFF", defval=true)len = input(4, minval=1, title="Length")⋯offset = input(title="Offset COT", defval=0, minval=0, maxval=10)-out = ema(srcsma, len)+out = ta.ema(srcsma, len)-useaux1 = input(title="Aux 1 ON/OFF", type=input.bool, defval=true)+useaux1 = input.bool(title="Aux 1 ON/OFF", defval=true)-auxinv1 = input(title="Aux 1 inv.", type=input.bool, defval=false)+auxinv1 = input.bool(title="Aux 1 inv.", defval=false)lenaux1 = input( 4, minval=1, title="Ema aux 1 period.")-auxsma1 = input(title="AUX Symbol", type=input.symbol, defval="DELL")+auxsma1 = input.symbol(title="AUX Symbol", defval="DELL")-s1 = security(auxsma1, "W", close)+s1 = request.security(auxsma1, "W", close)-outaux1 = ema(s1, lenaux1)+outaux1 = ta.ema(s1, lenaux1)-useaux2 = input(title="Aux 2 ON/OFF", type=input.bool, defval=true)+useaux2 = input.bool(title="Aux 2 ON/OFF", defval=true)-auxinv2 = input(title="Aux 2 inv.", type=input.bool, defval=false)+auxinv2 = input.bool(title="Aux 2 inv.", defval=false)lenaux2 = input( 4, minval=1, title="Ema aux 2 period.")-auxsma2 = input(title="AUX 2 Symbol", type=input.symbol, defval="DELL")+auxsma2 = input.symbol(title="AUX 2 Symbol", defval="DELL")-s2 = security(auxsma2, "W", close)+s2 = request.security(auxsma2, "W", close)-outaux2 = ema(s2, lenaux2)+outaux2 = ta.ema(s2, lenaux2)//Can't set bFX as an input because plot and legend titles require literals⋯//Data functions-dLong(asCode) =>  security(sHead + asCode + (sLong),   "W", close[0 + offset] - close[1 + offset], lookahead=barmerge.lookahead_on)+dLong(asCode) =>  request.security(sHead + asCode + (sLong),   "W", close[0 + offset] - close[1 + offset], lookahead=barmerge.lookahead_on)-dShort(asCode) => security(sHead +asCode + (sShort),   "W", close[0 + offset] - close[1 + offset], lookahead=barmerge.lookahead_on)+dShort(asCode) => request.security(sHead +asCode + (sShort),   "W", close[0 + offset] - close[1 + offset], lookahead=barmerge.lookahead_on)// COMMERCIALS 1 ticker ⋯sTitle2 =  "2nd Ticker"-dLong2(asCode2) =>  security(sHead + asCode2 + (sLong),   "W", close[0 + offset] - close[1 + offset], lookahead=barmerge.lookahead_on)+dLong2(asCode2) =>  request.security(sHead + asCode2 + (sLong),   "W", close[0 + offset] - close[1 + offset], lookahead=barmerge.lookahead_on)-dShort2(asCode2) => security(sHead +asCode2 + (sShort),   "W", close[0 + offset] - close[1 + offset], lookahead=barmerge.lookahead_on)+dShort2(asCode2) => request.security(sHead +asCode2 + (sShort),   "W", close[0 + offset] - close[1 + offset], lookahead=barmerge.lookahead_on)_pos_coms2_long    =  dLong2(sCode2)⋯

Clean v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 19: input() → input.int()
  • Line 20: input() → input.source()
  • Line 21: input() → input.int()
  • Line 25: input() → input.int()
  • Line 31: input() → input.int()
⋯useema = input.bool(title="EMA ON/OFF", defval=true)-len = input(4, minval=1, title="Length")+len = input.int(4, minval=1, title="Length")-srcsma = input(close, title="Source")+srcsma = input.source(close, title="Source")-offset = input(title="Offset COT", defval=0, minval=0, maxval=10)+offset = input.int(title="Offset COT", defval=0, minval=0, maxval=10)out = ta.ema(srcsma, len)⋯auxinv1 = input.bool(title="Aux 1 inv.", defval=false)-lenaux1 = input( 4, minval=1, title="Ema aux 1 period.")+lenaux1 = input.int( 4, minval=1, title="Ema aux 1 period.")auxsma1 = input.symbol(title="AUX Symbol", defval="DELL")⋯auxinv2 = input.bool(title="Aux 2 inv.", defval=false)-lenaux2 = input( 4, minval=1, title="Ema aux 2 period.")+lenaux2 = input.int( 4, minval=1, title="Ema aux 2 period.")auxsma2 = input.symbol(title="AUX 2 Symbol", defval="DELL")⋯

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.

⋯// © Noldo-//@version=5+//@version=6strategy("COT + ema + aux ticker", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)⋯

Settings

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

SettingDefaultType and rangeFeeds
Start Date1int (written input.integer) · min 1 · max 31afterStartDate
Start Month1int (written input.integer) · min 1 · max 12afterStartDate
Start Year2010int (written input.integer) · min 1800 · max 2100afterStartDate
COT ON/OFFtrueboolbuy_cot sell_cot
EMA ON/OFFtrueboolbuy_ema sell_ema
Length4int · min 1out
Sourceclosesourceout
Offset COT0int · min 0 · max 10line 79 line 80 line 87 line 88
Aux 1 ON/OFFtrueboolbuy_aux1 sell_aux1
Aux 1 inv.falseboolline 106 line 109
Ema aux 1 period.4int · min 1outaux1
AUX SymbolDELLsymbols1
Aux 2 ON/OFFtrueboolbuy_aux2 sell_aux2
Aux 2 inv.falseboolline 112 line 115
Ema aux 2 period.4int · min 1outaux2
AUX 2 SymbolDELLsymbols2
Tickets:
1stEURstring · options ["AUD","GBP","CAD","EUR","JPY","CHF","NZD","USD"]sCode1
2ndEURstring · options ["AUD","GBP","CAD","EUR","JPY","CHF","NZD","USD"]sCode2

What it calculates

  • EMA (ema, ta.ema in v5)Source (close), Length (4)out · line 22
  • EMA (ema, ta.ema in v5)s1, Ema aux 1 period. (4)outaux1 · line 28
  • EMA (ema, ta.ema in v5)s2, Ema aux 2 period. (4)outaux2 · line 34

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.

closecloseprice datalenLengthsetting · 4lenaux1Ema aux 1 period.setting · 4lenaux2Ema aux 2 period.setting · 4auxsma1AUX Symbolsetting · DELLauxsma2AUX 2 Symbolsetting · DELLticket001stsetting · EURticket012ndsetting · EURtimetimeprice datastartYearStart Yearsetting · 2010startMonthStart Monthsetting · 1startDateStart Datesetting · 1outEMA→ outoutaux1EMA→ outaux1outaux2EMA→ outaux2srcsrcvalues1s1values2s2valuesCode1sCode1valuesCode2sCode2value_pos_coms1_short, _pos_coms1_long_pos_coms1_short · _pos…2 valuesnet_com1net_com1value_pos_coms2_long, _pos_coms2_short_pos_coms2_long · _pos_…2 valuesnet_com2net_com2valuebuybuyconditionsellsellconditionafterStartDateafterStartDateconditionbTotal, bTotal2bTotal · bTotal22 conditionsbuy_aux1, sell_aux1buy_aux1 · sell_aux12 conditionsbuy_aux2, sell_aux2buy_aux2 · sell_aux22 conditionsbuy_cot, sell_cotbuy_cot · sell_cot2 conditionsbuy_ema, sell_emabuy_ema · sell_ema2 conditionsentry:ShortOpen Shortstrategy.entryexit:SL-TP Shortexit SL-TP Shortstrategy.exitentry:LongOpen Longstrategy.entryexit:SL-TP Longexit SL-TP Longstrategy.exitclose:ShortClose Shortstrategy.closeclose:LongClose Longstrategy.closeplotshape:134plotshapeplotshapeplotshape:135plotshapeplotshape

Order rules

OrderFires whenBy defaultLine
Open Short short(sell)On121
Exit SL-TP Short stop(sell)On122
Open Long long(buy)On125
Exit SL-TP Long stop(buy)On126
Close Shortstrategy.openprofit > 0On132
Close Longstrategy.openprofit > 0On133

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • CheckHigher-timeframe data4 security call(s) use lookahead_on (line 79, 80, 87, 88). 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

Not run on other markets: the script requests DELL W, QUANDL:CFTC/099741_F_L_ALL|5 W, QUANDL:CFTC/099741_F_L_ALL|4 W, and that data is not available here (not a Binance spot market; not a Binance spot market; not a Binance spot market). Its results would rest on empty values.

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
COT + ema + aux ticker this page—v4 strategy0.0%00.0%
EMA Slope AyE by fajardoarelysemav4 strategyNo trades on this market
ROoT by realisticDove62527emav5 strategy−4.7%2259.4%
sachin5986 by mohitesachin78emav4 strategy+32.1%3517.6%
sonu1997 by Sonu1997emav4 strategy+960.7%21,103.8%
Moving Average Crossover by Muh4mm4demav4 strategy+19,990.1%301,274.2%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 26 msWith a workaround 1,000 bars in 62 msNot measured
PineTSNo v5 and v6 only—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. 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/// © Noldo//@version=4strategy("COT + ema + aux ticker", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)src = closebFX = false startDate = input(title="Start Date", type=input.integer,     defval=1, minval=1, maxval=31)startMonth = input(title="Start Month", type=input.integer,     defval=1, minval=1, maxval=12)startYear = input(title="Start Year", type=input.integer,     defval=2010, minval=1800, maxval=2100)afterStartDate = (time >= timestamp(syminfo.timezone,     startYear, startMonth, startDate, 0, 0))string ticket00 = input(defval='EUR', type=input.string, options=["AUD","GBP","CAD","EUR","JPY","CHF","NZD","USD"], title='1st', group='Tickets:', inline='T0')string ticket01 = input(defval='EUR', type=input.string, options=["AUD","GBP","CAD","EUR","JPY","CHF","NZD","USD"],title='2nd', group='Tickets:', inline='T0')usecot = input(title="COT ON/OFF", type=input.bool, defval=true)useema = input(title="EMA ON/OFF", type=input.bool, defval=true)len = input(4, minval=1, title="Length")srcsma = input(close, title="Source")offset = input(title="Offset COT", defval=0, minval=0, maxval=10)out = ema(srcsma, len)useaux1 = input(title="Aux 1 ON/OFF", type=input.bool, defval=true)auxinv1 = input(title="Aux 1 inv.", type=input.bool, defval=false)lenaux1 = input( 4, minval=1, title="Ema aux 1 period.")auxsma1 = input(title="AUX Symbol", type=input.symbol, defval="DELL")s1 = security(auxsma1, "W", close)outaux1 = ema(s1, lenaux1)useaux2 = input(title="Aux 2 ON/OFF", type=input.bool, defval=true)auxinv2 = input(title="Aux 2 inv.", type=input.bool, defval=false)lenaux2 = input( 4, minval=1, title="Ema aux 2 period.")auxsma2 = input(title="AUX 2 Symbol", type=input.symbol, defval="DELL")s2 = security(auxsma2, "W", close)outaux2 = ema(s2, lenaux2)//Can't set bFX as an input because plot and legend titles require literals// INPUTSsCalc  = "MARKETS"// ***** MARKET TYPES *****// Financial Markets (Commercial)bTotal = (sCalc == "MARKETS")sHead = "QUANDL:CFTC/"sLong = "_F_L_ALL|4"sShort = "_F_L_ALL|5"iWidth = 2// Non-Commercials (Speculators)bTotal2 = (sCalc == "NON-COMS")sHead2  = "QUANDL:CFTC/"sLong2  = "_F_L_ALL|1"sShort2 = "_F_L_ALL|2"iWidth2 = 2//***** CFTC MARKET CODES *****// 1 - FuturessCode1 =                  ticket00 == "AUD" ? "232741" :           ticket00 == "GBP" ? "096742" :          ticket00 == "CAD" ? "090741" :         ticket00 == "EUR" ? "099741" :         ticket00 == "JPY" ? "097741" :          ticket00 == "CHF" ? "092741" :         ticket00 == "NZD" ? "112741" :          ticket00 == "USD" ? "098662" :         ""sCode2 =                  ticket01 == "AUD" ? "232741" :           ticket01 == "GBP" ? "096742" :          ticket01 == "CAD" ? "090741" :         ticket01 == "EUR" ? "099741" :         ticket01 == "JPY" ? "097741" :          ticket01 == "CHF" ? "092741" :         ticket01 == "NZD" ? "112741" :          ticket01 == "USD" ? "098662" :         ""//TitlessTitle1 =  "1st Ticker" // COT CFTC Auto Generation Codes //Data functionsdLong(asCode) =>  security(sHead + asCode + (sLong),   "W", close[0 + offset] - close[1 + offset], lookahead=barmerge.lookahead_on)dShort(asCode) => security(sHead +asCode + (sShort),   "W", close[0 + offset] - close[1 + offset], lookahead=barmerge.lookahead_on)// COMMERCIALS 1 ticker _pos_coms1_short = dShort(sCode1)_pos_coms1_long  = dLong (sCode1)net_com1 = _pos_coms1_long - _pos_coms1_short// COMMERCIALS 2 tickersTitle2 =  "2nd Ticker"dLong2(asCode2) =>  security(sHead + asCode2 + (sLong),   "W", close[0 + offset] - close[1 + offset], lookahead=barmerge.lookahead_on)dShort2(asCode2) => security(sHead +asCode2 + (sShort),   "W", close[0 + offset] - close[1 + offset], lookahead=barmerge.lookahead_on)_pos_coms2_long    =  dLong2(sCode2)_pos_coms2_short   =  dShort2(sCode2)net_com2 = _pos_coms2_long - _pos_coms2_shortbuy =  falsesell = false//if(not useaux1)//    buy :=  (net_com1 > 0) and (net_com2 < 0)  and (out[0] > out[1])  and afterStartDate//    sell :=  (net_com1 < 0) and (net_com2 > 0) and (out[0] < out[1])  and afterStartDate// Plot data buy_aux1 = falsebuy_aux2 = falsesell_aux1 = falsesell_aux2 = falsebuy_cot = ((net_com1 > 0) and (net_com2 < 0) and usecot) or (not usecot)sell_cot = ((net_com1 < 0) and (net_com2 > 0) and usecot) or (not usecot)buy_ema = ((out[0] > out[1]) and useema) or (not useema)sell_ema = ((out[0] < out[1]) and useema) or (not useema)if(auxinv1)    buy_aux1 := ((outaux1[0]<outaux1[1]) and useaux1) or (not useaux1)    sell_aux1 := ((outaux1[0]>outaux1[1]) and useaux1) or not useaux1if not auxinv1    buy_aux1:= ((outaux1[0]>outaux1[1]) and useaux1) or not useaux1    sell_aux1 := ((outaux1[0]<outaux1[1]) and useaux1) or not useaux1if auxinv2    buy_aux2 := ((outaux2[0]<outaux2[1]) and useaux2) or not useaux2    sell_aux2 := ((outaux2[0]>outaux2[1]) and useaux2) or not useaux2if not auxinv2    buy_aux2:= ((outaux2[0]>outaux2[1]) and useaux2) or not useaux2    sell_aux2 := ((outaux2[0]<outaux2[1]) and useaux2) or not useaux2buy :=  buy_cot  and buy_ema and buy_aux1 and buy_aux2 and afterStartDatesell :=  sell_cot and sell_ema and sell_aux1 and sell_aux2 and afterStartDateif (sell)    strategy.entry("Short", strategy.short,  qty = 100000)    strategy.exit("SL-TP Short","Short",stop = high[0])    if (buy)    strategy.entry("Long", strategy.long,  qty = 100000)    strategy.exit("SL-TP Long","Long",stop = low[0])//if close[0] < close[1] or close[0] > close[1]//    strategy.close("Short")//    strategy.close("Long")    if strategy.openprofit > 0     strategy.close("Short")    strategy.close("Long")plotshape(buy, style=shape.triangleup,   location=location.belowbar, offset=0, color=color.green, size = size.small)plotshape(sell, style=shape.triangledown,   location=location.abovebar, offset=0, color=color.red, size = size.small)