# Plotting a horizontal line and subsequent breakout

#### Stockbat

##### Member
Hello Experts...

I use the following shared study ( http://tos.mx/ZM7lt1T ) on Heiken Ashi candles.
1) I want to a plot a horizontal line (about 5 bars long) at the high of the bar that is signaled by the study.
2) And then plot an arrow on the first bar that opens above that line. Ideally have only the past two occurrences of the signal and lines.

Ideally to have only past 2 of such occurrences on the chart instead of past signals.

.. pls help .. thanks!

Solution
Hello @SleepyZ,

I can get the current plot line with the use of AddLabel(yes, "Current " + data );
How can I get the label values of current and the previous plot line for data?

Ruby:
def pxcond = if xcond != xcond[1] then xcond[1] else pxcond[1];
AddLabel(yes, "Current " + AsText(xcond) + " |  Prior " + AsText(pxcond), color.white);
Hello Experts...

I use the following shared study ( http://tos.mx/ZM7lt1T ) on Heiken Ashi candles.
1) I want to a plot a horizontal line (about 5 bars long) at the high of the bar that is signaled by the study.
2) And then plot an arrow on the first bar that opens above that line. Ideally have only the past two occurrences of the signal and lines.

Ideally to have only past 2 of such occurrences on the chart instead of past signals.

.. pls help .. thanks!

Try this.. Explanations are in the code.

Code:
input maLengthOne = 2;
input maTypeOne = AverageType.EXPONENTIAL;
input maPriceOne = close;
input maLengthTwo = 6;
input maTypeTwo = AverageType.EXPONENTIAL;
input maPriceTwo = close;
def maOne = MovingAverage(maTypeOne, maPriceOne, maLengthOne);
def maTwo = MovingAverage(maTypeTwo, maPriceTwo, maLengthTwo);

def scan = low <= maTwo and close > maTwo and (close < maOne[1] or close < maOne[2] or close < maOne[3]);

input plotCount   = 2;#Hint plotcount: Number of Horizontal Lines to plot
input linelength  = 5;#Hint linelength: Max Length of Horizontal Lines

def cond          = if scan then high else Double.NaN;
def xcond         = if IsNaN(cond)
then xcond[1]
else cond; #Extend cond beyond bar where cond occurred
def linecount     = if scan then 1 else linecount[1] + 1;
def dataCount     = CompoundValue(1,
if !IsNaN(cond)
then dataCount[1] + 1
else dataCount[1], 0);

#Plot of Horizontal Lines
plot data     = if HighestAll(dataCount) - dataCount <= plotCount - 1 and linecount <= linelength
then xcond
else Double.NaN;
data.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
data.SetLineWeight(3);

#If break does not occur within the 'linelength' then break will not plot
plot break    = if high crosses above data and linecount <= linelength
then 1
else 0;
break.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
break.SetDefaultColor(Color.CYAN);
break.SetLineWeight(4);

Try this.. Explanations are in the code.
Hello @SleepyZ,

I can get the current plot line with the use of AddLabel(yes, "Current " + data );
How can I get the label values of current and the previous plot line for data?

Hello @SleepyZ,

I can get the current plot line with the use of AddLabel(yes, "Current " + data );
How can I get the label values of current and the previous plot line for data?

Ruby:
def pxcond = if xcond != xcond[1] then xcond[1] else pxcond[1];
AddLabel(yes, "Current " + AsText(xcond) + " |  Prior " + AsText(pxcond), color.white);

Thanks @SleepyZ.

I have another request, not particular to this thread but a general one.
How do I get a chartbubble/label/number counter for any signal?.

For example, if I define the 'retest' as below, how do I get the instance counter of it?. Basically to plot 1st signal, 2nd signal and so on whenever the condition is met.

I could get as far as getting the barNumber Of retest in the example code below

################################################
plot data = ExpAverage(close, 20);
plot retest = low < data and close > data and open > data;

rec barNumberOfSignal = if retest then BarNumber() else barNumberOfSignal[1];
def bago = BarNumber() - barNumberOfSignal;

################################################

Thanks!

Last edited:

87k+ Posts
293 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?