Created
January 2, 2025 19:08
-
-
Save phillipchan1/a7976aadcf261b51844ceda4cf0d7c2f to your computer and use it in GitHub Desktop.
Volume Delta + Price action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@version=5 | |
strategy("Price Action + Volume Delta Strategy", overlay=true) | |
// Internal Volume Delta Calculation | |
useCustomTimeframeInput = input.bool(false, "Use custom timeframe") | |
lowerTimeframeInput = input.timeframe("1", "Timeframe") | |
var lowerTimeframe = switch | |
useCustomTimeframeInput => lowerTimeframeInput | |
timeframe.isseconds => "1S" | |
timeframe.isintraday => "1" | |
timeframe.isdaily => "5" | |
=> "60" | |
// Simulate Volume Delta (up and down volume) | |
upVolume = request.security(syminfo.tickerid, lowerTimeframe, close > open ? volume : 0) | |
downVolume = request.security(syminfo.tickerid, lowerTimeframe, close < open ? volume : 0) | |
// Calculate Volume Delta | |
lastVolume = upVolume - downVolume | |
// Volume Delta Conditions | |
volumeDeltaUp = lastVolume > 0 | |
volumeDeltaDown = lastVolume < 0 | |
// Price Action Conditions | |
isBullishCandle = close > open | |
isBearishCandle = close < open | |
// Entry and Exit Conditions | |
longEntry = isBearishCandle and volumeDeltaUp | |
longExit = volumeDeltaDown | |
shortEntry = isBullishCandle and volumeDeltaDown | |
shortExit = volumeDeltaUp | |
// Execute Strategy | |
if (longEntry) | |
strategy.entry("Buy", strategy.long) | |
if (longExit) | |
strategy.close("Buy") | |
if (shortEntry) | |
strategy.entry("Sell", strategy.short) | |
if (shortExit) | |
strategy.close("Sell") | |
// Plot Volume Delta for Visualization | |
plot(lastVolume, title="Volume Delta", color=lastVolume > 0 ? color.teal : color.red) | |
hline(0, "Zero Line", color=color.gray) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment