Sample TradingView Strategy: On Balance Volume crossovers

 

TradingView has 100s of free opensource strategies. We found a nice strategy for a 1hr time frame working for long and short entries for BTC-perpetual futures on Binance futures exchange. The original idea was taken from QuantNomad. You will find the original strategy code here OnbalanceVolume Strategy.

Note:

  • This strategy was adjusted to make fast entries and exits on low timeframes
  • It trades in both long and short directions
  • It works best on BTCUSDT perp contracts
  • It works best on 1Hr time frames

1. Create a new strategy on TradingView Pinescript

You can click on the 'Pine Editor' Tab just under any chart on TradingView and open up the pine script editor.

mceclip1.png

Then copy-paste the below strategy code. The only thing you need to change is that you need to add the unique strategy id in the comment field in "strategy.entry()" and "Strategy.exit()"

 

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Mudrex

//@version=4
strategy(title="On Balance Volume Oscillator Strategy ", shorttitle="OBV")


// Inputs
obv_length = input(20, title = "OBV Length")
obv_source = input(close, title = "OBV Source")
obv_show_ema = input(true, title = "Show OBV EMA")
obv_ema1_length = input(12, title = "EMA1 Length")
obv_ema2_length = input(26, title = "EMA2 Length")

// Calculatios
obv = sum(volume * sign(change(obv_source)), obv_length)
obv_osc = obv / sum(volume, obv_length)
obv_ema1 = ema(obv_osc, obv_ema1_length)
obv_ema2 = ema(obv_osc, obv_ema2_length)

plot(0, color = color.gray, title = "0 line")
plot(obv_osc, color = color.blue, title = "OBV Osc", linewidth = 2)
plot(obv_show_ema ? obv_ema1 : na, color = color.orange, title = "OBV EMA1", linewidth = 2)
plot(obv_show_ema ? obv_ema2 : na, color = color.green , title = "OBV EMA2", linewidth = 2)

strategy.entry('long', true, when = crossover( obv_ema1, obv_ema2),comment="{\"id\": \"<Insert your unique strategy id here>\", \"action\" : \"reverse_short_to_long\"}")
strategy.entry('short', false, when = crossunder(obv_ema1, obv_ema2),comment="{\"id\": \"<Insert your unique strategy id here>\", \"action\" : \"reverse_long_to_short\"}")

2. Setting up alerts using the TradingView alert dialog

You need to click on the 'Alert' icon. This icon shows up in multiple places. Here is how it shows up in the top panel

mceclip0.png

 

On clicking the add alert icon, a dialog box will open up. In the dialog box, all you now need to do is set the URL correctly and in the message box enter

{{strategy.order.comment}}

This will make sure that the comments we added earlier are passed on the Mudrex correctly!

mceclip0.png

 

3. Go live!

Once you create an alert and save it, Mudrex will be ready and waiting for the alert to come in. You can now either let the alerts accumulate or start a paper/live run.

Here is how the results look like on TradingView

 

mceclip0.png

If you need any help using Mudrex then please feel free to write to us at help@mudrex.com

Was this article helpful?
1 out of 1 found this helpful