Horizontal lines not extending past candle

godzilla74

New member
I'm trying to get horizontal lines to extend all the way to the right of a chart on certain candles where the high/low range has exceeded the previous candle (These are labeled as '3' on my chart and are painted yellow). It plots the high/low of the candle (again, in yellow) but doesn't extend to the right as I would expect it to based on the numerous posts I've read in this forum. The desired effect would be a bunch of yellow lines that extend all the way to the right of the chart

Can someone help or at least identify what I've missed in the code?

Ruby:
# Find all outside bars and change their fill color to yellow
rec outsideBar = if high > high[1] and low < low[1] then 1 else 0;
plot ThreeBar = outsideBar;

# Use the upcolor and downcolor variables to fill the candles
AssignPriceColor(if ThreeBar then color.Yellow else color.CURRENT);


# Find the high and low of the most recent outside bar
def outsideBarHigh = if ThreeBar then high else Double.NaN;
def outsideBarLow = if ThreeBar then low else Double.NaN;

# Add horizontal lines to the chart
plot OutsideBarHighLine = outsideBarHigh;
plot OutsideBarLowLine = outsideBarLow;

OutsideBarHighLine.SetDefaultColor(color.YELLOW);
OutsideBarLowLine.SetDefaultColor(color.YELLOW);
OutsideBarHighLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
OutsideBarLowLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


JSM8jC6.png
 
I'm trying to get horizontal lines to extend all the way to the right of a chart on certain candles where the high/low range has exceeded the previous candle (These are labeled as '3' on my chart and are painted yellow). It plots the high/low of the candle (again, in yellow) but doesn't extend to the right as I would expect it to based on the numerous posts I've read in this forum. The desired effect would be a bunch of yellow lines that extend all the way to the right of the chart

Can someone help or at least identify what I've missed in the code?

Ruby:
# Find all outside bars and change their fill color to yellow
rec outsideBar = if high > high[1] and low < low[1] then 1 else 0;
plot ThreeBar = outsideBar;

# Use the upcolor and downcolor variables to fill the candles
AssignPriceColor(if ThreeBar then color.Yellow else color.CURRENT);


# Find the high and low of the most recent outside bar
def outsideBarHigh = if ThreeBar then high else Double.NaN;
def outsideBarLow = if ThreeBar then low else Double.NaN;

# Add horizontal lines to the chart
plot OutsideBarHighLine = outsideBarHigh;
plot OutsideBarLowLine = outsideBarLow;

OutsideBarHighLine.SetDefaultColor(color.YELLOW);
OutsideBarLowLine.SetDefaultColor(color.YELLOW);
OutsideBarHighLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
OutsideBarLowLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


JSM8jC6.png
You are instructing the yellow line to disappear by setting it to NaN in the definition:

def outsideBarHigh = if ThreeBar then high else Double.NaN;

You can change your to code to keep the variable until the next ThreeBar like so:

def outsideBarHigh = if ThreeBar then high else outsideBarHigh[1];

If you want each line to extend all the way, you need to introduce more variables to store them. Something like:

def outsideBarHighLast = if ThreeBar then outsideBarHigh[1] else outsideBarHighLast[1];

That should get you pointed in the right direction. Good luck!
 
I'm trying to get horizontal lines to extend all the way to the right of a chart on certain candles where the high/low range has exceeded the previous candle (These are labeled as '3' on my chart and are painted yellow). It plots the high/low of the candle (again, in yellow) but doesn't extend to the right as I would expect it to based on the numerous posts I've read in this forum. The desired effect would be a bunch of yellow lines that extend all the way to the right of the chart

Can someone help or at least identify what I've missed in the code?

Ruby:
# Find all outside bars and change their fill color to yellow
rec outsideBar = if high > high[1] and low < low[1] then 1 else 0;
plot ThreeBar = outsideBar;

# Use the upcolor and downcolor variables to fill the candles
AssignPriceColor(if ThreeBar then color.Yellow else color.CURRENT);


# Find the high and low of the most recent outside bar
def outsideBarHigh = if ThreeBar then high else Double.NaN;
def outsideBarLow = if ThreeBar then low else Double.NaN;

# Add horizontal lines to the chart
plot OutsideBarHighLine = outsideBarHigh;
plot OutsideBarLowLine = outsideBarLow;

OutsideBarHighLine.SetDefaultColor(color.YELLOW);
OutsideBarLowLine.SetDefaultColor(color.YELLOW);
OutsideBarHighLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
OutsideBarLowLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


JSM8jC6.png

TOS allows only individual plots to be extended to the right edge. The following script function OS does that.

You can create more plots using the logic of the 5 used in the code. You can limit how many of these plots to be displayed at the input named display.

Screenshot-2023-01-03-121456.png
Ruby:
#OutsideBars_Script_ExtPlots
script OS {

    input count = 0;

    def na = Double.NaN;
    def bn = BarNumber();
# Find all outside bars and change their fill color to yellow
    rec outsideBar = high > high[1] and low < low[1];
    plot ThreeBar  = outsideBar;

    rec dataCount = CompoundValue(1, if ThreeBar then dataCount[1] + 1 else dataCount[1], 0);
    def dc        = HighestAll(dataCount) - dataCount == count;

# Find the high and low of the most recent outside bar
    def outsideBarHigh   = if ThreeBar and dc then high else outsideBarHigh[1];
    def outsideBarLow    = if ThreeBar and dc then low else outsideBarLow[1];
    def outsideBarHighbn = HighestAll(if ThreeBar and dc
                           then bn
                           else na);
    def outsideBarLowbn  = HighestAll(if ThreeBar and dc
                           then bn
                           else na);


# Add horizontal lines to the chart
    plot OutsideBarHighLine = if bn >= outsideBarHighbn
                              then HighestAll(outsideBarHigh) else na;
    plot OutsideBarLowLine  = if bn >= outsideBarLowbn
                              then HighestAll(outsideBarLow) else na;



}

# Find all outside bars and change their fill color to yellow
def na = Double.NaN;
rec outsideBar = if high > high[1] and low < low[1] then 1 else 0;

# Use the upcolor and downcolor variables to fill the candles
AssignPriceColor(if outsideBar then Color.YELLOW else Color.CURRENT);

input display = 1;
plot OsH0 = if display  > 0 then os(0).OutsideBarHighLine else na;
plot OsL0 = if display  > 0 then os(0).OutsideBarLowLine else na;
OsH0.SetDefaultColor(Color.YELLOW);
OsL0.SetDefaultColor(Color.YELLOW);
OsH0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
OsL0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


plot OsH1 = if display  > 1 then os(1).OutsideBarHighLine else na;
plot OsL1 = if display  > 1 then os(1).OutsideBarLowLine else na;
OsH1.SetDefaultColor(Color.YELLOW);
OsL1.SetDefaultColor(Color.YELLOW);
OsH1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
OsL1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot OsH2 = if display  > 2 then os(2).OutsideBarHighLine else na;
plot OsL2 = if display  > 2 then os(2).OutsideBarLowLine else na;
OsH2.SetDefaultColor(Color.YELLOW);
OsL2.SetDefaultColor(Color.YELLOW);
OsH2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
OsL2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot OsH3 = if display  > 3 then os(3).OutsideBarHighLine else na;
plot OsL3 = if display  > 3 then os(3).OutsideBarLowLine else na;
OsH3.SetDefaultColor(Color.YELLOW);
OsL3.SetDefaultColor(Color.YELLOW);
OsH3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
OsL3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot OsH4 = if display > 4 then os(4).OutsideBarHighLine else na;
plot OsL4 = if display > 4 then os(4).OutsideBarLowLine else na;
OsH4.SetDefaultColor(Color.YELLOW);
OsL4.SetDefaultColor(Color.YELLOW);
OsH4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
OsL4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
You are instructing the yellow line to disappear by setting it to NaN in the definition:

def outsideBarHigh = if ThreeBar then high else Double.NaN;

You can change your to code to keep the variable until the next ThreeBar like so:

def outsideBarHigh = if ThreeBar then high else outsideBarHigh[1];

If you want each line to extend all the way, you need to introduce more variables to store them. Something like:

def outsideBarHighLast = if ThreeBar then outsideBarHigh[1] else outsideBarHighLast[1];

That should get you pointed in the right direction. Good luck!
Of course it was something simple! Thanks!
 
TOS allows only individual plots to be extended to the right edge. The following script function OS does that.

You can create more plots using the logic of the 5 used in the code. You can limit how many of these plots to be displayed at the input named display.
I like this idea! So, create something like a loop to create the OsHx plots to make this dynamic for a user?
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
603 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