Pine Script v4 · Strategy
EMA_cumulativeVolume_crossover[Strategy]
A Pine Script v4 strategy built on EMA (close, 50). It has 8 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 commits 20% of equity and pays no commission. 6 settings; defaults include EMA Length 50, cumulative volume Period 100 and Risk % of capital 10.
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 EMA_cumulativeVolume_crossover[Strategy] repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 1 of 1 trades.
- How did EMA_cumulativeVolume_crossover[Strategy] do on BTCUSDT 1D with default settings?
- +17.50%
- From 26 Jan 2024 to 21 Oct 2026, over 6 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can EMA_cumulativeVolume_crossover[Strategy] be converted to Pine Script v5?
- Yes
- The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
- Does EMA_cumulativeVolume_crossover[Strategy] use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does EMA_cumulativeVolume_crossover[Strategy] run in Zeal Terminal?
- Yes
- It compiles in 25 ms and runs 1,000 bars in 57 ms, in the browser.
BTCUSDT · 1D · default settings
- EMA
- Cumulate Volumne / VWAP
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +17.50%
- $1,749.80
- Buy and hold
- +102.5%
- same period
- Closed trades
- 6
- 3 won · 3 lost
- Profitable
- 50.0%
- of closed trades
- Profit factor
- 1.34
- gross profit ÷ gross loss
- Max drawdown
- 28.87%
- −$4,431.33
One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A long 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.
-
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
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 25, 33, 35, 36, 38, 46, 49, 50. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 17
transp = on line 17, 18. v5 folds the transparency into the colour with color.new(c, transp).
-
Note
Uses long =, which v5 renamed line 25
long = on line 25, 38. v5 writes it as direction = strategy.long or strategy.short.
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 sum → math.sum, ema → ta.ema, crossover → ta.crossover, tostring → str.tostring, crossunder → ta.crossunder, abs → math.abs.
- 8 strategy calls use the when = argument (line 25, 33, 35, 36, 38, 46, 49, 50). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 6 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 13: sum → math.sum
- Line 14: sum → math.sum
- Line 16: ema → ta.ema
- Line 17: transp = 25 → color.new(color.green, 25)
- Line 18: transp = 25 → color.new(color.orange, 25)
16 more edits
- Line 25: long = true → direction = strategy.long
- Line 25: crossover → ta.crossover
- Line 33: tostring → str.tostring
- Line 33: crossunder → ta.crossunder
- Line 35: tostring → str.tostring
- Line 35: crossunder → ta.crossunder
- Line 36: tostring → str.tostring
- Line 38: long = false → direction = strategy.short
- Line 40: abs → math.abs
- Line 42: abs → math.abs
- Line 44: abs → math.abs
- Line 49: tostring → str.tostring
- Line 49: abs → math.abs
- Line 49: crossover → ta.crossover
- Line 50: tostring → str.tostring
- Line 50: abs → math.abs
⋯// © mohanee-//@version=4+//@version=5strategy("EMA_cumulativeVolume_crossover[Strategy]", overlay=true, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=20, initial_capital=10000)⋯avgPriceVolume = avgPrice * volume-cumulPriceVolume = sum(avgPriceVolume, cumulativePeriod)+cumulPriceVolume = math.sum(avgPriceVolume, cumulativePeriod)-cumulVolume = sum(volume, cumulativePeriod)+cumulVolume = math.sum(volume, cumulativePeriod)vwapValue = cumulPriceVolume / cumulVolume-emaVal=ema(close, emaLength)+emaVal=ta.ema(close, emaLength)-plot(emaVal, title="EMA", color=color.green, transp=25)+plot(emaVal, title="EMA", color=color.new(color.green, 25))-plot(vwapValue, title="Cumulate Volumne / VWAP", color=color.orange, linewidth=2, transp=25)+plot(vwapValue, title="Cumulate Volumne / VWAP", color=color.new(color.orange, 25), linewidth=2)bgcolor(emaVal>vwapValue?color.blue:color.purple) ⋯qty1:= (qty1 * close >= strategy.equity ) ? (strategy.equity / close) : qty1-strategy.entry(id="LE",comment="LE", long=true, qty=qty1, when=crossover(emaVal, vwapValue) and (tradeDirection=="LONG") ) //emaVal>vwapValue and crossover(close , emaVal)+strategy.entry(id="LE",comment="LE", direction = strategy.long, qty=qty1, when=ta.crossover(emaVal, vwapValue) and (tradeDirection=="LONG") ) //emaVal>vwapValue and crossover(close , emaVal)//stoploss⋯if(takePartialProfits==true)- strategy.close(id="LE", comment="Partial"+tostring(close-strategy.position_avg_price, "###.##") , qty=strategy.position_size/3 , when = (tradeDirection=="LONG" ) and close>takeProfit and crossunder(close, emaVal) ) //close<close[1] and close[1]<close[2] and close[2]<close[3])+ strategy.close(id="LE", comment="Partial"+str.tostring(close-strategy.position_avg_price, "###.##") , qty=strategy.position_size/3 , when = (tradeDirection=="LONG" ) and close>takeProfit and ta.crossunder(close, emaVal) ) //close<close[1] and close[1]<close[2] and close[2]<close[3]) -strategy.close(id="LE" , comment="LE Exit Points="+tostring(close-strategy.position_avg_price, "###.##"), when=crossunder(emaVal, vwapValue) and (tradeDirection=="LONG") )+strategy.close(id="LE" , comment="LE Exit Points="+str.tostring(close-strategy.position_avg_price, "###.##"), when=ta.crossunder(emaVal, vwapValue) and (tradeDirection=="LONG") )-strategy.close(id="LE" , comment="SL Exit Loss="+tostring(close-strategy.position_avg_price, "###.##"), when= close < stopLossVal and (tradeDirection=="LONG") )+strategy.close(id="LE" , comment="SL Exit Loss="+str.tostring(close-strategy.position_avg_price, "###.##"), when= close < stopLossVal and (tradeDirection=="LONG") )//for short you dont have to wait crossodown of ema, falling is speed , so just check if close crossing down vwapVal-strategy.entry(id="SE",comment="SE", long=false, qty=qty1, when=(close<vwapValue and close<open and close[1] < vwapValue and close[1]<open[1] and close<close[1]) and emaVal>=vwapValue and (tradeDirection=="SHORT") ) //emaVal>vwapValue and crossover(close , emaVal)+strategy.entry(id="SE",comment="SE", direction = strategy.short, qty=qty1, when=(close<vwapValue and close<open and close[1] < vwapValue and close[1]<open[1] and close<close[1]) and emaVal>=vwapValue and (tradeDirection=="SHORT") ) //emaVal>vwapValue and crossover(close , emaVal)//stoploss-stopLossValUpside= abs(strategy.position_size)>=1 and tradeDirection=="SHORT" ? (strategy.position_avg_price * (1+(stopLoss*0.01) )) : 0.00+stopLossValUpside= math.abs(strategy.position_size)>=1 and tradeDirection=="SHORT" ? (strategy.position_avg_price * (1+(stopLoss*0.01) )) : 0.00//draw initil stop loss-plot(abs(strategy.position_size)>=1 and tradeDirection=="SHORT" ? stopLossValUpside : na, color = color.purple , style=plot.style_linebr, linewidth = 2, title = "stop loss")+plot(math.abs(strategy.position_size)>=1 and tradeDirection=="SHORT" ? stopLossValUpside : na, color = color.purple , style=plot.style_linebr, linewidth = 2, title = "stop loss")//partial exits-shortTakeProfit= abs(strategy.position_size)>=1 and tradeDirection=="SHORT" ? (strategy.position_avg_price * (1-(stopLoss*0.01) )) : 0.00+shortTakeProfit= math.abs(strategy.position_size)>=1 and tradeDirection=="SHORT" ? (strategy.position_avg_price * (1-(stopLoss*0.01) )) : 0.00if(takePartialProfits==true)⋯//strategy.close(id="SE" , comment="SE Exit Points="+tostring(close-strategy.position_avg_price, "###.##"), when=crossover(emaVal, vwapValue) and (tradeDirection=="SHORT") )-strategy.close(id="SE" , comment="SE Exit Points="+tostring(close-strategy.position_avg_price, "###.##"), when= abs(strategy.position_size)>=1 and ( (emaVal<vwapValue and close>vwapValue and open>vwapValue and close>open ) or (crossover(emaVal,vwapValue)) ) and (tradeDirection=="SHORT") )+strategy.close(id="SE" , comment="SE Exit Points="+str.tostring(close-strategy.position_avg_price, "###.##"), when= math.abs(strategy.position_size)>=1 and ( (emaVal<vwapValue and close>vwapValue and open>vwapValue and close>open ) or (ta.crossover(emaVal,vwapValue)) ) and (tradeDirection=="SHORT") )-strategy.close(id="SE" , comment="SL Exit Loss="+tostring(close-strategy.position_avg_price, "###.##"), when= abs(strategy.position_size)>=1 and close > stopLossValUpside and (tradeDirection=="SHORT" ) )+strategy.close(id="SE" , comment="SL Exit Loss="+str.tostring(close-strategy.position_avg_price, "###.##"), when= math.abs(strategy.position_size)>=1 and close > stopLossValUpside and (tradeDirection=="SHORT" ) )Same 6 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 5: input() → input.int()
- Line 6: input() → input.int()
- Line 7: input() → input.int()
- Line 8: input() → input.int()
- Line 9: input() → input.bool()
- Line 10: input() → input.string()
8 more edits
- Line 25: when = ta.crossover(emaVal, vwapValue) and (tradeDirection=="LONG") → if block
- Line 33: when = (tradeDirection=="LONG" ) and close>takeProfit and ta.crossunder(close, emaVal) → if block
- Line 35: when = ta.crossunder(emaVal, vwapValue) and (tradeDirection=="LONG") → if block
- Line 36: when = close < stopLossVal and (tradeDirection=="LONG") → if block
- Line 38: when = (close<vwapValue and close<open and close[1] < vwapValue and close[1]<open[1] and close<close[1]) and emaVal>=vwapValue and (tradeDirection=="SHORT") → if block
- Line 46: when = (tradeDirection=="SHORT" ) and close<shortTakeProfit → if block
- Line 49: when = math.abs(strategy.position_size)>=1 and ( (emaVal<vwapValue and close>vwapValue and open>vwapValue and close>open ) or (ta.crossover(emaVal,vwapValue)) ) and (tradeDirection=="SHORT") → if block
- Line 50: when = math.abs(strategy.position_size)>=1 and close > stopLossValUpside and (tradeDirection=="SHORT" ) → if block
⋯strategy("EMA_cumulativeVolume_crossover[Strategy]", overlay=true, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=20, initial_capital=10000)-emaLength= input(50, title="EMA Length", minval=1, maxval=200)+emaLength= input.int(50, title="EMA Length", minval=1, maxval=200)-cumulativePeriod = input(100, title="cumulative volume Period", minval=1, maxval=200)+cumulativePeriod = input.int(100, title="cumulative volume Period", minval=1, maxval=200)-riskCapital = input(title="Risk % of capital", defval=10, minval=1)+riskCapital = input.int(title="Risk % of capital", defval=10, minval=1)-stopLoss=input(8,title="Stop Loss",minval=1)+stopLoss=input.int(8,title="Stop Loss",minval=1)-takePartialProfits=input(false, title="take partial profits (percentage same as stop loss)")+takePartialProfits=input.bool(false, title="take partial profits (percentage same as stop loss)")-tradeDirection=input(title="Trade Direction", defval="LONG", options=["LONG", "SHORT"])+tradeDirection=input.string(title="Trade Direction", defval="LONG", options=["LONG", "SHORT"])avgPrice = (high + low + close) / 3⋯qty1:= (qty1 * close >= strategy.equity ) ? (strategy.equity / close) : qty1-strategy.entry(id="LE",comment="LE", direction = strategy.long, qty=qty1, when=ta.crossover(emaVal, vwapValue) and (tradeDirection=="LONG") ) //emaVal>vwapValue and crossover(close , emaVal)+if ta.crossover(emaVal, vwapValue) and (tradeDirection=="LONG")+ strategy.entry(id="LE",comment="LE", direction = strategy.long, qty=qty1 ) //emaVal>vwapValue and crossover(close , emaVal)//stoploss⋯if(takePartialProfits==true)- strategy.close(id="LE", comment="Partial"+str.tostring(close-strategy.position_avg_price, "###.##") , qty=strategy.position_size/3 , when = (tradeDirection=="LONG" ) and close>takeProfit and ta.crossunder(close, emaVal) ) //close<close[1] and close[1]<close[2] and close[2]<close[3])+ if (tradeDirection=="LONG" ) and close>takeProfit and ta.crossunder(close, emaVal)+ strategy.close(id="LE", comment="Partial"+str.tostring(close-strategy.position_avg_price, "###.##") , qty=strategy.position_size/3 ) //close<close[1] and close[1]<close[2] and close[2]<close[3]) -strategy.close(id="LE" , comment="LE Exit Points="+str.tostring(close-strategy.position_avg_price, "###.##"), when=ta.crossunder(emaVal, vwapValue) and (tradeDirection=="LONG") )+if ta.crossunder(emaVal, vwapValue) and (tradeDirection=="LONG")+ strategy.close(id="LE" , comment="LE Exit Points="+str.tostring(close-strategy.position_avg_price, "###.##") )-strategy.close(id="LE" , comment="SL Exit Loss="+str.tostring(close-strategy.position_avg_price, "###.##"), when= close < stopLossVal and (tradeDirection=="LONG") )+if close < stopLossVal and (tradeDirection=="LONG")+ strategy.close(id="LE" , comment="SL Exit Loss="+str.tostring(close-strategy.position_avg_price, "###.##") )//for short you dont have to wait crossodown of ema, falling is speed , so just check if close crossing down vwapVal-strategy.entry(id="SE",comment="SE", direction = strategy.short, qty=qty1, when=(close<vwapValue and close<open and close[1] < vwapValue and close[1]<open[1] and close<close[1]) and emaVal>=vwapValue and (tradeDirection=="SHORT") ) //emaVal>vwapValue and crossover(close , emaVal)+if (close<vwapValue and close<open and close[1] < vwapValue and close[1]<open[1] and close<close[1]) and emaVal>=vwapValue and (tradeDirection=="SHORT")+ strategy.entry(id="SE",comment="SE", direction = strategy.short, qty=qty1 ) //emaVal>vwapValue and crossover(close , emaVal)//stoploss⋯if(takePartialProfits==true)- strategy.close(id="SE", comment="Partial" , qty=strategy.position_size/3 , when = (tradeDirection=="SHORT" ) and close<shortTakeProfit ) //close<takeProfit and (emaVal - close)>8 )+ if (tradeDirection=="SHORT" ) and close<shortTakeProfit+ strategy.close(id="SE", comment="Partial" , qty=strategy.position_size/3 ) //close<takeProfit and (emaVal - close)>8 ) //strategy.close(id="SE" , comment="SE Exit Points="+tostring(close-strategy.position_avg_price, "###.##"), when=crossover(emaVal, vwapValue) and (tradeDirection=="SHORT") )-strategy.close(id="SE" , comment="SE Exit Points="+str.tostring(close-strategy.position_avg_price, "###.##"), when= math.abs(strategy.position_size)>=1 and ( (emaVal<vwapValue and close>vwapValue and open>vwapValue and close>open ) or (ta.crossover(emaVal,vwapValue)) ) and (tradeDirection=="SHORT") )+if math.abs(strategy.position_size)>=1 and ( (emaVal<vwapValue and close>vwapValue and open>vwapValue and close>open ) or (ta.crossover(emaVal,vwapValue)) ) and (tradeDirection=="SHORT")+ strategy.close(id="SE" , comment="SE Exit Points="+str.tostring(close-strategy.position_avg_price, "###.##") )-strategy.close(id="SE" , comment="SL Exit Loss="+str.tostring(close-strategy.position_avg_price, "###.##"), when= math.abs(strategy.position_size)>=1 and close > stopLossValUpside and (tradeDirection=="SHORT" ) )+if math.abs(strategy.position_size)>=1 and close > stopLossValUpside and (tradeDirection=="SHORT" )+ strategy.close(id="SE" , comment="SL Exit Loss="+str.tostring(close-strategy.position_avg_price, "###.##") )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: 6 before, 4 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.
⋯// © mohanee-//@version=5+//@version=6strategy("EMA_cumulativeVolume_crossover[Strategy]", overlay=true, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=20, initial_capital=10000)⋯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 |
|---|---|---|---|
| EMA Length | 50 | int · min 1 · max 200 | emaVal |
| cumulative volume Period | 100 | int · min 1 · max 200 | cumulPriceVolume cumulVolume |
| Risk % of capital | 10 | int · min 1 | qty1 |
| Stop Loss | 8 | int · min 1 | qty1 stopLossVal takeProfit stopLossValUpside shortTakeProfit |
| take partial profits (percentage same as stop loss) | false | bool | close LE close SE line 32 line 45 |
| Trade Direction | LONG | string · options ["LONG", "SHORT"] | stopLossValUpside shortTakeProfit entry LE close LE entry SE stop loss close SE |
What it calculates
- EMA (
ema,ta.emain v5)close, EMA Length (50)emaVal · line 16
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 LE long | crossover(emaVal, vwapValue) and (tradeDirection=="LONG") | On | 25 |
| Close LE | (tradeDirection=="LONG" ) and close>takeProfit and crossunder(close, emaVal) | On | 33 |
| Close LE | crossunder(emaVal, vwapValue) and (tradeDirection=="LONG") | On | 35 |
| Close LE | close < stopLossVal and (tradeDirection=="LONG") | On | 36 |
| Open SE short | (close<vwapValue and close<open and close[1] < vwapValue and close[1]<open[1] and close<close[1]) and emaVal>=vwapValue and (tradeDirection=="SHORT") | On | 38 |
| Close SE | (tradeDirection=="SHORT" ) and close<shortTakeProfit | On | 46 |
| Close SE | abs(strategy.position_size)>=1 and ( (emaVal<vwapValue and close>vwapValue and open>vwapValue and close>open ) or (crossover(emaVal,vwapValue)) ) and (tradeDirection=="SHORT") | On | 49 |
| Close SE | abs(strategy.position_size)>=1 and close > stopLossValUpside and (tradeDirection=="SHORT" ) | On | 50 |
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 dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder 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 | +17.5% | +102.5% | 6 | 50% | 1.34 | 28.9% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +2.0% | +5.5% | 6 | 67% | 1.17 | 11.8% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −13.6% | +9.8% | 4 | 25% | 0.49 | 18.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +9.7% | +8.4% | 9 | 56% | 1.58 | 11.4% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −28.5% | +16.7% | 6 | 17% | 0.24 | 29.6% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +25.0% | +21.5% | 4 | 75% | 3.87 | 11.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +41.7% | +148.3% | 3 | 67% | 3.65 | 14.7% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +18.0% | +17.1% | 5 | 60% | 3.74 | 6.6% | 8 May 2026 – 21 Oct 2026 |
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 | 0 | — | $0.00 |
| Sideways market | 6 | 50% | $1,749.80 |
| Falling market | 0 | — | $0.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
34.8%
The 95th percentile of the worst drawdown when the same 6 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 17.8% to 34.8%; the tick is what actually happened, 23.5%. Order luck alone moves it this much.
All 6 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 29 Jul 2024 68,249.90 | 5 Aug 2024 58,161.00 | 7 | −$1,478.23 |
| long | 6 Aug 2024 54,018.80 | 7 Aug 2024 56,022.00 | 1 | $316.01 |
| long | 25 Sep 2024 64,262.70 | 23 Feb 2025 96,551.00 | 151 | $4,440.48 |
| long | 5 May 2025 94,277.60 | 26 Sep 2025 108,994.00 | 144 | $2,072.76 |
| long | 8 Oct 2025 121,333.00 | 15 Oct 2025 113,028.00 | 7 | −$1,050.73 |
| long | 25 Apr 2026 77,437.10 | 12 Jun 2026 63,626.00 | 48 | −$2,550.50 |
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 |
|---|---|---|---|---|---|
| EMA_cumulativeVolume_crossover[Strategy] this page | — | v4 strategy | +17.5% | 6 | 28.9% |
| 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 25 ms | With a workaround 1,000 bars in 57 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as long = true, long = false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 25, 38) so the engine trades the way the script says.
“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/// © mohanee//@version=4strategy("EMA_cumulativeVolume_crossover[Strategy]", overlay=true, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=20, initial_capital=10000)emaLength= input(50, title="EMA Length", minval=1, maxval=200)cumulativePeriod = input(100, title="cumulative volume Period", minval=1, maxval=200)riskCapital = input(title="Risk % of capital", defval=10, minval=1)stopLoss=input(8,title="Stop Loss",minval=1)takePartialProfits=input(false, title="take partial profits (percentage same as stop loss)")tradeDirection=input(title="Trade Direction", defval="LONG", options=["LONG", "SHORT"])avgPrice = (high + low + close) / 3avgPriceVolume = avgPrice * volumecumulPriceVolume = sum(avgPriceVolume, cumulativePeriod)cumulVolume = sum(volume, cumulativePeriod)vwapValue = cumulPriceVolume / cumulVolumeemaVal=ema(close, emaLength)plot(emaVal, title="EMA", color=color.green, transp=25)plot(vwapValue, title="Cumulate Volumne / VWAP", color=color.orange, linewidth=2, transp=25)bgcolor(emaVal>vwapValue?color.blue:color.purple) //Entry--//Echeck how many units can be purchased based on risk manage ment and stop lossqty1 = (strategy.equity * riskCapital / 100 ) / (close*stopLoss/100) //check if cash is sufficient to buy qty1 , if capital not available use the available capital onlyqty1:= (qty1 * close >= strategy.equity ) ? (strategy.equity / close) : qty1strategy.entry(id="LE",comment="LE", long=true, qty=qty1, when=crossover(emaVal, vwapValue) and (tradeDirection=="LONG") ) //emaVal>vwapValue and crossover(close , emaVal)//stoplossstopLossVal= strategy.position_size>=1 ? (strategy.position_avg_price * (1-(stopLoss*0.01) )) : 0.00//draw initil stop lossplot(strategy.position_size>=1 ? stopLossVal : na, color = color.purple , style=plot.style_linebr, linewidth = 2, title = "stop loss")//partial exitstakeProfit= strategy.position_size>=1 ? (strategy.position_avg_price * (1+(stopLoss*0.01) )) : ( close[1] * 2 )if(takePartialProfits==true) strategy.close(id="LE", comment="Partial"+tostring(close-strategy.position_avg_price, "###.##") , qty=strategy.position_size/3 , when = (tradeDirection=="LONG" ) and close>takeProfit and crossunder(close, emaVal) ) //close<close[1] and close[1]<close[2] and close[2]<close[3]) strategy.close(id="LE" , comment="LE Exit Points="+tostring(close-strategy.position_avg_price, "###.##"), when=crossunder(emaVal, vwapValue) and (tradeDirection=="LONG") )strategy.close(id="LE" , comment="SL Exit Loss="+tostring(close-strategy.position_avg_price, "###.##"), when= close < stopLossVal and (tradeDirection=="LONG") )//for short you dont have to wait crossodown of ema, falling is speed , so just check if close crossing down vwapValstrategy.entry(id="SE",comment="SE", long=false, qty=qty1, when=(close<vwapValue and close<open and close[1] < vwapValue and close[1]<open[1] and close<close[1]) and emaVal>=vwapValue and (tradeDirection=="SHORT") ) //emaVal>vwapValue and crossover(close , emaVal)//stoplossstopLossValUpside= abs(strategy.position_size)>=1 and tradeDirection=="SHORT" ? (strategy.position_avg_price * (1+(stopLoss*0.01) )) : 0.00//draw initil stop lossplot(abs(strategy.position_size)>=1 and tradeDirection=="SHORT" ? stopLossValUpside : na, color = color.purple , style=plot.style_linebr, linewidth = 2, title = "stop loss")//partial exitsshortTakeProfit= abs(strategy.position_size)>=1 and tradeDirection=="SHORT" ? (strategy.position_avg_price * (1-(stopLoss*0.01) )) : 0.00if(takePartialProfits==true) strategy.close(id="SE", comment="Partial" , qty=strategy.position_size/3 , when = (tradeDirection=="SHORT" ) and close<shortTakeProfit ) //close<takeProfit and (emaVal - close)>8 ) //strategy.close(id="SE" , comment="SE Exit Points="+tostring(close-strategy.position_avg_price, "###.##"), when=crossover(emaVal, vwapValue) and (tradeDirection=="SHORT") )strategy.close(id="SE" , comment="SE Exit Points="+tostring(close-strategy.position_avg_price, "###.##"), when= abs(strategy.position_size)>=1 and ( (emaVal<vwapValue and close>vwapValue and open>vwapValue and close>open ) or (crossover(emaVal,vwapValue)) ) and (tradeDirection=="SHORT") )strategy.close(id="SE" , comment="SL Exit Loss="+tostring(close-strategy.position_avg_price, "###.##"), when= abs(strategy.position_size)>=1 and close > stopLossValUpside and (tradeDirection=="SHORT" ) )