Why does volume break the plot?

JVE

New member
On SPX, I can plot high/low of the current symbol, hard-coded numbers, high/low of a different symbol, but when I try to plot the volume of a different symbol, suddenly the plots don't render. Why not?? The debug chart bubble has the proper values for the plots, so there's nothing wrong with the values, and if I add this study to an AAPL chart, it also renders correctly.

def nan = Double.NaN;

#plot VAbove = if(close >= open, high, nan);
#plot VAbove = if(close >= open, 1, nan);
#plot VAbove = if(close >= open, high("MSFT"), nan);
plot VAbove = if(close >= open, volume("MSFT"), nan);
VAbove.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

#plot VBelow = if(close < open, low, nan);
#plot VBelow = if(close < open, 0, nan);
#plot VBelow = if(close < open, low("MSFT"), nan);
plot VBelow = if(close < open, volume("MSFT"), nan);
VBelow.SetPaintingStrategy(PaintingStrategy.VALUES_Below);

AddChartBubble(1, high, "Debug - " + "VAbove: " + VAbove + ", VBelow: " + VBelow);
 
Solution
On SPX, I can plot high/low of the current symbol, hard-coded numbers, high/low of a different symbol, but when I try to plot the volume of a different symbol, suddenly the plots don't render. Why not?? The debug chart bubble has the proper values for the plots, so there's nothing wrong with the values, and if I add this study to an AAPL chart, it also renders correctly.

def nan = Double.NaN;

#plot VAbove = if(close >= open, high, nan);
#plot VAbove = if(close >= open, 1, nan);
#plot VAbove = if(close >= open, high("MSFT"), nan);
plot VAbove = if(close >= open, volume("MSFT"), nan);
VAbove.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

#plot VBelow = if(close < open, low, nan);
#plot VBelow = if(close < open, 0, nan)...
On SPX, I can plot high/low of the current symbol, hard-coded numbers, high/low of a different symbol, but when I try to plot the volume of a different symbol, suddenly the plots don't render. Why not?? The debug chart bubble has the proper values for the plots, so there's nothing wrong with the values, and if I add this study to an AAPL chart, it also renders correctly.

def nan = Double.NaN;

#plot VAbove = if(close >= open, high, nan);
#plot VAbove = if(close >= open, 1, nan);
#plot VAbove = if(close >= open, high("MSFT"), nan);
plot VAbove = if(close >= open, volume("MSFT"), nan);
VAbove.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

#plot VBelow = if(close < open, low, nan);
#plot VBelow = if(close < open, 0, nan);
#plot VBelow = if(close < open, low("MSFT"), nan);
plot VBelow = if(close < open, volume("MSFT"), nan);
VBelow.SetPaintingStrategy(PaintingStrategy.VALUES_Below);

AddChartBubble(1, high, "Debug - " + "VAbove: " + VAbove + ", VBelow: " + VBelow);

SPX is an index, it doesn't have volume.
because of that, it must be affect the reading of volume from other symbols.
try /ES or SPY
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

SPX is an index, it doesn't have volume.
because of that, it must be affect the reading of volume from other symbols.
try /ES or SPY
Thanks halcyonguy, but the volume is actually read correctly and can be printed out in a ChartBubble. It's only the plot that's broken. I think I will file a bug with TOS on this one.
 
Thanks halcyonguy, but the volume is actually read correctly and can be printed out in a ChartBubble. It's only the plot that's broken. I think I will file a bug with TOS on this one.

This is not what you wanted, but may be of interest using the dataprofile function. This is using price selected at input data, as a profile.

Here it is on SPX using HL2 as the basis.

Screenshot-2022-10-18-114542.png
Ruby:
input Data  = close;
input pricePerRowHeightMode = { default AUTOMATIC, TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input timePerProfile = { CHART, MINUTE, HOUR, default DAY, WEEK, MONTH, "OPT EXP", BAR};
input multiplier = 1;
input onExpansion = no;
input profiles = 3;
input showPointOfControl = yes;
input showValueArea = no;
input valueAreaPercent = 70;
input opacity = 100;

def period;
def yyyymmdd = GetYYYYMMDD();
def seconds = SecondsFromTime(0);
def month = GetYear() * 12 + GetMonth();
def day_number = DaysFromDate(First(yyyymmdd)) + GetDayOfWeek(First(yyyymmdd));
def dom = GetDayOfMonth(yyyymmdd);
def dow = GetDayOfWeek(yyyymmdd - dom + 1);
def expthismonth = (if dow > 5 then 27 else 20) - dow;
def exp_opt = month + (dom > expthismonth);
switch (timePerProfile) {
case CHART:
    period = 0;
case MINUTE:
    period = Floor(seconds / 60 + day_number * 24 * 60);
case HOUR:
    period = Floor(seconds / 3600 + day_number * 24);
case DAY:
    period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
case WEEK:
    period = Floor(day_number / 7);
case MONTH:
    period = Floor(month - First(month));
case "OPT EXP":
    period = exp_opt - First(exp_opt);
case BAR:
    period = BarNumber() - 1;
}

def count = CompoundValue(1, if period != period[1] then (count[1] + period - period[1]) % multiplier else count[1], 0);
def cond = count < count[1] + period - period[1];
def height;
switch (pricePerRowHeightMode) {
case AUTOMATIC:
    height = PricePerRow.AUTOMATIC;
case TICKSIZE:
    height = PricePerRow.TICKSIZE;
case CUSTOM:
    height = customRowHeight;
}

profile datatype = DataProfile("data" = Data, "startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
def con = CompoundValue(1, onExpansion, no);
def pc = if IsNaN(datatype.GetPointOfControl()) and con then pc[1] else datatype.GetPointOfControl();
def hVA = if IsNaN(datatype.GetHighestValueArea()) and con then hVA[1] else datatype.GetHighestValueArea();
def lVA = if IsNaN(datatype.GetLowestValueArea()) and con then lVA[1] else datatype.GetLowestValueArea();

def hProfile = if IsNaN(datatype.GetHighest()) and con then hProfile[1] else datatype.GetHighest();
def lProfile = if IsNaN(datatype.GetLowest()) and con then lProfile[1] else datatype.GetLowest();
def plotsDomain = IsNaN(close) == onExpansion;

plot POC = if plotsDomain then pc else Double.NaN;
plot ProfileHigh = if plotsDomain then hProfile else Double.NaN;
plot ProfileLow = if plotsDomain then lProfile else Double.NaN;
plot VAHigh = if plotsDomain then hVA else Double.NaN;
plot VALow = if plotsDomain then lVA else Double.NaN;

DefineGlobalColor("Profile", Color.LIGHT_RED);
DefineGlobalColor("Point Of Control", GetColor(5));
DefineGlobalColor("Value Area", GetColor(8));

datatype.Show(GlobalColor("Profile"), if showPointOfControl then GlobalColor("Point Of Control") else Color.CURRENT, if showValueArea then GlobalColor("Value Area") else Color.CURRENT);
POC.SetDefaultColor(GlobalColor("Point Of Control"));
POC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VALow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh.SetDefaultColor(GlobalColor("Value Area"));
VALow.SetDefaultColor(GlobalColor("Value Area"));
ProfileHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileHigh.SetDefaultColor(GetColor(3));
ProfileLow.SetDefaultColor(GetColor(3));
ProfileHigh.Hide();
ProfileLow.Hide();
 
Thanks halcyonguy, but the volume is actually read correctly and can be printed out in a ChartBubble. It's only the plot that's broken. I think I will file a bug with TOS on this one.

Here is a workaround for a bare bones addition of volume displayed on SPX. This uses the SPY chart with the price subgraph hidden and volume showing. The addchart() is placed in the lower pane set for SPX. Here is a link to the chart. https://tos.mx/fL0FBVm

Screenshot-2022-10-19-083933.png

Ruby:
input sym = "SPX";
input charttype = ChartType.CANDLE;
def oPart = open(symbol = sym);
def hPart = high(symbol = sym);
def lPart = low(symbol = sym);
def cPart = close(symbol = sym);

def o1 = if oPart < cPart then oPart else Double.NaN;
def c1 = if oPart < cPart then cPart else Double.NaN;
def h1 = if oPart < cPart then hPart else Double.NaN;
def l1 = if oPart < cPart then lPart else Double.NaN;

AddChart(growColor = Color.GREEN, fallColor = Color.RED, neutralColor = Color.GRAY, high = h1, low = l1, open = c1, close = o1, type = charttype);

def o = if oPart >= cPart then oPart else Double.NaN;
def h = hPart;
def l = lPart;
def c = if oPart >= cPart then cPart else Double.NaN;
AddChart(growColor = CreateColor(153, 0, 0), fallColor = Color.GREEN, neutralColor = Color.GRAY, high = h, low = l, open = o, close = c, type = charttype);
 
Here is a workaround for a bare bones addition of volume displayed on SPX. This uses the SPY chart with the price subgraph hidden and volume showing. The addchart() is placed in the lower pane set for SPX. Here is a link to the chart. https://tos.mx/fL0FBVm

Here is the SPX workaround with SPY volume and an example indicator, ParabolicSAR added. Expansion area turned off as SPX doesn't use. http://tos.mx/y9rhJIf ... Give the link a few seconds to load.

 
Last edited:
Here is a workaround for a bare bones addition of volume displayed on SPX. This uses the SPY chart with the price subgraph hidden and volume showing. The addchart() is placed in the lower pane set for SPX. Here is a link to the chart. https://tos.mx/fL0FBVm

It seems my first attempt to respond didn't go through. Thank you for the idea, SleepyZ! I don't see AddChart documented on https://tlc.thinkorswim.com/center/reference/thinkScript. Where can I learn more about it?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
399 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

How do I get started?

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.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top