Strategy · Pine Script v5 · On the chart

Composite RVI CVD Strategy

by jawauntb

This strategy plots long and short markers on the price chart.

View on GitHub

Repaints

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code126
Settings8inputs
LicenceGPL-3.0
Last update2 years ago22 May 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

126 lines of Pine Script v5 from volatility-volume-strat.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

volatility-volume-strat.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jawauntb

//@version=5
strategy("Composite RVI CVD Strategy", overlay=true, calc_on_every_tick = true)

// Inputs
rsiPeriod = input(14, "RSI Period")
emaPeriod = input(13, "EMA Period")
maPeriod = input(30, "MA Period")
vwapSource = input(hlc3, "VWAP Source")
longStopLossPerc = input(0.05, "Long Stop Loss %")
longTakeProfitPerc = input(0.1, "Long Take Profit %")
shortStopLossPerc = input(0.05, "Short Stop Loss %") 
shortTakeProfitPerc = input(0.1, "Short Take Profit %")

// Composite Index
rsiSource = close
rsiDelta = ta.rsi(rsiSource, rsiPeriod) - ta.rsi(rsiSource, rsiPeriod)[9]
rsiSma = ta.sma(ta.rsi(rsiSource, 3), 3)
compIndex = rsiDelta + rsiSma

// CVD Volume
[upVolume, dnVolume] = request.security_lower_tf(syminfo.tickerid, "1", [volume, volume])
cvdVolume = array.get(upVolume, 0) - array.get(dnVolume, 0)

// EMA and MA
ema13 = ta.ema(close, emaPeriod)
ma30 = ta.sma(close, maPeriod)

// VWAP
vwap = ta.vwap(vwapSource)

// RVI
length = 10
src = close
stddev = ta.stdev(src, length)
upper = ta.ema(ta.change(src) <= 0 ? 0 : stddev, length)
lower = ta.ema(ta.change(src) > 0 ? 0 : stddev, length)
rvi = upper / (upper + lower) * 100

// Composite Oscillator Moving Averages
compositeOscillator = compIndex
ma13 = ta.sma(compositeOscillator, 13)
ma33 = ta.sma(compositeOscillator, 33)

// Long Conditions
longBias1 = ema13 > ma30 and close > ema13 ? 1.3 : 1.0
longBias2 = compositeOscillator > ma13 and ma13 > ma33 ? 1.265 : 1.0
longCond1 = compIndex > 45 * longBias1 * longBias2
longCond2 = compIndex - compIndex[4] > 20 * longBias1 * longBias2
longCond3 = cvdVolume >= cvdVolume[1] * 0.97 * longBias1 * longBias2 and cvdVolume[1] >= cvdVolume[2] * 0.97 * longBias1 * longBias2 and cvdVolume[2] >= cvdVolume[3] * 0.97 * longBias1 * longBias2
longCond4 = rvi > rvi[1] * longBias1 * longBias2 and rvi[1] > rvi[2] * longBias1 * longBias2

// Short Conditions
shortBias1 = close < ema13 ? 1.1 : 1.0
shortBias2 = close < vwap ? 1.15 : 1.0 
shortBias3 = close > vwap ? 1.15 : 1.0
shortBias4 = rvi < 45 ? 1.0 : 0.85
shortBias5 = ma33 > ma13 ? 1.15 : 1.0
shortBias6 = compositeOscillator < ma13 and compositeOscillator < ma33 ? 1.3225 : 1.0
shortCond1 = compIndex < 40 * shortBias1 * shortBias2 * shortBias3 * shortBias4 * shortBias5 * shortBias6
shortCond2 = ((cvdVolume < cvdVolume[1] * 0.9 or (cvdVolume < cvdVolume[1] and cvdVolume[1] < cvdVolume[2] and cvdVolume[2] < cvdVolume[3])) ? 1.0 : 0.0) * shortBias1 * shortBias2 * shortBias3 * shortBias4 * shortBias5 * shortBias6


// Entry Signals
longSignal = longCond1 and longCond2 and longCond3 and longCond4 
shortSignal = shortCond1 or shortCond2

// Stop Loss & Take Profit
longStopLoss = strategy.position_avg_price * (1 - longStopLossPerc)
longTakeProfit = strategy.position_avg_price * (1 + longTakeProfitPerc)
shortStopLoss = strategy.position_avg_price * (1 + shortStopLossPerc)
shortTakeProfit = strategy.position_avg_price * (1 - shortTakeProfitPerc)

// Execution
if longSignal
    strategy.entry("Long", strategy.long)
    strategy.exit("Long TP/SL", "Long", stop=longStopLoss, limit=longTakeProfit)
else if shortSignal
    strategy.entry("Short", strategy.short)
    strategy.exit("Short TP/SL", "Short", stop=shortStopLoss, limit=shortTakeProfit)

// Plotting
plotshape(longSignal, location=location.belowbar, style=shape.triangleup, size=size.small, color=color.green)  
plotshape(shortSignal, location=location.abovebar, style=shape.triangledown, size=size.small, color=color.red)
plot(compositeOscillator, color=color.blue)
plot(ma13, color=color.yellow)
plot(ma33, color=color.red)

// Function to plot individual condition confirmations or breaks
plotCondition(series, condition, labelTrue, labelFalse, yOffset) =>
    var label myLabel = na
    labelText = condition ? labelTrue : labelFalse
    labelColor = condition ? color.new(color.green, 0) : color.new(color.red, 0)
    
    // Detect changes in the condition value
    conditionChanged = ta.change(condition)
    
    if conditionChanged or barstate.islast
        if (na(myLabel))
            myLabel := label.new(x=time, y=series + yOffset, text=labelText, style=label.style_label_down, color=labelColor, size=size.small, textcolor=color.white, xloc=xloc.bar_time, yloc=yloc.price)
        else
            label.set_xy(myLabel, x=time, y=series + yOffset)  
            label.set_text(myLabel, text=labelText)
            label.set_color(myLabel, color=labelColor)
            label.set_textcolor(myLabel, color.white)
    myLabel

// Assuming atr is already calculated somewhere in your script
atrl = ta.atr(14)

// Check and plot each condition separately
// Momentum Conditions
plotCondition(close, longCond1, "Momentum: Composite Index > Biased 45", "Momentum: Composite Index <= Biased 45", atrl * 1.75)
plotCondition(close, longCond2, "Momentum: Composite Index Biased Increase 20 Points", "Momentum: Composite Index No Biased Increase 20 Points", atrl * 2)

// Volume Conditions  
plotCondition(close, longCond3, "Volume: CVD Volume Biased Consistent Increase or Not Dropped >3%", "Volume: CVD Volume No Biased Consistent Increase or Dropped >3%", atrl * 1.5)
plotCondition(close, shortCond2, "Volume: CVD Volume Biased Decrease 10% or Bearish 3/4 Bars", "Volume: CVD Volume No Biased Decrease 10% or Not Bearish 3/4 Bars", -atrl * 2)

// Price Conditions
plotCondition(close, shortCond1, "Price: Composite Index < Biased 40", "Price: Composite Index >= Biased 40", -atrl * 1.5)  

// Trend Conditions
plotCondition(close, longCond4, "Trend: RVI Biased Increase Last 3 Bars", "Trend: RVI No Biased Increase Last 3 Bars", atrl * 2.3)

Overview

Composite RVI CVD Strategy builds a composite index from RSI change and a short RSI average, then requires that index, a one-minute cumulative volume delta, and a relative volatility index to agree. EMA, SMA, and VWAP relationships scale the thresholds. Long entries need all four conditions; shorts need one of two. Percentage stop-loss and take-profit exits are set from average entry price. It recalculates on every tick, so signals can change on the live bar.

Details

Published by

jawauntb on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Oscillators & momentum, Volume, Moving averages, Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Settings

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

SettingTypeDefaultVariable
RSI Periodint14rsiPeriod
EMA Periodint13emaPeriod
MA Periodint30maPeriod
VWAP Sourcesourcehlc3vwapSource
Long Stop Loss %float0.05longStopLossPerc
Long Take Profit %float0.1longTakeProfitPerc
Short Stop Loss %float0.05shortStopLossPerc
Short Take Profit %float0.1shortTakeProfitPerc
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

BB+RSI+OBV

by hasnocool
106 stars

This strategy combines Bollinger Bands, the Relative Strength Index (RSI), and On-Balance Volume (OBV) to generate trade signals directly on the price chart. Long entries trigger when price is above the middle SMA band, RSI is over 50, and OBV is rising. Short

Strategy v4 Volatility & bandsOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of BB+RSI+OBV

CombinedBinHAndClucV8

by viktors1982
36 stars

This strategy trades on the price chart using multiple indicators. It enters long positions when price dips meet conditions on Bollinger Bands 40 and 20, RSI, MFI, volume and other thresholds. It exits at custom ROI profit levels based on RSI or after timeout

Strategy v4 Oscillators & momentumMoving averages Repaints
Updated 2 years ago · None stated GitHub repository of CombinedBinHAndClucV8
4 stars

The Simpleton STEPFUN Strategy combines signals from multiple technical indicators including RSI-2, MACD crossover, Bollinger Band squeeze, volume spikes, triple EMA, and Ichimoku cloud. It generates buy signals when the weighted ensemble meets or exceeds the

Strategy v5 Oscillators & momentumVolatility & bands
1 stars

TnSovereignSignalForgeV20 is a price-chart strategy that combines seven directional votes from RSI, EMA, MACD, volume, VWAP, Bollinger Bands, and a volume oscillator. A long condition requires the vote total to meet a minimum agreement setting. A thermodynamic

Strategy v6 Oscillators & momentumMoving averages
Updated 2 months ago · None stated GitHub repository of TnSovereignSignalForgeV20
330 stars

This strategy plots MACD line, signal line, Bollinger Bands, and RSI on the price chart. It signals long entries on MACD crossover above signal with RSI below 50 and price below BB basis, plus optional DMI filter. Short entries are available but disabled by de

Strategy v5 Oscillators & momentumVolatility & bands
Updated 2 months ago · None stated GitHub repository of MACD + BB + RSI [Alorse]
257 stars

This overlay strategy is built for ES futures on the one-minute chart. It plots a volume-weighted moving average of price opens and standard-deviation bands at Fibonacci ratios, plus a second longer volume-weighted average from a higher-timeframe open. Call an

Strategy v5 Volatility & bandsMoving averages
Updated 6 weeks ago · None stated GitHub repository of ES Futures 1M No Repaint

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