Missing plot

JVE

New member
I am trying to write a simple indicator that automatically draws the midpoint for either the previous bar or the current bar. I see the correct plot bubble, but no plot. What am I missing / doing wrong? TIA for the help!

# Automatically draws the midpoint for either the previous bar or the current bar
#declare once_per_bar;

input Mode = {default Current, Previous};

def barNumber = barNumber();
def mostRecentBarIndex = HighestAll(if(close > 0, barNumber(), Double.NaN));

def plotBarNumber;
def barOpen;
def barHigh;
def barLow;
def barClose;

# Please pick only one approach at a time in order to avoid compiler errors...

# Approach 1: displays OHLC in the label for Current and Previous and the plot bubble for each, but no plot!

if(barNumber == mostRecentBarIndex)
{
switch (Mode)
{
case Current:
plotBarNumber = barNumber;
barOpen = open;
barHigh = high;
barLow = low;
barClose = close;

case Previous:
plotBarNumber = barNumber - 1;
barOpen = open[1];
barHigh = high[1];
barLow = low[1];
barClose = close[1];
}
}
else
{
plotBarNumber = Double.NaN;
barOpen = Double.NaN;
barHigh = Double.NaN;
barLow = Double.NaN;
barClose = Double.NaN;
}

# Approach 2: displays OHLC in the label for Current but not Previous (as expected) and the plot bubble for each, but no plot!

if(((Mode == Mode.Current) AND (barNumber == mostRecentBarIndex)) OR ((Mode == Mode.Previous) AND (barNumber == mostRecentBarIndex - 1)))
{
plotBarNumber = barNumber;
barOpen = open;
barHigh = high;
barLow = low;
barClose = close;
}
else
{
plotBarNumber = Double.NaN;
barOpen = Double.NaN;
barHigh = Double.NaN;
barLow = Double.NaN;
barClose = Double.NaN;
}

Plot mid = (barHigh + barLow) / 2;
mid.AssignValueColor(Color.Cyan);
mid.SetLineWeight(2);
mid.SetPaintingStrategy(PaintingStrategy.LINE);
mid.SetStyle(Curve.MEDIUM_DASH);

AddLabel(yes, "Mode: " + Mode + ", mostRecentBarIndex: " + mostRecentBarIndex + ", barNumber: " + barNumber + ", plotBarNumber: " + plotBarNumber + ", barOpen: " + barOpen + ", barHigh: " + barHigh + ", barLow: " + barLow + ", barClose: " + barClose + ", mid: " + mid, Color.LIGHT_GREEN);
 
Solution
I only skimmed it, but on first glance it looks like the issue is that PaintingStrategy.LINE requires two points to make a line.

Try PaintingStrategy.horizontal
I only skimmed it, but on first glance it looks like the issue is that PaintingStrategy.LINE requires two points to make a line.

Try PaintingStrategy.horizontal
 
  • Like
Reactions: JVE
Solution

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
398 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