![VFYZnhD.png](/proxy.php?image=https%3A%2F%2Fi.imgur.com%2FVFYZnhD.png&hash=714e315732dc516d5a5d02dcf9eac36c)
I created upper and lower study to choose from. However, lower study can be switched between volume or candle chart.
Author Message:
Volume Delta: Volume Delta is an indicator that simplifies how you analyze trading volumes and the percentage of buy-sell activities effortlessly.
Mode Details: https://www.tradingview.com/v/n4NK9sLH/
Lower Study Code:
CSS:
#/ This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © hapharmonic
#indicator('Volume Delta [hapharmonic]',format=FV, max_bars_back=5000, max_labels_count=500)
# Converted by Samer4Cok@Samer800 - 05/2024
declare lower;
#HidePricePlot();
input ChartStyle = {default "Volume Chart", "Candlestick Chart"}; #(true,title = 'Volume on Candles')
input showSignals = yes;
input showLabel = yes; #(false,inline = 'l') ,
input showBuyStrengthLebel = yes; #(true,inline = 'l')
input showMovAvg = yes; #(true,title = 'EMA Volume Confirmed',group = "EMA Volume")
input MovAvgType = AverageType.EXPONENTIAL;
input MovAvgFastLength = 12; #, title="Fast EMA Length",group = "EMA Volume")
input MovAvgSlowLength = 26; #, title="Slow EMA Length",group = "EMA Volume")
input volumeConfirmationLength = 6; #, title="Volume Confirmation Length",group = "EMA Volume")
def na = Double.NaN;
def last = !IsNaN(close[1]);
def usecandle = ChartStyle == ChartStyle."Candlestick Chart";
def ohlcvO = open;
def ohlcvH = high;
def ohlcvL = low;
def ohlcvC = close;
def ohlcvV = volume;
#-- Colors
DefineGlobalColor("Up", Color.CYAN);
DefineGlobalColor("Dn", Color.MAGENTA);
#// Calculate volumes and percentages |
#calcVolumes(OHLCV ohlcv) =>
def volDatabuyVol = ohlcvV * (ohlcvC - ohlcvL) / (ohlcvH - ohlcvL);
def volDatasellVol = ohlcvV - volDatabuyVol;
def volDatapcBuy = volDatabuyVol / ohlcvV * 100;
def volDatapcSell = 100 - volDatapcBuy;
def volDataisBuyGreater = volDatabuyVol > volDatasellVol;
def volDatahigherVol = if volDataisBuyGreater then volDatabuyVol else volDatasellVol;
def volDatalowerVol = if volDataisBuyGreater then volDatasellVol else volDatabuyVol;
def volDatahigherCol = if volDataisBuyGreater then 1 else 0;
def volDatalowerCol = if volDataisBuyGreater then -1 else 0;
#// Plot volumes and create labels
def LoVol = if usecandle then na else volDatalowerVol; # 'Lower Volume'
def HiVol = if usecandle then na else volDatahigherVol; # 'Higher Volume'
def Total = if usecandle then na else ohlcvV; #ohlcvV; # 'Totals'
# Plot the new Chart
def upVol = volDatahigherCol > 0;
def dnVol = volDatalowerCol < 0;
AddChart(open = if upVol then 0 else na, high = Total , low = 0 , close = Total,
type = ChartType.CANDLE, growcolor = GlobalColor("Up"));
AddChart(open = if upVol then na else 0, high = Total , low = 0 , close = Total,
type = ChartType.CANDLE, growcolor = GlobalColor("Dn"));
AddChart(open = if upVol then na else HiVol, high = HiVol , low = 0 , close = 0,
type = ChartType.CANDLE, growcolor = GlobalColor("Dn"));
AddChart(open = if upVol then HiVol else na, high = HiVol , low = 0 , close = 0,
type = ChartType.CANDLE, growcolor = GlobalColor("Up"));
AddChart(open = if dnVol then na else LoVol, high = LoVol , low = 0 , close = 0,
type = ChartType.CANDLE, growcolor = GlobalColor("Up"));
AddChart(open = if dnVol then LoVol else na, high = LoVol , low = 0 , close = 0,
type = ChartType.CANDLE, growcolor = GlobalColor("Dn"));
#-- Labrl
def volStr = if last then Round(Sign(ohlcvC - ohlcvC[1]) * ohlcvV / 1000000, 3) else volStr[1];
def buyVolStr = if last then Round(volDatabuyVol / 1000, 3) else buyVolStr[1];
def sellVolStr = if last then Round(volDatasellVol / 1000, 3) else sellVolStr[1];
def buyPercentStr = if last then Round(volDatapcBuy, 2) else buyPercentStr[1];
def sellPercentStr = if last then Round(volDatapcSell, 2) else sellPercentStr[1];
def totalbuyPercentC = if last then volDatabuyVol / (volDatabuyVol + volDatasellVol) else totalbuyPercentC[1];
def cnt1 = if 19 < (20 * totalbuyPercentC) then 1 else 0;
def cnt2 = if 18 < (20 * totalbuyPercentC) then 1 else 0;
def cnt3 = if 17 < (20 * totalbuyPercentC) then 1 else 0;
def cnt4 = if 16 < (20 * totalbuyPercentC) then 1 else 0;
def cnt5 = if 15 < (20 * totalbuyPercentC) then 1 else 0;
def cnt6 = if 14 < (20 * totalbuyPercentC) then 1 else 0;
def cnt7 = if 13 < (20 * totalbuyPercentC) then 1 else 0;
def cnt8 = if 12 < (20 * totalbuyPercentC) then 1 else 0;
def cnt9 = if 11 < (20 * totalbuyPercentC) then 1 else 0;
def cnt10 = if 10 < (20 * totalbuyPercentC) then 1 else 0;
def cnt11 = if 9 < (20 * totalbuyPercentC) then 1 else 0;
def cnt12 = if 8 < (20 * totalbuyPercentC) then 1 else 0;
def cnt13 = if 7 < (20 * totalbuyPercentC) then 1 else 0;
def cnt14 = if 6 < (20 * totalbuyPercentC) then 1 else 0;
def cnt15 = if 5 < (20 * totalbuyPercentC) then 1 else 0;
def cnt16 = if 4 < (20 * totalbuyPercentC) then 1 else 0;
def cnt17 = if 3 < (20 * totalbuyPercentC) then 1 else 0;
def cnt18 = if 2 < (20 * totalbuyPercentC) then 1 else 0;
def cnt19 = if 1 < (20 * totalbuyPercentC) then 1 else 0;
def cnt20 = if 0 < (20 * totalbuyPercentC) then 1 else 0;
def totPer = cnt1 + cnt2 + cnt3 + cnt4 + cnt5 + cnt6 + cnt7 + cnt8 + cnt9 + cnt10
+ cnt11+ cnt12+ cnt13+ cnt14+ cnt15+ cnt16+ cnt17+ cnt18+ cnt19+ cnt20;
AddLabel(showLabel, "Net: " + volStr + "M", if volStr > 0 then Color.LIGHT_GREEN else
if volStr < 0 then Color.PINK else Color.GRAY);
AddLabel(showLabel, "Buy: " + buyPercentStr + "%", if buyPercentStr > 50 then Color.GREEN else Color.DARK_GREEN);
AddLabel(showLabel, "Sell: " + sellPercentStr + "%", if sellPercentStr > 50 then Color.RED else Color.DARK_RED);
AddLabel(showBuyStrengthLebel, "100%", if cnt1 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "95%", if cnt2 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "90%", if cnt3 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "85%", if cnt4 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "80%", if cnt5 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "75%", if cnt6 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "70%", if cnt7 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "65%", if cnt8 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "60%", if cnt9 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "55%", if cnt10 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "50%", if cnt11 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "45%", if cnt12 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "40%", if cnt13 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "35%", if cnt14 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "30%", if cnt15 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "25%", if cnt16 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "20%", if cnt17 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "15%", if cnt18 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "10%", if cnt19 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, " 5%", if cnt20 > 0 then Color.CYAN else Color.MAGENTA);
#/ Draw volume levels on the candlesticks |
#// Define base and value for gradient candles
def base;
def value;
#// Calculate base and value based on buy/sell volume and open/close relationship
if volDataisBuyGreater {
base = Min(ohlcvO, ohlcvC); # // Start from the lower of open/close for buy
value = base + AbsValue(ohlcvO - ohlcvC) * (volDatapcBuy / 100); # // Extend to the percentage of buy volume
} else {
base = Max(ohlcvO, ohlcvC); # // Start from the higher of open/close for sell
value = base - AbsValue(ohlcvO - ohlcvC) * (volDatapcSell / 100); # // Extend to the percentage of sell volume
}
def UseC = if usecandle then volDatahigherCol else na;
AddChart(open = if UseC > 0 then value else na, high = base , low = value , close = base,
type = ChartType.CANDLE, growcolor = GlobalColor("Up"));
AddChart(open = if UseC > 0 then na else base, high = base , low = value , close = value,
type = ChartType.CANDLE, growcolor = GlobalColor("Dn"));
AddChart(open = if UseC > 0 then ohlcvO else na, high = ohlcvH , low = ohlcvL , close = ohlcvC,
type = ChartType.CANDLE, growcolor = GlobalColor("Up"));
AddChart(open = if UseC > 0 then na else ohlcvC, high = ohlcvH , low = ohlcvL , close = ohlcvO,
type = ChartType.CANDLE, growcolor = GlobalColor("Dn"));
#/ Plot the EMA and filter out the noise with volume control. |
#//------------------------------------------------------------
#// Calculate EMAs
def emaFast = MovingAverage(MovAvgType, ohlcvC, MovAvgFastLength);
def emaSlow = MovingAverage(MovAvgType, ohlcvC, MovAvgSlowLength);
def emaVolFast = MovingAverage(MovAvgType, ohlcvV, MovAvgFastLength);
def emaVolSlow = MovingAverage(MovAvgType, ohlcvV, MovAvgSlowLength);
def Signal = if usecandle then emaFast > emaSlow else emaVolFast > emaVolSlow;
#// Calculate volume moving average
def volumeMA = Average(ohlcvV, volumeConfirmationLength);
#// Determine crossover and crossunder conditions
def crossover = Crosses(emaFast, emaSlow, CrossingDirection.ABOVE);
def crossunder = Crosses(emaFast, emaSlow, CrossingDirection.BELOW);
#// Function to check for volume confirmation
script isVolumeConfirmed {
input source = volume;
input length = 6;
input ma = volume;
def sumVol1 = Sum(if source > ma then source else 0, length);
def sumVol2 = Sum(if source < ma then source else 0, length);
def isVolumeConfirmed = sumVol1 >= sumVol2;
plot out = isVolumeConfirmed;
}
#// Check for volume confirmation on crossover and crossunder
def isVolConfirm = isVolumeConfirmed(ohlcvV, volumeConfirmationLength, volumeMA);
def crossoverConfirmed = crossover and isVolConfirm;
def crossunderConfirmed = crossunder and isVolConfirm;
#// Plot EMAs with fill based on gradient
def PF = if showMovAvg then emaFast else na;
def PS = if showMovAvg then emaSlow else na;
def PFVol = if showMovAvg then emaVolFast else na;
def PSVol = if showMovAvg then emaVolSlow else na;
plot p1 = if usecandle then PF else PFVol;
plot p2 = if usecandle then PS else PSVol;
p1.AssignValueColor(if Signal then Color.GREEN else Color.RED);
p2.AssignValueColor(if Signal then Color.GREEN else Color.RED);
AddCloud(p1, p2, Color.DARK_GREEN, Color.DARK_RED);
AddChartBubble(showSignals and crossoverConfirmed, if usecandle then ohlcvL else ohlcvV, "B", Color.GREEN,if usecandle then no else yes);
AddChartBubble(showSignals and crossunderConfirmed, if usecandle then ohlcvH else ohlcvV, "S", Color.RED);
#-- END of CODE
Upper Study Code:
CSS:
#/ This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © hapharmonic
#indicator('Volume Delta [hapharmonic]',format=FV, max_bars_back=5000, max_labels_count=500)
# Converted by Samer4Cok@Samer800 - 05/2024
input ChartStyle = {default "Volume Chart", "Volume Delta Candlestick"}; #(true,title = 'Volume on Candles')
input showSignals = yes;
input showLabel = yes; #(false,inline = 'l') ,
input showBuyStrengthLebel = yes; #(true,inline = 'l')
input showMovAvg = yes; #(true,title = 'EMA Volume Confirmed',group = "EMA Volume")
input MovAvgType = AverageType.EXPONENTIAL;
input MovAvgFastLength = 12; #, title="Fast EMA Length",group = "EMA Volume")
input MovAvgSlowLength = 26; #, title="Slow EMA Length",group = "EMA Volume")
input volumeConfirmationLength = 6; #, title="Volume Confirmation Length",group = "EMA Volume")
def na = Double.NaN;
def last = !IsNaN(close[1]);
def usecandle = ChartStyle == ChartStyle."Volume Delta Candlestick";
def ohlcvO = open;
def ohlcvH = high;
def ohlcvL = low;
def ohlcvC = close;
def ohlcvV = volume;
HidePricePlot(usecandle);
#-- Colors
DefineGlobalColor("Up", Color.CYAN);
DefineGlobalColor("Dn", Color.MAGENTA);
#// Calculate volumes and percentages |
#calcVolumes(OHLCV ohlcv) =>
def volDatabuyVol = ohlcvV * (ohlcvC - ohlcvL) / (ohlcvH - ohlcvL);
def volDatasellVol = ohlcvV - volDatabuyVol;
def volDatapcBuy = volDatabuyVol / ohlcvV * 100;
def volDatapcSell = 100 - volDatapcBuy;
def volDataisBuyGreater = volDatabuyVol > volDatasellVol;
def volDatahigherCol = if volDataisBuyGreater then 1 else 0;
#-- Labrl
def volStr = if last then Round(Sign(ohlcvC - ohlcvC[1]) * ohlcvV / 1000000, 3) else volStr[1];
def buyPercentStr = if last then Round(volDatapcBuy, 2) else buyPercentStr[1];
def sellPercentStr = if last then Round(volDatapcSell, 2) else sellPercentStr[1];
def totalbuyPercentC = if last then volDatabuyVol / (volDatabuyVol + volDatasellVol) else totalbuyPercentC[1];
def cnt1 = if 19 < (20 * totalbuyPercentC) then 1 else 0;
def cnt2 = if 18 < (20 * totalbuyPercentC) then 1 else 0;
def cnt3 = if 17 < (20 * totalbuyPercentC) then 1 else 0;
def cnt4 = if 16 < (20 * totalbuyPercentC) then 1 else 0;
def cnt5 = if 15 < (20 * totalbuyPercentC) then 1 else 0;
def cnt6 = if 14 < (20 * totalbuyPercentC) then 1 else 0;
def cnt7 = if 13 < (20 * totalbuyPercentC) then 1 else 0;
def cnt8 = if 12 < (20 * totalbuyPercentC) then 1 else 0;
def cnt9 = if 11 < (20 * totalbuyPercentC) then 1 else 0;
def cnt10 = if 10 < (20 * totalbuyPercentC) then 1 else 0;
def cnt11 = if 9 < (20 * totalbuyPercentC) then 1 else 0;
def cnt12 = if 8 < (20 * totalbuyPercentC) then 1 else 0;
def cnt13 = if 7 < (20 * totalbuyPercentC) then 1 else 0;
def cnt14 = if 6 < (20 * totalbuyPercentC) then 1 else 0;
def cnt15 = if 5 < (20 * totalbuyPercentC) then 1 else 0;
def cnt16 = if 4 < (20 * totalbuyPercentC) then 1 else 0;
def cnt17 = if 3 < (20 * totalbuyPercentC) then 1 else 0;
def cnt18 = if 2 < (20 * totalbuyPercentC) then 1 else 0;
def cnt19 = if 1 < (20 * totalbuyPercentC) then 1 else 0;
def cnt20 = if 0 < (20 * totalbuyPercentC) then 1 else 0;
def totPer = cnt1 + cnt2 + cnt3 + cnt4 + cnt5 + cnt6 + cnt7 + cnt8 + cnt9 + cnt10
+ cnt11+ cnt12+ cnt13+ cnt14+ cnt15+ cnt16+ cnt17+ cnt18+ cnt19+ cnt20;
AddLabel(showLabel, "Net: " + volStr + "M", if volStr > 0 then Color.LIGHT_GREEN else
if volStr < 0 then Color.PINK else Color.GRAY);
AddLabel(showLabel, "Buy: " + buyPercentStr + "%", if buyPercentStr > 50 then Color.GREEN else Color.DARK_GREEN);
AddLabel(showLabel, "Sell: " + sellPercentStr + "%", if sellPercentStr > 50 then Color.RED else Color.DARK_RED);
AddLabel(showBuyStrengthLebel, "100%", if cnt1 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "95%", if cnt2 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "90%", if cnt3 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "85%", if cnt4 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "80%", if cnt5 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "75%", if cnt6 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "70%", if cnt7 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "65%", if cnt8 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "60%", if cnt9 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "55%", if cnt10 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "50%", if cnt11 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "45%", if cnt12 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "40%", if cnt13 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "35%", if cnt14 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "30%", if cnt15 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "25%", if cnt16 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "20%", if cnt17 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "15%", if cnt18 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, "10%", if cnt19 > 0 then Color.CYAN else Color.MAGENTA);
AddLabel(showBuyStrengthLebel, " 5%", if cnt20 > 0 then Color.CYAN else Color.MAGENTA);
#/ Draw volume levels on the candlesticks |
#// Define base and value for gradient candles
def base;
def value;
#// Calculate base and value based on buy/sell volume and open/close relationship
if volDataisBuyGreater {
base = Min(ohlcvO, ohlcvC); # // Start from the lower of open/close for buy
value = base + AbsValue(ohlcvO - ohlcvC) * (volDatapcBuy / 100); # // Extend to the percentage of buy volume
} else {
base = Max(ohlcvO, ohlcvC); # // Start from the higher of open/close for sell
value = base - AbsValue(ohlcvO - ohlcvC) * (volDatapcSell / 100); # // Extend to the percentage of sell volume
}
def UseC = if usecandle then volDatahigherCol else na;
AddChart(open = if UseC > 0 then value else na, high = base , low = value , close = base,
type = ChartType.CANDLE, growcolor = GlobalColor("Up"));
AddChart(open = if UseC > 0 then na else base, high = base , low = value , close = value,
type = ChartType.CANDLE, growcolor = GlobalColor("Dn"));
AddChart(open = if UseC > 0 then ohlcvO else na, high = ohlcvH , low = ohlcvL , close = ohlcvC,
type = ChartType.CANDLE, growcolor = GlobalColor("Up"));
AddChart(open = if UseC > 0 then na else ohlcvC, high = ohlcvH , low = ohlcvL , close = ohlcvO,
type = ChartType.CANDLE, growcolor = GlobalColor("Dn"));
#/ Plot the EMA and filter out the noise with volume control. |
#//------------------------------------------------------------
#// Calculate EMAs
def emaFast = MovingAverage(MovAvgType, ohlcvC, MovAvgFastLength);
def emaSlow = MovingAverage(MovAvgType, ohlcvC, MovAvgSlowLength);
def Signal = emaFast > emaSlow;
#// Calculate volume moving average
def volumeMA = Average(ohlcvV, volumeConfirmationLength);
#// Determine crossover and crossunder conditions
def crossover = Crosses(emaFast, emaSlow, CrossingDirection.ABOVE);
def crossunder = Crosses(emaFast, emaSlow, CrossingDirection.BELOW);
#// Function to check for volume confirmation
script isVolumeConfirmed {
input source = volume;
input length = 6;
input ma = volume;
def sumVol1 = Sum(if source > ma then source else 0, length);
def sumVol2 = Sum(if source < ma then source else 0, length);
def isVolumeConfirmed = sumVol1 >= sumVol2;
plot out = isVolumeConfirmed;
}
#// Check for volume confirmation on crossover and crossunder
def isVolConfirm = isVolumeConfirmed(ohlcvV, volumeConfirmationLength, volumeMA);
def crossoverConfirmed = crossover and isVolConfirm;
def crossunderConfirmed = crossunder and isVolConfirm;
#// Plot EMAs with fill based on gradient
def PF = if showMovAvg then emaFast else na;
def PS = if showMovAvg then emaSlow else na;
plot fastMovAvg = PF;
plot slowMovAvg = PS;
fastMovAvg.AssignValueColor(if Signal then Color.GREEN else Color.RED);
slowMovAvg.AssignValueColor(if Signal then Color.GREEN else Color.RED);
AddCloud(fastMovAvg, slowMovAvg, Color.DARK_GREEN, Color.DARK_RED);
AddChartBubble(showSignals and crossoverConfirmed, low, "B", Color.GREEN, no);
AddChartBubble(showSignals and crossunderConfirmed,high, "S", Color.RED);
#-- END of CODE