OPEN-SOURCE SCRIPT

MA + Volume Strategy

//version=5
strategy("MA + Volume Strategy", overlay=true)

// Parameters
maLength = input.int(50, title="MA Length", minval=1)
volLength = input.int(20, title="Volume MA Length", minval=1)

// Calculating Moving Average and Volume Average
ma = ta.sma(close, maLength)
volMa = ta.sma(volume, volLength)

// Plot the Moving Average
plot(ma, title="Moving Average", color=color.blue, linewidth=2)

// Buy Condition: Price crosses above the MA and Volume > Volume MA
buyCondition = ta.crossover(close, ma) and volume > volMa

// Sell Condition: Price crosses below the MA and Volume > Volume MA
sellCondition = ta.crossunder(close, ma) and volume > volMa

// Strategy entry/exit
if (buyCondition)
strategy.entry("Buy", strategy.long)

if (sellCondition)
strategy.close("Buy")

// Plot volume with volume average for reference
plot(volume, title="Volume", color=color.green, style=plot.style_histogram, transp=70)
plot(volMa, title="Volume Moving Average", color=color.red)
Bill Williams Indicators

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer