Strategy · Pine Script v4 · Own pane

Aggregate BTC Volume + EMA Strat

by hasnocool· code credited to MartinShkreli and tweakerID

This strategy calculates and plots aggregated Bitcoin volume collected across multiple exchanges, along with two volume moving averages in a separate pane.

View on GitHub

GitHub stars106on the repository
Pine versionv4older, still runs
Lines of code64
Settings11inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

64 lines of Pine Script v4 from Aggregate BTC Volume + EMA Strat.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Aggregate BTC Volume + EMA Strat.pine
//@license=MIT
// © MartinShkreli and tweakerID
// This strategy buys when the price crosses the Fast EMA. It can go long only 
// when the price is above the slow EMA and short when is below. The exit 
// is determined by volume spikes, when the volume is greater than the Volume
// MA multiplied by the assigned input multiplier. Thanks to MartinShkreli 
// for the Aggregated BTC volume. There is also a Maximum Loss filter which 
// should be modified depending on the traded market.
//@version=4
strategy("Aggregate BTC Volume + EMA Strat", shorttitle="BTC Vol + EMA Strat", overlay=false, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=10000, commission_value=0.04, calc_on_every_tick=false, slippage=0)
direction = input(0, title = "Direction (Long=1, Both=0, Short=-1 ", type=input.integer, minval=-1, maxval=1)
strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))
res = timeframe.period
getVolumeSym(symbolPair) => security(symbolPair, res, volume)
getVolumeSymNz(symbolPair) => nz(getVolumeSym(symbolPair))
showma  = input(title="Show MA", type=input.bool, defval=true)
i_MAslow = input(100, title="Vol Slow MA Length")
i_MAfast = input(10, title="Vol Fast MA Length")
i_EMA = input(255, title="Slow EMA Length")
i_EMAFast = input(40, title="Fast EMA Length")
i_VolMult = input(4, step=.2, title="Volume MA Multiplier")
i_useMAFast = input(true, title="Use Fast MA for exit condition")
i_reverse = input(false, title="Reverse Trades")
i_AllowMaxLoss = input(true, title="Allow Maximum Loss Filter")
i_MaxLoss = input(6, title="Maximum Loss % Allowed Per Day")
//Aggregated Volume
vol = 0*volume
vol := vol + getVolumeSymNz("BINANCE:BTCUSDT")
vol := vol + getVolumeSymNz("BINANCE:BTCUSDTPERP")
vol := vol + getVolumeSymNz("OKEX:BTCUSDT")
vol := vol + getVolumeSymNz("OKEX:BTCUSDTPERP")
vol := vol + getVolumeSymNz("HUOBI:BTCUSDT")
vol := vol + getVolumeSymNz("HUOBI:BTCPERP")
vol := vol + getVolumeSymNz("FTX:BTCUSD")
vol := vol + getVolumeSymNz("FTX:BTCPERP")
vol := vol + getVolumeSymNz("KRAKEN:XBTUSD")
vol := vol + getVolumeSymNz("KRAKEN:XBTUSDPERP")
vol := vol + getVolumeSymNz("COINBASE:BTCUSD")
vol := vol + getVolumeSymNz("DERIBIT:BTCPERP")
vol := vol + getVolumeSymNz("BITFINEX:BTCUSD")
vol := vol + getVolumeSymNz("BITMEX:XBTUSD")
vol := vol + getVolumeSymNz("BITSTAMP:BTCUSD") 
vol := vol + getVolumeSymNz("BYBIT:BTCUSD") 
//Strategy Variables
strategy.risk.max_intraday_loss(i_AllowMaxLoss ? i_MaxLoss : 100, strategy.percent_of_equity)
EMA=ema(close, i_EMA)
EMAFast=ema(close, i_EMAFast)
MASlow=sma(vol, i_MAslow)
MAFast=sma(vol, i_MAfast)
//Trading Logic
BUY=crossover(close, EMAFast) and close > EMA
SELL=crossunder(close, EMAFast) and close < EMA
Exit=vol > (i_useMAFast ? MAFast*i_VolMult : MASlow*i_VolMult) 
MAExit = strategy.position_size < 0 ? crossover(close, EMA) : 
 strategy.position_size > 0 ? crossunder(close, EMA) : na
//Entries
strategy.entry("long", i_reverse?false:true, when=BUY)
strategy.entry("short", i_reverse?true:false, when=SELL)
strategy.close_all(when=Exit)
//Plots
plot(vol, "Volume", color=(open > close) ? #B03838 : #008060, style=plot.style_columns)
plot(showma ? MASlow : na, color=color.yellow)
plot(showma ? MAFast : na)
Expand (76 lines)

Overview

Aggregate BTC Volume + EMA Strat enters long positions when price crosses above a fast EMA while remaining above a slow EMA, and enters short positions under the inverse conditions. Positions are closed when aggregated volume spikes above a moving average multiplied by a user-defined threshold. Inputs control EMA lengths, volume parameters, trade direction, and a daily maximum loss percentage, but individual trades lack fixed stop losses.

Details

Published by

hasnocool on GitHub

Code credit

MartinShkreli and tweakerID, as written in the script's header

Type

Strategy, Pine Script v4

Draws

Separate pane below the chart

Category

Trend, Moving averages, Volume

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Direction (Long=1, Both=0, Short=-1 int0direction
Show MAbooltrueshowma
Vol Slow MA Lengthint100i_MAslow
Vol Fast MA Lengthint10i_MAfast
Slow EMA Lengthint255i_EMA
Fast EMA Lengthint40i_EMAFast
Volume MA Multiplierint4i_VolMult
Use Fast MA for exit conditionbooltruei_useMAFast
Reverse Tradesboolfalsei_reverse
Allow Maximum Loss Filterbooltruei_AllowMaxLoss
Maximum Loss % Allowed Per Dayint6i_MaxLoss
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

1 stars

This Pine Script strategy calculates the accumulation/distribution line with ta.accdist and its 21-period EMA. It plots these in a separate pane. The strategy issues long entries on ta.crossover of the accumulation/distribution line above its EMA and short ent

Strategy v6 VolumeMoving averages
Updated 5 days ago · Apache-2.0 GitHub repository of PF TA isolate - accdist EMA(21) cross
218 stars

This strategy enters long when a faster moving average crosses above a slower one and short when it crosses below, unless long-only mode is on. An optional volume filter requires volume above a 20-bar average times a multiplier. Exits use a percentage stop los

Strategy v6 TrendMoving averages
Updated 3 months ago · None stated GitHub repository of MA Cross Strategy Template

This strategy enters long or short when eight conditions align over the last two bars. It requires EMA 10 and EMA 55 alignment on the one-hour, four-hour and daily charts, a positive ADX slope, matching monitor direction, and price relative to a 400-bar point

Strategy v5 TrendMoving averages
Updated 1 year ago · None stated GitHub repository of Ruckard ABCBitcoin TradingLatino B002
12 stars

This strategy enters long when a fast EMA crosses above a slow EMA and RSI, ADX, and volume all clear their thresholds. It sizes the order from a percentage of equity and an ATR stop distance, then sets a partial profit target at a multiple of that risk. After

Strategy v5 TrendMoving averages
Updated 4 months ago · None stated GitHub repository of BTC 4H Institutional Trend
8 stars

This overlay strategy combines three distinct SuperTrend levels with multiple moving averages and volume profile analytics on the main price chart. It calculates trend directions using three configurable ATR periods and multipliers alongside SMA, EMA, and HMA

Strategy v5 TrendVolatility & bands
Updated 4 years ago · None stated GitHub repository of ATR 3Lvls VP Strategy

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers