Starting point of plot line

greco26

Active member
How do I not have the plot line go all the way across the chart to the left but instead start the Line from the bar's high which it is plotting? In the screenshot below, the line should start at bar # 381 and travel to the right for example. Thanks!


Code:
def H5 = High(Period = AggregationPeriod.Five_min);
def L5 = Low(Period = AggregationPeriod.Five_min);
def O5 = Open(Period = AggregationPeriod.Five_min);
def C5 = Close(Period = AggregationPeriod.Five_min);
def bn = barnumber();


def FiveLongbar =  if  H5[1] < H5[2] then H5[1] else FiveLongbar[1];
def level = if isnan(close) then level[1] else FiveLongbar[1];
plot FiveLong =  highestall(if !isnan(FiveLongbar) and isnan(FiveLongbar[-1]) then level else double.nan);

FiveLong.setpaintingStrategy(paintingStrategy.HORIZONTAL);
addchartbubble(if bn==highestall(bn-5) then FiveLongbar else double.nan, FiveLong,"5 Trigger",color.green);
addchartbubble(bn, low, bn, color.white);
 
How do I not have the plot line go all the way across the chart to the left but instead start the Line from the bar's high which it is plotting? In the screenshot below, the line should start at bar # 381 and travel to the right for example. Thanks!


Code:
def H5 = High(Period = AggregationPeriod.Five_min);
def L5 = Low(Period = AggregationPeriod.Five_min);
def O5 = Open(Period = AggregationPeriod.Five_min);
def C5 = Close(Period = AggregationPeriod.Five_min);
def bn = barnumber();


def FiveLongbar =  if  H5[1] < H5[2] then H5[1] else FiveLongbar[1];
def level = if isnan(close) then level[1] else FiveLongbar[1];
plot FiveLong =  highestall(if !isnan(FiveLongbar) and isnan(FiveLongbar[-1]) then level else double.nan);

FiveLong.setpaintingStrategy(paintingStrategy.HORIZONTAL);
addchartbubble(if bn==highestall(bn-5) then FiveLongbar else double.nan, FiveLong,"5 Trigger",color.green);
addchartbubble(bn, low, bn, color.white);

See if this helps

Ruby:
def H5 = high(Period = AggregationPeriod.FIVE_MIN);
def L5 = low(Period = AggregationPeriod.FIVE_MIN);
def O5 = open(Period = AggregationPeriod.FIVE_MIN);
def C5 = close(Period = AggregationPeriod.FIVE_MIN);
def bn = BarNumber();


def FiveLongval = if H5[1] < H5[2] then H5[1] else FiveLongval[1];
def FiveLongbar = if high == FiveLongval then bn else Double.NaN;
def level       = if bn == HighestAll(FiveLongbar) then FiveLongval else level[1];
plot FiveLong   = level;

FiveLong.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
AddChartBubble(if bn == HighestAll(bn - 5) then level else Double.NaN, FiveLong, "5 Trigger", Color.GREEN);

#Debug
AddChartBubble(bn, low, bn, Color.WHITE);
AddLabel(1, HighestAll(FiveLongbar) + " " + level);
 

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

Looks like your code has the same issue I was having. I am able to identify the correct bar however Im not able to actually plot the line for some reason. Im not sure why. Any idea?
Actually, I forgot to mention this. I'm using the 5 min agg on a 1 minute chart. I want to draw the high of the prior 5 minute bar on the 1 minute chart. Your code works on the 5 min chart but not on the 1. make sense?
 
Actually, the code below gives me what I need however I only want a line plotted for the most recent occurrence and not any of the historical ones.

Code:
def H5 = high(Period = AggregationPeriod.FIVE_MIN);
def L5 = low(Period = AggregationPeriod.FIVE_MIN);
def O5 = open(Period = AggregationPeriod.FIVE_MIN);
def C5 = close(Period = AggregationPeriod.FIVE_MIN);
def bn = BarNumber();

def FiveLongval = if H5[1] < H5[2] then H5[1] else FiveLongval[1];
def FiveLongbar = if high == FiveLongval then bn else 0;
def level = if isnan(close) then level[1] else FiveLongval[1];

plot FiveLong = level;
FiveLong.setpaintingStrategy(paintingStrategy.HORIZONTAL);
 
Actually, the code below gives me what I need however I only want a line plotted for the most recent occurrence and not any of the historical ones.

Code:
def H5 = high(Period = AggregationPeriod.FIVE_MIN);
def L5 = low(Period = AggregationPeriod.FIVE_MIN);
def O5 = open(Period = AggregationPeriod.FIVE_MIN);
def C5 = close(Period = AggregationPeriod.FIVE_MIN);
def bn = BarNumber();

def FiveLongval = if H5[1] < H5[2] then H5[1] else FiveLongval[1];
def FiveLongbar = if high == FiveLongval then bn else 0;
def level = if isnan(close) then level[1] else FiveLongval[1];

plot FiveLong = level;
FiveLong.setpaintingStrategy(paintingStrategy.HORIZONTAL);

Changing this line in my post should work. I used high instead of what you wanted of H5

Ruby:
def FiveLongbar = if H5 == FiveLongval then bn else Double.NaN;

Revised code
Code:
def H5 = high(Period = AggregationPeriod.FIVE_MIN);
def L5 = low(Period = AggregationPeriod.FIVE_MIN);
def O5 = open(Period = AggregationPeriod.FIVE_MIN);
def C5 = close(Period = AggregationPeriod.FIVE_MIN);
def bn = BarNumber();


def FiveLongval = if H5[1] < H5[2] then H5[1] else FiveLongval[1];
def FiveLongbar = if H5 == FiveLongval then bn else Double.NaN;
def level       = if bn == HighestAll(FiveLongbar) then FiveLongval else level[1];
plot FiveLong   = level;

FiveLong.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
AddChartBubble(if bn == HighestAll(bn - 5) then level else Double.NaN, FiveLong, "5 Trigger", Color.GREEN);

#Debug
#AddChartBubble(bn, low, bn, Color.WHITE);
AddLabel(1, HighestAll(FiveLongbar) + " " + level);
 
Unfortunately its still not working properly. Looks like your code is still having the same issue I was having. I was able to get it to identify a bar number and plot the line however its identifying the wrong bar number. I tried changing it to highestall(fivelongbar) and it doesn't work either. Its good to see I tried the same things you are though. It makes me feel like I was heading down the right path. :) Let m know if. you have any other ideas!
 
Unfortunately its still not working properly. Looks like your code is still having the same issue I was having. I was able to get it to identify a bar number and plot the line however its identifying the wrong bar number. I tried changing it to highestall(fivelongbar) and it doesn't work either. Its good to see I tried the same things you are though. It makes me feel like I was heading down the right path. :) Let m know if. you have any other ideas!

See if this works. In both charts the line starts plotting on the bar following the condition being met. On the 1min chart though, the high is within the 5 bars preceding the start of the line there.

Capture.jpg
Ruby:
def H5 = high(Period = AggregationPeriod.FIVE_MIN);
def L5 = low(Period = AggregationPeriod.FIVE_MIN);
def O5 = open(Period = AggregationPeriod.FIVE_MIN);
def C5 = close(Period = AggregationPeriod.FIVE_MIN);
def bn = BarNumber();

def FiveLongval = if H5[1] < H5[2]
                  then H5[1]
                  else FiveLongval[1];
def FiveLongbar = if IsNaN(close)
                  then FiveLongbar[1]
                  else if FiveLongval[1] != FiveLongval
                  then FiveLongbar[1] + 1
                  else FiveLongbar[1];
def level       = if IsNaN(close)
                  then level[1]
                  else FiveLongval;

plot FiveLong   = if FiveLongbar >= HighestAll(FiveLongbar)
                  then level
                  else Double.NaN;
FiveLong.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FiveLong.SetLineWeight(5);

AddChartBubble(if bn == HighestAll(bn - 5) then level else Double.NaN, FiveLong, "5 Trigger", Color.GREEN);
 
@SleepyZ, question for you. In the code below, 'backlow' is not identifying the correct bar. In this sample screenshot, I added bar numbers to easily point them out to you. Bar # 778 is the the condition called frontlow and that is working fine. The backlow condition is saying the following; 1) find a bar older than frontlow bn and 2) the bar's low must be greater than the low of frontlow and 3) if conditions 1 and 2 are true, then find the bar that has the lowest low (but low must be above the low of frontlow).


Code:
def bn = BarNumber();

def fronthigh = if high[1] > high[2] and high < high[1] then high[1] else fronthigh[1];
def fronthighBN = if high[1] == fronthigh then bn - 1 else fronthighBN[1];
def backhigh = if bn < HighestAll(fronthighBN) and high < fronthigh then Highest(high) else backhigh[1];
def backhighBN = if high == backhigh then bn else backhighBN[1];


def frontlow = if low[1] < low[2] and low > low[1] then low[1] else frontlow[1];
def frontlowBN = if low[1] == frontlow then bn-1  else frontlowBN[1];
def backlow = if  bn < HighestAll(frontlowBN) and low > frontlow then lowest(low) else backlow[1];
def backlowBN = if low == backlow then bn else backlowBN[1];



AddChartBubble(backlow, backlow, backlow);

AddChartBubble(bn, low, bn, Color.PINK);

AddLabel(1, backlow, Color.WHITE);
 
@SleepyZ, question for you. In the code below, 'backlow' is not identifying the correct bar. In this sample screenshot, I added bar numbers to easily point them out to you. Bar # 778 is the the condition called frontlow and that is working fine. The backlow condition is saying the following; 1) find a bar older than frontlow bn and 2) the bar's low must be greater than the low of frontlow and 3) if conditions 1 and 2 are true, then find the bar that has the lowest low (but low must be above the low of frontlow).


Code:
def bn = BarNumber();

def fronthigh = if high[1] > high[2] and high < high[1] then high[1] else fronthigh[1];
def fronthighBN = if high[1] == fronthigh then bn - 1 else fronthighBN[1];
def backhigh = if bn < HighestAll(fronthighBN) and high < fronthigh then Highest(high) else backhigh[1];
def backhighBN = if high == backhigh then bn else backhighBN[1];


def frontlow = if low[1] < low[2] and low > low[1] then low[1] else frontlow[1];
def frontlowBN = if low[1] == frontlow then bn-1  else frontlowBN[1];
def backlow = if  bn < HighestAll(frontlowBN) and low > frontlow then lowest(low) else backlow[1];
def backlowBN = if low == backlow then bn else backlowBN[1];



AddChartBubble(backlow, backlow, backlow);

AddChartBubble(bn, low, bn, Color.PINK);

AddLabel(1, backlow, Color.WHITE);

See if the use of the snippet to identify the range of bars between frontlowbn helps. Once that is defined then your conditions were used to find the lowest low. Only the last frontlowbn points preceding lowest low if plotted. Arrows represent frontlowbn. The image has debug set to yes.

Capture.jpg
Ruby:
def bn = BarNumber();

def fronthigh = if high[1] > high[2] and high < high[1] then high[1] else fronthigh[1];
def fronthighBN = if high[1] == fronthigh then bn - 1 else fronthighBN[1];
def backhigh = if bn < HighestAll(fronthighBN) and high < fronthigh then Highest(high) else backhigh[1];
def backhighBN = if high == backhigh then bn else backhighBN[1];


def frontlow = if low[1] < low[2] and low > low[1] then low[1] else frontlow[1];
def frontlowBN = if low[1] == frontlow then bn - 1  else frontlowBN[1];

#Identify bars between frontlowbn points
def fl = frontlowBN;
def ok = !IsNaN(close);
def capture = ok and fl != fl[1];
def Count = CompoundValue(1, if capture then Count[1] + 1 else Count[1], 0);
def thislow = (HighestAll(Count) - Count) + 1;

#Find the lowest low above frontlow in the bars between frontlowbn points   
def low1 = if thislow[1] <= 3 and thislow == 2 and low > frontlow then low else if thislow == 2 then Min(low, low1[1]) else low1[1];
 #This extends the low1 to the right edge
def low2 = if IsNaN(close) then low2[1] else if thislow == 2 and bn < HighestAll(frontlowBN) then low1 else low2[1];
 #This identifies the backlowbn to start plot of backlow from it
def backlowbn = if low == low2 then bn else Double.NaN;

plot backlow = if bn < HighestAll(backlowbn) then Double.NaN else low2;
DefineGlobalColor("Back", Color.RED);
backlow.SetLineWeight(2);
backlow.SetDefaultColor(GlobalColor("Back"));

#Debug
input debug = yes;
plot frontlobn = if debug then thislow != thislow[-1] else Double.NaN;
frontlobn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
AddChartBubble(debug and backlow, backlow, backlow);
 
I'm going to have to study your code and play around with it. amazing as always so thank you!. What im actually trying to do is identify and (eventually) plot a line from the front low to the historical closest low above the frontlow. it could be 1 bar behind the front low or 30 bars behind. it will obviously vary.

 
yea, I can't figure it out. I really like your code and there is something else I will use it for but I dont think it will work for this. I've been messing around with it for 1.5 hours. I just can't make the code find the right bar. if frontlow is true, then look left and find the lowest value slightly above the frontlow. I tried if low > front low, then lowest(low) but I guess its not going to get me that bar I need. I need to identify the bar that has a historical low closest in value to the frontlow. if you have any ideas, let me know, thank you!!
 
I just can't make the code find the right bar. if frontlow is true, then look left and find the lowest value slightly above the frontlow. ... I need to identify the bar that has a historical low closest in value to the frontlow.

Since your code already calculates frontLow, you just need to compare frontLow[0] to the prior recent frontLow values.

It appears that you want to target the prior frontLow[1-6] that is higher than your current frontLow, but the lowest of the prior front Low[1-6] (EDIT: 1-6 is just an example here, I 've no idea what your lookback period would be.)

I think that you can do this, if you define your lookback period [how many frontLows back are you comparing? if you go back far enough, you may find a low that more closely matches, but it may not be contextual to recent price action].

EDIT2: On second look, this is very similar to what @SleepyZ already provided. I see an issue with my code, it needs to compare the low values of the bars. , so you need something like this:

Combined with the below, you just need to grab the bar numbers of the frontLow bars, however which looks already defined in code above.

Code:
def frontLowValue = if frontLow then low, else frontLowValue[1];

# This should define the lowestFrontLowValue:
input lookback = 7; #how far back are you  comparing FrontLow?
def lowestFrontLowValue = Lowest(FrontLowValue, lookback);

# This should set your prior FrontLow. If the current frontLow is the lowest, then just pick the next-most-recent-value for lowestFrontLow.
def priorFrontLowValue = if frontLowValue == lowestFrontLowValue then lowestFrontLowValue[1] else LowestFrontLowValue;
 
Last edited:

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
330 Online
Create Post

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