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?

Thanks in advance!

Add this to the bottom of your code

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.

Capture.jpg
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);
 

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

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?

Thanks in advance!

Add this to the bottom of your code

Ruby:
def pxcond = if xcond != xcond[1] then xcond[1] else pxcond[1];
AddLabel(yes, "Current " + AsText(xcond) + " |  Prior " + AsText(pxcond), color.white);
 
Solution
Add this to the bottom of your code
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;

AddLabel(yes, "Ago" + bago );
################################################

Thanks!
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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