K_O_Trader
Member
Any way to put a second moving average on this indicator?
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
try the belowAny way to put a second moving average on this indicator?
#study("Cumulative Delta Volume", "CDV")
#https://www.tradingview.com/script/vB1T3EMp-Cumulative-Delta-Volume/
# Created based on LonesomeTheBlue code above - Sam4Cok @ 08/2022
# Added time reset option, Added VWAP option - Sam4Cok@Samer800 - 11/2022
# Added Scrond Mov Avg by Sam4COK@Samer800 - 12/2022
declare lower;
input linestyle = {default HeikinAshi, Candle, Line};
input timeFrame = {default DAY, WEEK, MONTH, ALL};
input maType = {SMMA,default VWAP, SMA, HMA, EMA, WMA};
input ma2Type = {default SMMA,VWAP, SMA, HMA, EMA, WMA};
input maLength = 50; #"MA Length"
input ma2Length = 10; #"MA Length"
input BarColor = no;
input BackgroundColor = yes;
input ShowMovAvg = yes;
input ShowBand = no;
def na = Double.NaN;
def cl = close; def op = open; def vo = volume;
def yyyyMmDd = GetYYYYMMDD();
def periodIndx;
switch (timeFrame) {
case DAY:
periodIndx = yyyyMmDd;
case WEEK:
periodIndx = Floor((DaysFromDate(First(yyyyMmDd)) + GetDayOfWeek(First(yyyyMmDd))) / 7);
case MONTH:
periodIndx = RoundDown(yyyyMmDd / 100, 0);
case ALL:
periodIndx = na;
}
def isPeriodRolled = CompoundValue(1, periodIndx != periodIndx[1], yes);
###############
script nz {
input data = volume;
input replacement = 0;
def ret_val = if IsNaN(data) then replacement else data;
plot return = ret_val;
}
# volVWAP
script VVWAP {
input src = close;
def timeFrame = AggregationPeriod.DAY;
def v = volume;
def cap = GetAggregationPeriod();
def errorInAggregation = cap >= AggregationPeriod.WEEK;
Assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period");
def yyyyMmDd = GetYYYYMMDD();
def periodIndx = yyyyMmDd;
def isPeriodRolled = CompoundValue(1, periodIndx != periodIndx[1], yes);
def volumeSum;
def volumeVwapSum;
if (isPeriodRolled) {
volumeSum = v;
volumeVwapSum = v * src;
} else {
volumeSum = CompoundValue(1, volumeSum[1] + v, v);
volumeVwapSum = CompoundValue(1, volumeVwapSum[1] + v * src, v * src);
}
def price = volumeVwapSum / volumeSum;
plot return = price;
}
#ma(source, length, type) =>
script ma {
input source = close;
input length = 10;
input type = "SMA";
def ma;
ma = if type == "VWAP" then VVWAP(source) else
if type == "SMA" then SimpleMovingAvg(source, length) else
if type == "EMA" then ExpAverage(source, length) else
if type == "WMA" then WMA(source, length) else
if type == "HMA" then WMA(2 * WMA(source, length / 2) - WMA(source, length), Round(Sqrt(length)))
else if IsNaN(ma[1]) then SimpleMovingAvg(source, length) else
(ma[1] * (length - 1) + source) / length;
plot result = ma;
}
#_rate(cond) =>
script _rate {
input cond = 1;
def o = open; def c = close; def l = low;
def criteria = if cond == 1 then o <= c else o > c;
def tw = high - Max(o, c) ;
def bw = Min(o, c) - l;
def body = AbsValue(c - o);
def ret = 0.5 * (tw + bw + (if criteria then 2 * body else 0)) / (tw + bw + body);
def rate = if nz(ret) == 0 then 0.5 else ret;
plot Result = rate;
}
def deltaup = vo * _rate(1);
def deltadown = vo * _rate(0);
def delta = if cl >= op then deltaup else -deltadown;
def cumdelta1;
if isNaN(isPeriodRolled) {
cumdelta1 = TotalSum(delta);
} else {
if (isPeriodRolled) {
cumdelta1 = delta;
} else {
cumdelta1 = CompoundValue(1, cumdelta1[1] + delta, delta);
}}
def cumdelta = cumdelta1;
def o;
def h;
def l;
def c;
def ctl;
if linestyle != linestyle.Line
then {
o = cumdelta[1];
h = Max(cumdelta, cumdelta[1]);
l = Min(cumdelta, cumdelta[1]);
c = cumdelta;
ctl = na;
} else {
o = na;
h = na;
l = na;
c = na;
ctl = cumdelta;
}
def LineClose = ExpAverage((cumdelta[1] + Max(cumdelta, cumdelta[1]) + Min(cumdelta, cumdelta[1]) + cumdelta) / 4, 5);
def LineOpen = ExpAverage(if IsNaN(LineOpen[1]) then (cumdelta[1] + cumdelta) / 2 else (LineOpen[1] + LineClose[1]) / 2, 5);
plot Line = ctl;
Line.AssignValueColor( if LineClose >= LineOpen then CreateColor(8, 153, 129) else
if LineClose < LineOpen then CreateColor(239, 83, 80) else Color.GRAY);
Line.SetLineWeight(2);
##############
def _Close = (o + h + l + c) / 4;
def _Open = if IsNaN(_Open[1]) then (o + c) / 2 else (_Open[1] + _Close[1]) / 2;
def _High = Max(Max(h, _Open), _Close);
def _Low = Min(Min(l, _Open), _Close);
def haClose = if linestyle==linestyle.HeikinAshi then _Close else c;
def haOpen = if linestyle==linestyle.HeikinAshi then _Open else o;
def haHigh = if linestyle==linestyle.HeikinAshi then _High else h;
def haLow = if linestyle==linestyle.HeikinAshi then _Low else l;
def Color = if haClose >= haOpen then 1 else -1;
# Plot UP candle
def UpO;
def UpH;
def UpL;
def UpC;
if Color > 0
then {
UpO = haOpen ;
UpH = haHigh ;
UpL = haLow ;
UpC = haClose;
} else
{
UpO = na;
UpH = na;
UpL = na;
UpC = na;
}
# Plot DOWN candle
def DnO;
def DnH;
def DnL;
def DnC;
if Color < 0
then {
DnO = haOpen ;
DnH = haHigh ;
DnL = haLow ;
DnC = haClose;
} else
{
DnO = na;
DnH = na;
DnL = na;
DnC = na;
}
# Plot the new Chart
AddChart(high = UpH , low = UpL , open = UpC, close = UpO,
type = ChartType.CANDLE, growcolor = CreateColor(8, 153, 129));
AddChart(high = DnH , low = DnL , open = DnO, close = DnC,
type = ChartType.CANDLE, growcolor = CreateColor(239, 83, 80));
## Plot MA Lines
plot AvgLine = ma(ctl, maLength, maType);
AvgLine.SetHiding(!ShowMovAvg);
plot AvgLine2 = ma(ctl, ma2Length, ma2Type);
AvgLine.SetHiding(!ShowMovAvg);
plot HaAvgLine = ma(haClose, maLength, maType);
HaAvgLine.SetHiding(!ShowMovAvg);
plot HaAvgLine2 = ma(haClose, ma2Length, ma2Type);
HaAvgLine2.SetHiding(!ShowMovAvg);
### Band
def offs = (1.6185 * StDev(if linestyle != linestyle.Line then haClose else ctl, maLength));
def upBand = (if linestyle != linestyle.Line then HaAvgLine else AvgLine) + offs;
def dnBand = (if linestyle != linestyle.Line then HaAvgLine else AvgLine) - offs;
def BandColor = if (if(linestyle!=linestyle.Line,haClose,ctl)) > upBand then 1 else
if (if(linestyle!=linestyle.Line,haClose,ctl)) < dnBand then -1 else 0;
plot Oband = upBand;
Oband.AssignValueColor(if BandColor > 0 then Color.GREEN else
if BandColor < 0 then Color.RED else CreateColor(100, 181, 246));
Oband.SetHiding(!ShowBand);
plot Sband = dnBand;
Sband.AssignValueColor(if BandColor > 0 then Color.GREEN else
if BandColor < 0 then Color.RED else CreateColor(100, 181, 246));
Sband.SetHiding(!ShowBand);
AvgLine.AssignValueColor(if BandColor > 0 then Color.GREEN else
if BandColor < 0 then Color.RED else Color.WHITE);
AvgLine2.AssignValueColor(if BandColor > 0 then Color.GREEN else
if BandColor < 0 then Color.RED else Color.WHITE);
HaAvgLine.AssignValueColor(if BandColor > 0 then Color.GREEN else
if BandColor < 0 then Color.RED else Color.WHITE);
HaAvgLine2.AssignValueColor(if BandColor > 0 then Color.GREEN else
if BandColor < 0 then Color.RED else Color.WHITE);
### Background
AddCloud(if BackgroundColor then
if (if(linestyle!=linestyle.Line,haClose,ctl)) > Oband then Double.POSITIVE_INFINITY else if
(if linestyle != linestyle.Line then haClose else ctl) < Sband then Double.NEGATIVE_INFINITY else na else na,
if (if linestyle != linestyle.Line then haClose else ctl) > Oband then Double.NEGATIVE_INFINITY else if
(if linestyle != linestyle.Line then haClose else ctl) < Sband then Double.POSITIVE_INFINITY else na, Color.DARK_GREEN, Color.DARK_RED);
### Bar Color
def Exup = if linestyle != linestyle.Line then (Color > 0 and BandColor > 0)
else (LineClose >= LineOpen and BandColor > 0);
def up = if linestyle != linestyle.Line then (Color > 0 and BandColor <= 0)
else (LineClose >= LineOpen and BandColor <= 0) ;
def Exdn = if linestyle != linestyle.Line then (Color < 0 and BandColor < 0)
else (LineClose < LineOpen and BandColor < 0);
def dn = if linestyle != linestyle.Line then (Color < 0 and BandColor >= 0)
else (LineClose < LineOpen and BandColor >= 0);
AssignPriceColor(if BarColor then
if Exup then Color.GREEN else
if up then Color.DARK_GREEN else
if dn then Color.DARK_RED else
if Exdn then Color.RED else Color.GRAY else Color.CURRENT);
### END
shades on TOS need to confirm more than one candle in order to plot the colordoes this repaint? or will the shaded green/red area change or pop up after its already passed the candle?
Okay cool. So if it’s on a 5min time frame. The shaded green/red could change up to 2 candles or 10min period then?shades on TOS need to confirm more than one candle in order to plot the color
//@version=5
indicator("Cummulative Delta", "Delta", format=format.volume)
lowerTimeframeTooltip = "The indicator uses the new Up/Down Volume native indicator on TradingView to calculate the Cummulative Delta based on actual buyer/seller aggression.\n\nHigher timeframes provide more historical data, but the data will be less precise."
barsBackTooltip = "Some higher values only work in lower timeframes"
reset = input.bool(true, "Reset the cummulative Delta at start of day/month/year?", group="Reseting")
barsBack = input.int(300, "Start calculating how many bars back?", tooltip = barsBackTooltip, group="Reseting")
useCustomTimeframeInput = input.bool(false, "Use custom timeframe", tooltip = lowerTimeframeTooltip, group="Custom TF")
lowerTimeframeInput = input.timeframe("1", "Timeframe", group="Custom TF")
upAndDownVolume() =>
posVol = 0.0
negVol = 0.0
switch
close > open => posVol += volume
close < open => negVol -= volume
close >= close[1] => posVol += volume
close < close[1] => negVol -= volume
[posVol, negVol]
lowerTimeframe = switch
useCustomTimeframeInput => lowerTimeframeInput
timeframe.isintraday => "1"
timeframe.isdaily => "5"
=> "60"
[upVolumeArray, downVolumeArray] = request.security_lower_tf(syminfo.tickerid, lowerTimeframe, upAndDownVolume())
upVolume = array.sum(upVolumeArray)
downVolume = array.sum(downVolumeArray)
delta = upVolume + downVolume
dayStart = (dayofmonth[1] != dayofmonth)
monthStart = (month[1] != month)
yearStart = (year[1] != year)
// cumulative delta reset at globex and rth openings
cumdelta = 0.0
cumdelta := (reset == false and (bar_index == last_bar_index - barsBack)) or (reset == true and (((timeframe.isweekly or timeframe.ismonthly) and yearStart) or (timeframe.isdaily and monthStart) or (timeframe.isintraday and dayStart))) ? delta : cumdelta[1]+delta
// getting ohlc values to plot the cumulative delta candles.
float o = na
float h = na
float l = na
float c = na
o := (reset == false and (bar_index == last_bar_index - barsBack)) or (reset == true and (((timeframe.isweekly or timeframe.ismonthly) and yearStart) or (timeframe.isdaily and monthStart) or (timeframe.isintraday and dayStart))) ? 0 : cumdelta[1]
h := ta.highest(cumdelta, 1)
l := ta.lowest(cumdelta, 1)
c := cumdelta
// plotting cumulative delta as candles. Two 'plotcandle' calls to set wickcolor/bordercolor 'dinamically' setting 'o' to 'na' when needed
plotcandle(o<=c?o:na, h, l, c, title='Cumulative Delta Green Candle', color = color.green,wickcolor=color.green,bordercolor=color.green)
plotcandle(o>=c?o:na, h, l, c, title='Cumulative Delta Red Candle', color = color.red,wickcolor=color.red,bordercolor=color.red)
var cumVol = 0.
cumVol += nz(volume)
if barstate.islast and cumVol == 0
runtime.error("The data vendor doesn't provide volume data for this symbol.")
This is Cumulative Delta Volume script based on LonesomeTheBlue script. I added multiple options to identify the trend based on the standard deviation and moving average. You can use it along with your strategy to confirm the entry and exit referring to the delta volume (the difference between buying and selling volume at each price level.
CODE:
CSS:#study("Cumulative Delta Volume", "CDV") #https://www.tradingview.com/script/vB1T3EMp-Cumulative-Delta-Volume/ # Created based on LonesomeTheBlue code link above - Sam4Cok @ 08/2022 declare lower; input linestyle = {default Candle, Line}; input HeikinAshi = yes; #"Heikin Ashi Candles?") input maType = {default "SMMA", "SMA", "HMA", "EMA", "WMA"}; input maLength = 50; #"MA Length" input BarColor = no; input BackgroundColor = yes; input ShowMovAvg = yes; input ShowBand = no; def na = Double.NaN; ############### script nz { input data = 0; input replacement = 0; def ret_val = if IsNaN(data) then replacement else data; plot return = ret_val; } #ma(source, length, type) => script ma { input source = close; input length = 0; input type = "SMA"; def ma; ma = if type == "SMA" then SimpleMovingAvg(source, length) else if type == "EMA" then ExpAverage(source, length) else if type == "WMA" then WMA(source, length) else if type == "HMA" then WMA(2 * WMA(source, length / 2) - WMA(source, length), Round(Sqrt(length))) else if isNaN(ma[1]) then SimpleMovingAvg(source, length) else (ma[1] * (length - 1) + source) / length; plot result = ma; } #_rate(cond) => script _rate { input cond = 1; def criteria = if cond == 1 then open <= close else open > close; def tw = high - Max(open, close) ; def bw = Min(open, close) - low; def body = AbsValue(close - open); def ret = 0.5 * (tw + bw + (if criteria then 2 * body else 0)) / (tw + bw + body); def rate = if nz(ret) == 0 then 0.5 else ret; plot Result = rate; } def deltaup = volume * _rate(1); def deltadown = volume * _rate(0); def delta = if close >= open then deltaup else -deltadown; def cumdelta = TotalSum(delta); def o; def h; def l; def c; def ctl; if linestyle == linestyle.Candle then { o = cumdelta[1]; h = Max(cumdelta, cumdelta[1]); l = Min(cumdelta, cumdelta[1]); c = cumdelta; ctl = na; } else { o = na; h = na; l = na; c = na; ctl = cumdelta; } def LineClose = ExpAverage((cumdelta[1] + Max(cumdelta, cumdelta[1]) + Min(cumdelta, cumdelta[1]) + cumdelta) / 4, 5); def LineOpen = ExpAverage(if IsNaN(LineOpen[1]) then (cumdelta[1] + cumdelta) / 2 else (LineOpen[1] + LineClose[1]) / 2, 5); plot Line = ctl; Line.AssignValueColor( if LineClose >= LineOpen then CreateColor(8,153,129) else if LineClose < LineOpen then CreateColor(239, 83, 80) else Color.GRAY); Line.SetLineWeight(2); ############## def _Close = (o + h + l + c) / 4; def _Open = if IsNaN(_Open[1]) then (o + c) / 2 else (_Open[1] + _Close[1]) / 2; def _High = Max(Max(h, _Open), _Close); def _Low = Min(Min(l, _Open), _Close); def haClose = if HeikinAshi then _Close else c; def haOpen = if HeikinAshi then _Open else o; def haHigh = if HeikinAshi then _High else h; def haLow = if HeikinAshi then _Low else l; def Color = if haClose >= haOpen then 1 else -1; # Plot UP candle def UpO; def UpH; def UpL; def UpC; if Color > 0 then { UpO = haOpen ; UpH = haHigh ; UpL = haLow ; UpC = haClose; } else { UpO = na; UpH = na; UpL = na; UpC = na; } # Plot DOWN candle def DnO; def DnH; def DnL; def DnC; if Color < 0 then { DnO = haOpen ; DnH = haHigh ; DnL = haLow ; DnC = haClose; } else { DnO = na; DnH = na; DnL = na; DnC = na; } # Plot the new Chart AddChart(high = UpH , low = UpL , open = UpC, close = UpO, type = ChartType.CANDLE, growcolor = CreateColor(8,153,129)); AddChart(high = DnH , low = DnL , open = DnO, close = DnC, type = ChartType.CANDLE, growcolor = CreateColor(239, 83, 80)); ## Plot MA Lines plot AvgLine = ma(ctl, maLength, maType); AvgLine.SetPaintingStrategy(PaintingStrategy.DASHES); AvgLine.SetHiding(!ShowMovAvg); plot HaAvgLine = ma(haClose, maLength, maType); HaAvgLine.SetPaintingStrategy(PaintingStrategy.DASHES); HaAvgLine.SetHiding(!ShowMovAvg); ### Band def offs = (1.6185 * stdev(if linestyle == linestyle.Candle then haClose else ctl, maLength)); def upBand = (if linestyle == linestyle.Candle then HaAvgLine else AvgLine) + offs; def dnBand = (if linestyle == linestyle.Candle then HaAvgLine else AvgLine) - offs; def BandColor = if (if linestyle == linestyle.Candle then haClose else ctl) > upBand then 1 else if (if linestyle == linestyle.Candle then haClose else ctl) < dnBand then -1 else 0; plot Oband = upBand; Oband.AssignValueColor(if BandColor > 0 then Color.GREEN else if BandColor < 0 then Color.RED else CreateColor(100, 181, 246)); Oband.SetHiding(!ShowBand); plot Sband = dnBand; sband.AssignValueColor(if BandColor > 0 then Color.GREEN else if BandColor < 0 then Color.RED else CreateColor(100, 181, 246)); Sband.SetHiding(!ShowBand); AvgLine.AssignValueColor(if BandColor > 0 then Color.GREEN else if BandColor < 0 then Color.RED else Color.WHITE); HaAvgLine.AssignValueColor(if BandColor > 0 then Color.GREEN else if BandColor < 0 then Color.RED else Color.WHITE); ### Background addCloud(if BackgroundColor then if(if linestyle == linestyle.Candle then haClose else ctl) > Oband then Double.POSITIVE_INFINITY else if (if linestyle == linestyle.Candle then haClose else ctl) < Sband then Double.NEGATIVE_INFINITY else na else na, if(if linestyle == linestyle.Candle then haClose else ctl) > Oband then Double.NEGATIVE_INFINITY else if (if linestyle == linestyle.Candle then haClose else ctl) < Sband then Double.POSITIVE_INFINITY else na, Color.DARK_GREEN, Color.DARK_RED); ### Bar Color def Exup = if linestyle == linestyle.Candle then (color > 0 and BandColor > 0) else (LineClose >= LineOpen and BandColor > 0); def up = if linestyle == linestyle.Candle then (color > 0 and BandColor <= 0) else (LineClose >= LineOpen and BandColor <= 0) ; def Exdn = if linestyle == linestyle.Candle then (color < 0 and BandColor < 0) else (LineClose < LineOpen and BandColor < 0); def dn = if linestyle == linestyle.Candle then (color < 0 and BandColor >= 0) else (LineClose < LineOpen and BandColor >= 0); AssignPriceColor(if BarColor then if Exup then Color.GREEN else if up then CreateColor(0,80,80) else if dn then CreateColor(117,0,14) else if Exdn then Color.RED else Color.GRAY else Color.CURRENT); ### END
change the the time frame will reset the calculation period. if you select DAY, the volume calculation will be based on daily, and if you select monthly, the calculation will be on monthly and so on. the difference can be notices when your chart on higher timeframe.Changing that option didn't seem to do anything. I'll just leave it.
Please, can you tell me how i can hidde(yes or not) the bars, with any inputs, and where i need to write in the code? thanks i am not master thinkscripter. thanks
This is Cumulative Delta Volume script based on LonesomeTheBlue script. I added multiple options to identify the trend based on the standard deviation and moving average. You can use it along with your strategy to confirm the entry and exit referring to the delta volume (the difference between buying and selling volume at each price level.
CODE:
CSS:#study("Cumulative Delta Volume", "CDV") #https://www.tradingview.com/script/vB1T3EMp-Cumulative-Delta-Volume/ # Created based on LonesomeTheBlue code link above - Sam4Cok @ 08/2022 declare lower; input linestyle = {default Candle, Line}; input HeikinAshi = yes; #"Heikin Ashi Candles?") input maType = {default "SMMA", "SMA", "HMA", "EMA", "WMA"}; input maLength = 50; #"MA Length" input BarColor = no; input BackgroundColor = yes; input ShowMovAvg = yes; input ShowBand = no; def na = Double.NaN; ############### script nz { input data = 0; input replacement = 0; def ret_val = if IsNaN(data) then replacement else data; plot return = ret_val; } #ma(source, length, type) => script ma { input source = close; input length = 0; input type = "SMA"; def ma; ma = if type == "SMA" then SimpleMovingAvg(source, length) else if type == "EMA" then ExpAverage(source, length) else if type == "WMA" then WMA(source, length) else if type == "HMA" then WMA(2 * WMA(source, length / 2) - WMA(source, length), Round(Sqrt(length))) else if isNaN(ma[1]) then SimpleMovingAvg(source, length) else (ma[1] * (length - 1) + source) / length; plot result = ma; } #_rate(cond) => script _rate { input cond = 1; def criteria = if cond == 1 then open <= close else open > close; def tw = high - Max(open, close) ; def bw = Min(open, close) - low; def body = AbsValue(close - open); def ret = 0.5 * (tw + bw + (if criteria then 2 * body else 0)) / (tw + bw + body); def rate = if nz(ret) == 0 then 0.5 else ret; plot Result = rate; } def deltaup = volume * _rate(1); def deltadown = volume * _rate(0); def delta = if close >= open then deltaup else -deltadown; def cumdelta = TotalSum(delta); def o; def h; def l; def c; def ctl; if linestyle == linestyle.Candle then { o = cumdelta[1]; h = Max(cumdelta, cumdelta[1]); l = Min(cumdelta, cumdelta[1]); c = cumdelta; ctl = na; } else { o = na; h = na; l = na; c = na; ctl = cumdelta; } def LineClose = ExpAverage((cumdelta[1] + Max(cumdelta, cumdelta[1]) + Min(cumdelta, cumdelta[1]) + cumdelta) / 4, 5); def LineOpen = ExpAverage(if IsNaN(LineOpen[1]) then (cumdelta[1] + cumdelta) / 2 else (LineOpen[1] + LineClose[1]) / 2, 5); plot Line = ctl; Line.AssignValueColor( if LineClose >= LineOpen then CreateColor(8,153,129) else if LineClose < LineOpen then CreateColor(239, 83, 80) else Color.GRAY); Line.SetLineWeight(2); ############## def _Close = (o + h + l + c) / 4; def _Open = if IsNaN(_Open[1]) then (o + c) / 2 else (_Open[1] + _Close[1]) / 2; def _High = Max(Max(h, _Open), _Close); def _Low = Min(Min(l, _Open), _Close); def haClose = if HeikinAshi then _Close else c; def haOpen = if HeikinAshi then _Open else o; def haHigh = if HeikinAshi then _High else h; def haLow = if HeikinAshi then _Low else l; def Color = if haClose >= haOpen then 1 else -1; # Plot UP candle def UpO; def UpH; def UpL; def UpC; if Color > 0 then { UpO = haOpen ; UpH = haHigh ; UpL = haLow ; UpC = haClose; } else { UpO = na; UpH = na; UpL = na; UpC = na; } # Plot DOWN candle def DnO; def DnH; def DnL; def DnC; if Color < 0 then { DnO = haOpen ; DnH = haHigh ; DnL = haLow ; DnC = haClose; } else { DnO = na; DnH = na; DnL = na; DnC = na; } # Plot the new Chart AddChart(high = UpH , low = UpL , open = UpC, close = UpO, type = ChartType.CANDLE, growcolor = CreateColor(8,153,129)); AddChart(high = DnH , low = DnL , open = DnO, close = DnC, type = ChartType.CANDLE, growcolor = CreateColor(239, 83, 80)); ## Plot MA Lines plot AvgLine = ma(ctl, maLength, maType); AvgLine.SetPaintingStrategy(PaintingStrategy.DASHES); AvgLine.SetHiding(!ShowMovAvg); plot HaAvgLine = ma(haClose, maLength, maType); HaAvgLine.SetPaintingStrategy(PaintingStrategy.DASHES); HaAvgLine.SetHiding(!ShowMovAvg); ### Band def offs = (1.6185 * stdev(if linestyle == linestyle.Candle then haClose else ctl, maLength)); def upBand = (if linestyle == linestyle.Candle then HaAvgLine else AvgLine) + offs; def dnBand = (if linestyle == linestyle.Candle then HaAvgLine else AvgLine) - offs; def BandColor = if (if linestyle == linestyle.Candle then haClose else ctl) > upBand then 1 else if (if linestyle == linestyle.Candle then haClose else ctl) < dnBand then -1 else 0; plot Oband = upBand; Oband.AssignValueColor(if BandColor > 0 then Color.GREEN else if BandColor < 0 then Color.RED else CreateColor(100, 181, 246)); Oband.SetHiding(!ShowBand); plot Sband = dnBand; sband.AssignValueColor(if BandColor > 0 then Color.GREEN else if BandColor < 0 then Color.RED else CreateColor(100, 181, 246)); Sband.SetHiding(!ShowBand); AvgLine.AssignValueColor(if BandColor > 0 then Color.GREEN else if BandColor < 0 then Color.RED else Color.WHITE); HaAvgLine.AssignValueColor(if BandColor > 0 then Color.GREEN else if BandColor < 0 then Color.RED else Color.WHITE); ### Background addCloud(if BackgroundColor then if(if linestyle == linestyle.Candle then haClose else ctl) > Oband then Double.POSITIVE_INFINITY else if (if linestyle == linestyle.Candle then haClose else ctl) < Sband then Double.NEGATIVE_INFINITY else na else na, if(if linestyle == linestyle.Candle then haClose else ctl) > Oband then Double.NEGATIVE_INFINITY else if (if linestyle == linestyle.Candle then haClose else ctl) < Sband then Double.POSITIVE_INFINITY else na, Color.DARK_GREEN, Color.DARK_RED); ### Bar Color def Exup = if linestyle == linestyle.Candle then (color > 0 and BandColor > 0) else (LineClose >= LineOpen and BandColor > 0); def up = if linestyle == linestyle.Candle then (color > 0 and BandColor <= 0) else (LineClose >= LineOpen and BandColor <= 0) ; def Exdn = if linestyle == linestyle.Candle then (color < 0 and BandColor < 0) else (LineClose < LineOpen and BandColor < 0); def dn = if linestyle == linestyle.Candle then (color < 0 and BandColor >= 0) else (LineClose < LineOpen and BandColor >= 0); AssignPriceColor(if BarColor then if Exup then Color.GREEN else if up then CreateColor(0,80,80) else if dn then CreateColor(117,0,14) else if Exdn then Color.RED else Color.GRAY else Color.CURRENT); ### END
yes background (AddCloud) function in TOS need at least 2 confirmed candles to be plotHey Sameer Anyway to Change the background color to match the MA Pressure line its a Bar off.. Thanks!
#study("Cumulative Delta Volume", "CDV")
#https://www.tradingview.com/script/vB1T3EMp-Cumulative-Delta-Volume/
# Created based on LonesomeTheBlue code link above - Sam4Cok @ 08/2022
#mod by AnimalMother 4/23
#One
declare lower;
input HeikinAshiX = yes;
def naX = Double.NaN;
script nzX {
input dataX = 0;
input replacementX = 0;
def ret_valX = if IsNaN(dataX) then replacementX else dataX;
plot returnX = ret_valX;
}
script _rateX {
input condX = 1;
def criteriaX = if condX == 1 then open <= close else open > close;
def twX = high - Max(open, close) ;
def bwX = Min(open, close) - low;
def bodyX = AbsValue(close - open);
def retX = 0.5 * (twX + bwX + (if criteriaX then 2 * bodyX else 0)) / (twX + bwX + bodyX);
def rateX = if nzX(retX) == 0 then 0.5 else retX;
plot ResultX = rateX;
}
def deltaupX = volume * _rateX(1);
def deltadownX = volume * _rateX(0);
def deltaX = if close >= open then deltaupX else -deltadownX;
def cumdeltaX = TotalSum(deltaX);
def haCloseX = if HeikinAshiX then (cumdeltaX[1] + Max(cumdeltaX, cumdeltaX[1]) + Min(cumdeltaX, cumdeltaX[1]) + cumdeltaX) / 4 else cumdeltaX;
def haOpenX = if HeikinAshiX then ExpAverage(if IsNaN(haOpenX[1]) then (cumdeltaX[1] + cumdeltaX) / 2 else (haOpenX[1] + haCloseX[1]) / 2, 5) else cumdeltaX[1];
def ColorX = if haCloseX >= haOpenX then 1 else -1;
plot ContinuousLineX = (cumdeltaX);
ContinuousLineX.SetLineWeight(2);
ContinuousLineX.AssignValueColor(if ColorX > 0 then CreateColor(255, 200, 0) else CreateColor(255, 255, 255));
#study("Cumulative Delta Volume", "CDV")
#https://www.tradingview.com/script/vB1T3EMp-Cumulative-Delta-Volume/
# Created based on LonesomeTheBlue code link above - Sam4Cok @ 08/2022
#mod by AnimalMother 4/23
#Two
declare lower;
input HeikinAshiX = yes;
script _rateX {
input condX = 1;
def criteriaX = if condX == 1 then open <= close else open > close;
def twX = high - Max(open, close) ;
def bwX = Min(open, close) - low;
def bodyX = AbsValue(close - open);
def retX = 0.5 * (twX + bwX + (if criteriaX then 2 * bodyX else 0)) / (twX + bwX + bodyX);
def rateX = if IsNaN(retX) then 0.5 else retX;
plot ResultX = rateX;
}
def deltaupX = volume * _rateX(1);
def deltadownX = volume * _rateX(0);
def deltaX = if close >= open then deltaupX else -deltadownX;
def cumdeltaX = TotalSum(deltaX);
def haCloseX = if HeikinAshiX then (cumdeltaX[1] + Max(cumdeltaX, cumdeltaX[1]) + Min(cumdeltaX, cumdeltaX[1]) + cumdeltaX) / 4 else cumdeltaX;
def haOpenX = if HeikinAshiX then ExpAverage(if IsNaN(haOpenX[1]) then (cumdeltaX[1] + cumdeltaX) / 2 else (haOpenX[1] + haCloseX[1]) / 2, 5) else cumdeltaX[1];
def ColorX = if haCloseX >= haOpenX then 1 else -1;
plot UpCandle = Absvalue(if ColorX > 0 then cumdeltaX else Double.NaN);
plot DownCandle = Absvalue(if ColorX < 0 then cumdeltaX else Double.NaN);
UpCandle.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
UpCandle.SetLineWeight(3);
UpCandle.AssignValueColor(CreateColor(255, 200, 0));
DownCandle.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
DownCandle.SetLineWeight(3);
DownCandle.AssignValueColor(CreateColor(255, 255, 255));
#study("Cumulative Delta Volume", "CDV")
#https://www.tradingview.com/script/vB1T3EMp-Cumulative-Delta-Volume/
# Created based on LonesomeTheBlue code link above - Sam4Cok @ 08/2022
#mod by AnimalMother 4/23
#Tres
declare lower;
input HeikinAshiX = yes;
script _rateX {
input condX = 1;
def criteriaX = if condX == 1 then open <= close else open > close;
def twX = high - Max(open, close) ;
def bwX = Min(open, close) - low;
def bodyX = AbsValue(close - open);
def retX = 0.5 * (twX + bwX + (if criteriaX then 2 * bodyX else 0)) / (twX + bwX + bodyX);
def rateX = if IsNaN(retX) then 0.5 else retX;
plot ResultX = rateX;
}
def deltaupX = volume * _rateX(1);
def deltadownX = volume * _rateX(0);
def deltaX = if close >= open then deltaupX else -deltadownX;
def cumdeltaX = TotalSum(deltaX);
def haCloseX = if HeikinAshiX then (cumdeltaX[1] + Max(cumdeltaX, cumdeltaX[1]) + Min(cumdeltaX, cumdeltaX[1]) + cumdeltaX) / 4 else cumdeltaX;
def haOpenX = if HeikinAshiX then ExpAverage(if IsNaN(haOpenX[1]) then (cumdeltaX[1] + cumdeltaX) / 2 else (haOpenX[1] + haCloseX[1]) / 2, 5) else cumdeltaX[1];
def ColorX = if haCloseX >= haOpenX then 1 else -1;
def UpO;
def UpH;
def UpL;
def UpC;
if ColorX > 0
then {
UpO = haOpenX ;
UpH = Max(cumdeltaX, cumdeltaX[1]);
UpL = Min(cumdeltaX, cumdeltaX[1]);
UpC = haCloseX;
} else
{
UpO = Double.NaN;
UpH = Double.NaN;
UpL = Double.NaN;
UpC = Double.NaN;
}
def DnO;
def DnH;
def DnL;
def DnC;
if ColorX < 0
then {
DnO = haOpenX ;
DnH = Max(cumdeltaX, cumdeltaX[1]);
DnL = Min(cumdeltaX, cumdeltaX[1]);
DnC = haCloseX;
} else
{
DnO = Double.NaN;
DnH = Double.NaN;
DnL = Double.NaN;
DnC = Double.NaN;
}
AddChart(high = UpH , low = UpL , open = UpC, close = UpO,
type = ChartType.CANDLE, growcolor = CreateColor(255, 200, 0));
AddChart(high = DnH , low = DnL , open = DnO, close = DnC,
type = ChartType.CANDLE, growcolor = CreateColor(255, 255, 255));
@AnimalMother Can you please add Exponential Moving Average 200 in it? ThanksRuby:#study("Cumulative Delta Volume", "CDV") #https://www.tradingview.com/script/vB1T3EMp-Cumulative-Delta-Volume/ # Created based on LonesomeTheBlue code link above - Sam4Cok @ 08/2022 #mod by AnimalMother 4/23 #Tres declare lower; input HeikinAshiX = yes; script _rateX { input condX = 1; def criteriaX = if condX == 1 then open <= close else open > close; def twX = high - Max(open, close) ; def bwX = Min(open, close) - low; def bodyX = AbsValue(close - open); def retX = 0.5 * (twX + bwX + (if criteriaX then 2 * bodyX else 0)) / (twX + bwX + bodyX); def rateX = if IsNaN(retX) then 0.5 else retX; plot ResultX = rateX; } def deltaupX = volume * _rateX(1); def deltadownX = volume * _rateX(0); def deltaX = if close >= open then deltaupX else -deltadownX; def cumdeltaX = TotalSum(deltaX); def haCloseX = if HeikinAshiX then (cumdeltaX[1] + Max(cumdeltaX, cumdeltaX[1]) + Min(cumdeltaX, cumdeltaX[1]) + cumdeltaX) / 4 else cumdeltaX; def haOpenX = if HeikinAshiX then ExpAverage(if IsNaN(haOpenX[1]) then (cumdeltaX[1] + cumdeltaX) / 2 else (haOpenX[1] + haCloseX[1]) / 2, 5) else cumdeltaX[1]; def ColorX = if haCloseX >= haOpenX then 1 else -1; def UpO; def UpH; def UpL; def UpC; if ColorX > 0 then { UpO = haOpenX ; UpH = Max(cumdeltaX, cumdeltaX[1]); UpL = Min(cumdeltaX, cumdeltaX[1]); UpC = haCloseX; } else { UpO = Double.NaN; UpH = Double.NaN; UpL = Double.NaN; UpC = Double.NaN; } def DnO; def DnH; def DnL; def DnC; if ColorX < 0 then { DnO = haOpenX ; DnH = Max(cumdeltaX, cumdeltaX[1]); DnL = Min(cumdeltaX, cumdeltaX[1]); DnC = haCloseX; } else { DnO = Double.NaN; DnH = Double.NaN; DnL = Double.NaN; DnC = Double.NaN; } AddChart(high = UpH , low = UpL , open = UpC, close = UpO, type = ChartType.CANDLE, growcolor = CreateColor(255, 200, 0)); AddChart(high = DnH , low = DnL , open = DnO, close = DnC, type = ChartType.CANDLE, growcolor = CreateColor(255, 255, 255));
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
R | Cumulative Volume Delta For ThinkOrSwim | Indicators | 1 | |
I | Cumulative Volume Delta Indicator For ThinkOrSwim | Indicators | 14 | |
Cumulative Volume Chart, Watchlists, Scan, Label for ThinkorSwim | Indicators | 34 | ||
Cumulative Tick Indicator for ThinkorSwim | Indicators | 34 | ||
A | Trade Volume Delta Indicator for ThinkorSwim | Indicators | 49 |
Start a new thread and receive assistance from our community.
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.