Dem Sup
Dem Sup
Dem Sup
max_lines_count=500, max_labels_count=10)
import PineCoders/Time/2 as timeLib
import PineCoders/lower_tf/3 as PCltf
import TradingView/ta/4 as TVta
// ————— Constants
// Default colors
color GRAY = #808080ff
color LIME = #00FF00ff
color MAROON = #800000ff
color ORANGE = #FF8000ff
color PINK = #FF0080ff
color TEAL = #008080ff
color BG_DIV = color.new(ORANGE, 90)
color BG_RESETS = color.new(GRAY, 90)
// Reset conditions
string RST1 = "None"
string RST2 = "On a stepped higher timeframe"
string RST3 = "On a fixed higher timeframe..."
string RST4 = "At a fixed time..."
string RST5 = "At the beginning of the regular session"
string RST6 = "At the first visible chart bar"
string RST7 = "On trend changes..."
// Trends
string TR01 = "Supertrend"
string TR02 = "Aroon"
// Intrabar precisions
string LTF1 = "Covering most chart bars (least precise)"
string LTF2 = "Covering some chart bars (less precise)"
string LTF3 = "Covering less chart bars (more precise)"
string LTF4 = "Very precise (2min intrabars)"
string LTF5 = "Most precise (1min intrabars)"
string LTF6 = "~12 intrabars per chart bar"
string LTF7 = "~24 intrabars per chart bar"
string LTF8 = "~50 intrabars per chart bar"
string LTF9 = "~100 intrabars per chart bar"
string LTF10 = "~250 intrabars per chart bar"
// Tooltips
string TT_RST = "This is where you specify how you want the cumulative volume
delta to reset.
If you select one of the last three choices, you must also specify the relevant
additional information below."
string TT_RST_HTF = "This value only matters when '" + RST3 +"' is selected."
string TT_RST_TIME = "Hour: 0-23\nMinute: 0-59\nThese values only matter when '" +
RST4 +"' is selected.
A reset will occur when the time is greater or equal to the bar's open time, and
less than its close time."
string TT_RST_TREND = "These values only matter when '" + RST7 +"' is selected.\n
For Supertrend, the first value is the length of ATR, the second is the factor.
For Aroon, the first value is the lookback length."
string TT_TOTVOL = "Total volume can only be displayed when '" + VD01 +"' is
selected as the Volume Delta Calculation mode.\n\n
The 'Bodies' value is the transparency of the total volume candle bodies. Zero is
opaque, 100 is transparent."
string TT_LINE = "This plots a line at the `close` values of the CVD candles.
You can use it instead of the CVD candles."
string TT_LTF = "Your selection here controls how many intrabars will be
analyzed for each chart bar.
The more intrabars you analyze, the less chart bars will be covered by the
indicator's calculations
because a maximum of 100K intrabars can be analyzed.\n\n
With the first four choices the quantity of intrabars is determined from the type
of chart bar coverage you want.
The last four choices allow you to select approximately how many intrabars you
want analyzed per chart bar."
string TT_MA = "This plots the running average of CVD from its last reset.
The 'Length' period only applies when CVD does not reset, i.e., the reset is
'None'."
// ————— Inputs
// ———————————————————— Functions {
// ———————————————————— Calculations {
// ————— Select between historical and realtime DV calcs. In rt, use user
selection.
float totalUpVolume = nz(array.sum(upVolumes))
float totalDnVolume = nz(array.sum(dnVolumes))
float totalVolume = totalUpVolume - totalDnVolume
float maxUpVolume = nz(array.max(upVolumes))
float maxDnVolume = nz(array.min(dnVolumes))
float delta = totalUpVolume + totalDnVolume
float deltaPct = delta / totalVolume
if reset
cvd := 0
//Smoothed MA Calculation
smma1 = 0.0
smma2 = 0.0
smakj1 = ta.sma(cvdC, i_kjminlen)
smakj2 = ta.sma(cvdC, i_kjmaxlen)
smma1 := na(smma1[1]) ? smakj1 : (smma1[1] * (20 - 1) + cvdC) / 20
smma2 := na(smma2[1]) ? smakj2 : (smma2[1] * (60 - 1) + cvdC) / 60
//Kijun-Sen Calculation
kjsmma = math.avg(ta.lowest(cvdC,26), ta.highest(cvdC,26))
//Conditions
hiddenbearkj = ta.crossunder(smma1, kjsmma) and kjsmma < smma2 and cvdC < smma1
hiddenbullkj = ta.crossover(smma1, kjsmma) and kjsmma > smma2 and cvdC > smma1