Pine Script v4 · Strategy
KSR Strategy
A Pine Script v4 strategy built on EMA (close, 10), Crossover (ema1, ema2) and Crossunder (ema1, ema2). It has 2 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 7 settings; defaults include Par1 10, Par2 20 and MA1 8.
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 KSR Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 11 of 11 trades.
- How did KSR Strategy do on BTCUSDT 1D with default settings?
- +35.33%
- From 26 Jan 2024 to 21 Oct 2026, over 42 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can KSR Strategy be converted to Pine Script v5?
- No
- The automatic step from v4 to v5 gives a script that does not run in v5 (Pine Script v5 Error at @L24:C15: 'label.style_labelup' is not available in Pine Script v5. It was added in a later version), so no v5 download is offered; the edits are shown below.
- Does KSR Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does KSR Strategy run in Zeal Terminal?
- Yes
- It compiles in 26 ms and runs 1,000 bars in 104 ms, in the browser.
BTCUSDT · 1D · default settings
- Up Arrow
- Down Arrow
- EMA Short
- EMA Long
- EMA
- Shape
- Shape
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +35.33%
- $35,330.80
- Buy and hold
- +102.5%
- same period
- Closed trades
- 42
- 12 won · 30 lost
- Profitable
- 28.6%
- of closed trades
- Profit factor
- 1.33
- gross profit ÷ gross loss
- Max drawdown
- 41.32%
- −$48,181.80
One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A short position was still open at the last bar. 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.
-
Likely bug
ema(close, 100) ignores the settings line 13
Line 13 hard-codes 100 where line 7 uses “Par1”. Changing those settings moves one band but not this one.
ema(close,100)ema(close, par1) -
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
2 settings have no label
In the settings dialog par1 (line 5), par2 (line 6) show an empty name. The labels on this page come from the variable names.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses iff(), which v5 removed line 11
iff() on line 11, 11. v5 writes it as the ternary c ? a : b.
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, crossover → ta.crossover, crossunder → ta.crossunder, tostring → str.tostring, heikinashi → ticker.heikinashi, security → request.security.
v4 → v5
DiffersThe v5 version does not run in Zeal Terminal's engine: Pine Script v5 Error at @L24:C15: 'label.style_labelup' is not available in Pine Script v5. It was added in a later version.
- Line 3: //@version=4 → //@version=5
- Line 7: ema → ta.ema
- Line 8: ema → ta.ema
- Line 11: iff(c, a, b) → (c ? a : b)
- Line 11: iff(c, a, b) → (c ? a : b)
- Line 13: ema → ta.ema
45 more edits
- Line 14: crossover → ta.crossover
- Line 15: crossunder → ta.crossunder
- Line 16: tostring → str.tostring
- Line 19: crossover → ta.crossover
- Line 19: ema → ta.ema
- Line 19: ema → ta.ema
- Line 21: tostring → str.tostring
- Line 26: crossunder → ta.crossunder
- Line 26: ema → ta.ema
- Line 26: ema → ta.ema
- Line 28: tostring → str.tostring
- Line 33: ema → ta.ema
- Line 34: ema → ta.ema
- Line 35: crossover → ta.crossover
- Line 35: ema → ta.ema
- Line 35: ema → ta.ema
- Line 38: crossunder → ta.crossunder
- Line 38: ema → ta.ema
- Line 38: ema → ta.ema
- Line 41: input(type = input.integer) → input.int()
- Line 42: input(type = input.integer) → input.int()
- Line 43: ema → ta.ema
- Line 44: ema → ta.ema
- Line 45: ema → ta.ema
- Line 46: ema → ta.ema
- Line 49: input(type = input.integer) → input.int()
- Line 50: ema → ta.ema
- Line 52: heikinashi → ticker.heikinashi
- Line 53: security → request.security
- Line 54: security → request.security
- Line 55: security → request.security
- Line 56: security → request.security
- Line 57: ema → ta.ema
- Line 58: ema → ta.ema
- Line 59: ema → ta.ema
- Line 60: ema → ta.ema
- Line 63: heikinashi → ticker.heikinashi
- Line 64: security → request.security
- Line 65: security → request.security
- Line 66: security → request.security
- Line 67: security → request.security
- Line 68: ema → ta.ema
- Line 69: ema → ta.ema
- Line 70: ema → ta.ema
- Line 71: ema → ta.ema
⋯// © askkuldeeprandhawa-//@version=4+//@version=5strategy("KSR Strategy", overlay=true)⋯par2=input(20)-ema1=ema(close,par1)+ema1=ta.ema(close,par1)-ema2=ema(close,par2)+ema2=ta.ema(close,par2)buy=ema1>ema2sell=ema2<ema1-mycolor= iff(buy,color.green,iff(sell,color.blue,color.red))+mycolor= (buy ? color.green : (sell ? color.blue : color.red))barcolor(color=mycolor)-ema100=ema(close,100)+ema100=ta.ema(close,100)-ibuy=crossover(ema1,ema2)+ibuy=ta.crossover(ema1,ema2)-iSell=crossunder(ema1,ema2)+iSell=ta.crossunder(ema1,ema2)-varp=tostring(close[1])+varp=str.tostring(close[1])plotshape(ibuy, "Up Arrow", shape.triangleup, location.belowbar, color.green, 0, 0,"Buy" , color.green, true, size.tiny)plotshape(iSell, "Down Arrow", shape.triangledown, location.abovebar, color.red, 0, 0, "Sell", color.red, true, size.tiny)-crossed =crossover(ema(close,par1), ema(close,par2))+crossed =ta.crossover(ta.ema(close,par1), ta.ema(close,par2))if crossed- l = label.new(bar_index, na, tostring(close), + l = label.new(bar_index, na, str.tostring(close), color=color.green, ⋯ -crossed2 =crossunder(ema(close,par1), ema(close,par2))+crossed2 =ta.crossunder(ta.ema(close,par1), ta.ema(close,par2))if crossed2- l = label.new(bar_index, na, tostring(close), + l = label.new(bar_index, na, str.tostring(close), color=color.red, ⋯ -plot(ema(close,par1),"EMA Short",color=color.white)+plot(ta.ema(close,par1),"EMA Short",color=color.white)-plot(ema(close,par2),"EMA Long",color=color.orange)+plot(ta.ema(close,par2),"EMA Long",color=color.orange)-longCondition = crossover(ema(close, par1), ema(close, par2))+longCondition = ta.crossover(ta.ema(close, par1), ta.ema(close, par2))if (longCondition) strategy.entry("My Long Entry Id", strategy.long)-shortCondition = crossunder(ema(close, par1), ema(close, par2))+shortCondition = ta.crossunder(ta.ema(close, par1), ta.ema(close, par2))if (shortCondition) strategy.entry("My Short Entry Id", strategy.short)-ma1_len = input(title="MA1", type=input.integer, defval=8, minval=1, maxval=100, step=1)+ma1_len = input.int(title="MA1", defval=8, minval=1, maxval=100, step=1)-ma2_len = input(title="MA2", type=input.integer, defval=12, minval=1, maxval=100, step=1)+ma2_len = input.int(title="MA2", defval=12, minval=1, maxval=100, step=1)-o = ema(open, ma1_len)+o = ta.ema(open, ma1_len)-c = ema(close, ma1_len)+c = ta.ema(close, ma1_len)-h = ema(high, ma1_len)+h = ta.ema(high, ma1_len)-l = ema(low, ma1_len)+l = ta.ema(low, ma1_len)tim1=input('D',"Short Time")tim2=input('W',"Long Time")-ema_p=input(title="EMA Period", type=input.integer, defval=16, minval=1, maxval=100, step=1)+ema_p=input.int(title="EMA Period", defval=16, minval=1, maxval=100, step=1)-refma = ema(close, ema_p)+refma = ta.ema(close, ema_p)plot(refma, title="EMA" , linewidth=1, color=close < refma ? color.orange : color.blue)-ha_t = heikinashi(syminfo.tickerid)+ha_t = ticker.heikinashi(syminfo.tickerid)-ha_o = security(ha_t, tim2, o)+ha_o = request.security(ha_t, tim2, o)-ha_c = security(ha_t, tim2, c)+ha_c = request.security(ha_t, tim2, c)-ha_h = security(ha_t, tim2, h)+ha_h = request.security(ha_t, tim2, h)-ha_l = security(ha_t, tim2, l)+ha_l = request.security(ha_t, tim2, l)-o2 = ema(ha_o, ma2_len)+o2 = ta.ema(ha_o, ma2_len)-c2 = ema(ha_c, ma2_len)+c2 = ta.ema(ha_c, ma2_len)-h2 = ema(ha_h, ma2_len)+h2 = ta.ema(ha_h, ma2_len)-l2 = ema(ha_l, ma2_len)+l2 = ta.ema(ha_l, ma2_len)ha_col = ha_c > ha_o ? color.red : color.greenplotshape(true, style=shape.circle, color=ha_c > ha_o ? color.green : color.red, location=location.bottom)-ha_t1 = heikinashi(syminfo.tickerid)+ha_t1 = ticker.heikinashi(syminfo.tickerid)-ha_o1 = security(ha_t1, tim1, o)+ha_o1 = request.security(ha_t1, tim1, o)-ha_c1 = security(ha_t1, tim1, c)+ha_c1 = request.security(ha_t1, tim1, c)-ha_h1 = security(ha_t1, tim1, h)+ha_h1 = request.security(ha_t1, tim1, h)-ha_l1 = security(ha_t1, tim1, l)+ha_l1 = request.security(ha_t1, tim1, l)-o3 = ema(ha_o1, ma2_len)+o3 = ta.ema(ha_o1, ma2_len)-c3 = ema(ha_c1, ma2_len)+c3 = ta.ema(ha_c1, ma2_len)-h3 = ema(ha_h1, ma2_len)+h3 = ta.ema(ha_h1, ma2_len)-l3 = ema(ha_l1, ma2_len)+l3 = ta.ema(ha_l1, ma2_len)ha_col1 = ha_c1 > ha_o1 ? color.red : color.green⋯Clean v5
Not verifiedThe v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L24:C15: 'label.style_labelup' is not available in Pine Script v5. It was added in a later version.), so this step could not be checked.
- Line 5: input() → input.int()
- Line 6: input() → input.int()
- Line 47: input() → input.string()
- Line 48: input() → input.string()
⋯strategy("KSR Strategy", overlay=true)-par1=input(10)+par1=input.int(10)-par2=input(20)+par2=input.int(20)ema1=ta.ema(close,par1)⋯l = ta.ema(low, ma1_len)-tim1=input('D',"Short Time")+tim1=input.string('D',"Short Time")-tim2=input('W',"Long Time")+tim2=input.string('W',"Long Time")ema_p=input.int(title="EMA Period", defval=16, minval=1, maxval=100, step=1)⋯Does it run in Pine Script v6?
Not tested
The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L24:C15: 'label.style_labelup' is not available in Pine Script v5. It was added in a later version.), so this step could not be checked. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © askkuldeeprandhawa-//@version=5+//@version=6strategy("KSR Strategy", overlay=true)⋯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 |
|---|---|---|---|
| Par1 (no label in the script) | 10 | int | ema1 crossed crossed2 longCondition shortCondition EMA Short |
| Par2 (no label in the script) | 20 | int | ema2 crossed crossed2 longCondition shortCondition EMA Long |
| MA1 | 8 | int (written input.integer) · min 1 · max 100 · step 1 | l o c h |
| MA2 | 12 | int (written input.integer) · min 1 · max 100 · step 1 | o2 c2 h2 l2 o3 c3 h3 l3 |
| Short Time | D | string | ha_o1 ha_c1 ha_h1 ha_l1 |
| Long Time | W | string | ha_o ha_c ha_h ha_l |
| EMA Period | 16 | int (written input.integer) · min 1 · max 100 · step 1 | refma |
What it calculates
- EMA (
ema,ta.emain v5)close, Par1 (10)ema1 · line 7 - EMA (
ema,ta.emain v5)close, Par2 (20)ema2 · line 8 - EMA (
ema,ta.emain v5)close, 100ema100 · line 13 - Crossover (
crossover,ta.crossoverin v5)ema1, ema2ibuy · line 14 - Crossunder (
crossunder,ta.crossunderin v5)ema1, ema2iSell · line 15 - Crossover / EMA (
crossover,ta.crossoverin v5)ema(close,par1), ema(close,par2)crossed · line 19 - EMA (
ema,ta.emain v5)low, MA1 (8)l · line 46 - Crossunder / EMA (
crossunder,ta.crossunderin v5)ema(close,par1), ema(close,par2)crossed2 · line 26 - Crossover / EMA (
crossover,ta.crossoverin v5)ema(close, par1), ema(close, par2)longCondition · line 35 - Crossunder / EMA (
crossunder,ta.crossunderin v5)ema(close, par1), ema(close, par2)shortCondition · line 38 - EMA (
ema,ta.emain v5)open, MA1 (8)o · line 43 - EMA (
ema,ta.emain v5)close, MA1 (8)c · line 44 - EMA (
ema,ta.emain v5)high, MA1 (8)h · line 45 - EMA (
ema,ta.emain v5)close, EMA Period (16)refma · line 50 - EMA (
ema,ta.emain v5)ha_o, MA2 (12)o2 · line 57 - EMA (
ema,ta.emain v5)ha_c, MA2 (12)c2 · line 58 - EMA (
ema,ta.emain v5)ha_h, MA2 (12)h2 · line 59 - EMA (
ema,ta.emain v5)ha_l, MA2 (12)l2 · line 60 - EMA (
ema,ta.emain v5)ha_o1, MA2 (12)o3 · line 68 - EMA (
ema,ta.emain v5)ha_c1, MA2 (12)c3 · line 69 - EMA (
ema,ta.emain v5)ha_h1, MA2 (12)h3 · line 70 - EMA (
ema,ta.emain v5)ha_l1, MA2 (12)l3 · line 71
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open My Long Entry Id long | (longCondition) | On | 37 |
| Open My Short Entry Id short | (shortCondition) | On | 40 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- ClearHigher-timeframe data8 security call(s), none with lookahead on.
- 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 | +35.3% | +102.5% | 42 | 29% | 1.33 | 41.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −7.6% | +5.5% | 51 | 27% | 0.84 | 14.9% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +1.5% | +9.8% | 36 | 31% | 1.24 | 2.8% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.6% | +8.4% | 57 | 21% | 0.74 | 1.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.0% | +16.7% | 36 | 42% | 1.15 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 37 | 27% | 1.98 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.4% | +148.3% | 40 | 28% | 1.47 | 0.5% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 49 | 31% | 1.05 | 0.1% | 8 May 2026 – 21 Oct 2026 |
Higher-timeframe data for request.security(): heikinashi:SYMBOL W (Binance BTCUSDT 1w, as Heikin-Ashi by the engine), heikinashi:SYMBOL D (Binance BTCUSDT 1d, as Heikin-Ashi by the engine), heikinashi:BINANCE:BTCUSDT W (Binance BTCUSDT 1w, as Heikin-Ashi by the engine), heikinashi:BINANCE:BTCUSDT D (Binance BTCUSDT 1d, as Heikin-Ashi by the engine), 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 | 16 | 25% | −$15,633.60 |
| Sideways market | 17 | 29% | $26,103.70 |
| Falling market | 9 | 33% | $24,860.70 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
46.7%
The 95th percentile of the worst drawdown when the same 42 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 23.2% to 46.7%; the tick is what actually happened, 30.0%. Order luck alone moves it this much.
All 42 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 14 Apr 2024 63,924.50 | 17 May 2024 65,235.20 | 33 | −$1,310.69 |
| long | 17 May 2024 65,235.20 | 15 Jun 2024 66,044.00 | 29 | $808.78 |
| short | 15 Jun 2024 66,044.00 | 17 Jul 2024 65,044.00 | 32 | $999.99 |
| long | 17 Jul 2024 65,044.00 | 4 Aug 2024 60,698.00 | 18 | −$4,346.01 |
| short | 4 Aug 2024 60,698.00 | 24 Aug 2024 64,037.20 | 20 | −$3,339.25 |
| long | 24 Aug 2024 64,037.20 | 30 Aug 2024 59,359.00 | 6 | −$4,678.24 |
| short | 30 Aug 2024 59,359.00 | 18 Sep 2024 60,314.00 | 19 | −$954.99 |
| long | 18 Sep 2024 60,314.00 | 10 Oct 2024 60,636.00 | 22 | $322.02 |
| short | 10 Oct 2024 60,636.00 | 13 Oct 2024 63,206.20 | 3 | −$2,570.22 |
| long | 13 Oct 2024 63,206.20 | 24 Dec 2024 94,881.50 | 72 | $31,675.20 |
| short | 24 Dec 2024 94,881.50 | 25 Dec 2024 98,663.60 | 1 | −$3,782.11 |
| long | 25 Dec 2024 98,663.60 | 27 Dec 2024 95,791.60 | 2 | −$2,871.98 |
| short | 27 Dec 2024 95,791.60 | 7 Jan 2025 102,236.00 | 11 | −$6,444.00 |
| long | 7 Jan 2025 102,236.00 | 10 Jan 2025 92,552.50 | 3 | −$9,683.11 |
| short | 10 Jan 2025 92,552.50 | 17 Jan 2025 99,987.30 | 7 | −$7,434.81 |
| long | 17 Jan 2025 99,987.30 | 5 Feb 2025 97,763.10 | 19 | −$2,224.16 |
| short | 5 Feb 2025 97,763.10 | 28 Mar 2025 87,232.00 | 51 | $10,531.10 |
| long | 28 Mar 2025 87,232.00 | 29 Mar 2025 84,424.40 | 1 | −$2,807.63 |
| short | 29 Mar 2025 84,424.40 | 18 Apr 2025 84,947.90 | 20 | −$523.54 |
| long | 18 Apr 2025 84,947.90 | 7 Jun 2025 104,288.00 | 50 | $19,340.50 |
| short | 7 Jun 2025 104,288.00 | 8 Jun 2025 105,552.00 | 1 | −$1,263.72 |
| long | 8 Jun 2025 105,552.00 | 19 Jun 2025 104,887.00 | 11 | −$665.36 |
| short | 19 Jun 2025 104,887.00 | 27 Jun 2025 106,947.00 | 8 | −$2,060.27 |
| long | 27 Jun 2025 106,947.00 | 3 Aug 2025 112,546.00 | 37 | $5,599.29 |
| short | 3 Aug 2025 112,546.00 | 10 Aug 2025 116,462.00 | 7 | −$3,915.90 |
| long | 10 Aug 2025 116,462.00 | 20 Aug 2025 112,873.00 | 10 | −$3,589.30 |
| short | 20 Aug 2025 112,873.00 | 13 Sep 2025 116,029.00 | 24 | −$3,156.46 |
| long | 13 Sep 2025 116,029.00 | 26 Sep 2025 108,994.00 | 13 | −$7,034.92 |
| short | 26 Sep 2025 108,994.00 | 2 Oct 2025 118,595.00 | 6 | −$9,600.50 |
| long | 2 Oct 2025 118,595.00 | 14 Oct 2025 115,166.00 | 12 | −$3,428.99 |
| short | 14 Oct 2025 115,166.00 | 4 Jan 2026 90,628.00 | 82 | $24,538.00 |
| long | 4 Jan 2026 90,628.00 | 23 Jan 2026 89,559.70 | 19 | −$1,068.33 |
| short | 23 Jan 2026 89,559.70 | 13 Mar 2026 70,541.30 | 49 | $19,018.30 |
| long | 13 Mar 2026 70,541.30 | 28 Mar 2026 66,407.30 | 15 | −$4,134.06 |
| short | 28 Mar 2026 66,407.30 | 9 Apr 2026 71,069.90 | 12 | −$4,662.65 |
| long | 9 Apr 2026 71,069.90 | 20 May 2026 76,834.40 | 41 | $5,764.43 |
| short | 20 May 2026 76,834.40 | 11 Jul 2026 64,161.70 | 52 | $12,672.60 |
| long | 11 Jul 2026 64,161.70 | 2 Aug 2026 62,823.70 | 22 | −$1,338.07 |
| short | 2 Aug 2026 62,823.70 | 8 Aug 2026 64,923.20 | 6 | −$2,099.55 |
| long | 8 Aug 2026 64,923.20 | 13 Aug 2026 63,480.00 | 5 | −$1,443.21 |
| short | 13 Aug 2026 63,480.00 | 20 Aug 2026 69,334.80 | 7 | −$5,854.79 |
| long | 20 Aug 2026 69,334.80 | 15 Oct 2026 81,682.00 | 56 | $12,347.20 |
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 |
|---|---|---|---|---|---|
| KSR Strategy this page | — | v4 strategy | +35.3% | 42 | 41.3% |
| EMA Slope AyE by fajardoarelys | ema | v4 strategy | No trades on this market | ||
| ROoT by realisticDove62527 | ema | v5 strategy | −4.7% | 225 | 9.4% |
| sachin5986 by mohitesachin78 | ema | v4 strategy | +32.1% | 35 | 17.6% |
| sonu1997 by Sonu1997 | ema | v4 strategy | +960.7% | 2 | 1,103.8% |
| Moving Average Crossover by Muh4mm4d | ema | v4 strategy | +19,990.1% | 30 | 1,274.2% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 26 ms | With a workaround 1,000 bars in 104 ms | Not measured |
| PineTS | No 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. Data the page supplies at the chart's own timeframe (another symbol, or Heikin-Ashi) reaches the script one bar later in Zeal Terminal's engine than on TradingView.
“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/// © askkuldeeprandhawa//@version=4strategy("KSR Strategy", overlay=true)par1=input(10)par2=input(20)ema1=ema(close,par1)ema2=ema(close,par2)buy=ema1>ema2sell=ema2<ema1mycolor= iff(buy,color.green,iff(sell,color.blue,color.red))barcolor(color=mycolor)ema100=ema(close,100)ibuy=crossover(ema1,ema2)iSell=crossunder(ema1,ema2)varp=tostring(close[1])plotshape(ibuy, "Up Arrow", shape.triangleup, location.belowbar, color.green, 0, 0,"Buy" , color.green, true, size.tiny)plotshape(iSell, "Down Arrow", shape.triangledown, location.abovebar, color.red, 0, 0, "Sell", color.red, true, size.tiny)crossed =crossover(ema(close,par1), ema(close,par2))if crossed l = label.new(bar_index, na, tostring(close), color=color.green, textcolor=color.white, style=label.style_labelup, yloc=yloc.belowbar) crossed2 =crossunder(ema(close,par1), ema(close,par2))if crossed2 l = label.new(bar_index, na, tostring(close), color=color.red, textcolor=color.white, style=label.style_labeldown, yloc=yloc.abovebar) plot(ema(close,par1),"EMA Short",color=color.white)plot(ema(close,par2),"EMA Long",color=color.orange)longCondition = crossover(ema(close, par1), ema(close, par2))if (longCondition) strategy.entry("My Long Entry Id", strategy.long)shortCondition = crossunder(ema(close, par1), ema(close, par2))if (shortCondition) strategy.entry("My Short Entry Id", strategy.short)ma1_len = input(title="MA1", type=input.integer, defval=8, minval=1, maxval=100, step=1)ma2_len = input(title="MA2", type=input.integer, defval=12, minval=1, maxval=100, step=1)o = ema(open, ma1_len)c = ema(close, ma1_len)h = ema(high, ma1_len)l = ema(low, ma1_len)tim1=input('D',"Short Time")tim2=input('W',"Long Time")ema_p=input(title="EMA Period", type=input.integer, defval=16, minval=1, maxval=100, step=1)refma = ema(close, ema_p)plot(refma, title="EMA" , linewidth=1, color=close < refma ? color.orange : color.blue)ha_t = heikinashi(syminfo.tickerid)ha_o = security(ha_t, tim2, o)ha_c = security(ha_t, tim2, c)ha_h = security(ha_t, tim2, h)ha_l = security(ha_t, tim2, l)o2 = ema(ha_o, ma2_len)c2 = ema(ha_c, ma2_len)h2 = ema(ha_h, ma2_len)l2 = ema(ha_l, ma2_len)ha_col = ha_c > ha_o ? color.red : color.greenplotshape(true, style=shape.circle, color=ha_c > ha_o ? color.green : color.red, location=location.bottom)ha_t1 = heikinashi(syminfo.tickerid)ha_o1 = security(ha_t1, tim1, o)ha_c1 = security(ha_t1, tim1, c)ha_h1 = security(ha_t1, tim1, h)ha_l1 = security(ha_t1, tim1, l)o3 = ema(ha_o1, ma2_len)c3 = ema(ha_c1, ma2_len)h3 = ema(ha_h1, ma2_len)l3 = ema(ha_l1, ma2_len)ha_col1 = ha_c1 > ha_o1 ? color.red : color.greenplotshape(true, style=shape.circle, color=ha_c1 > ha_o1 ? color.green : color.red, location=location.top)