Static label

SJP07

Member
I would like a label that says whether the swing high or swing low was the last condition to be met. Thanks in advance.

input length_10 = 10;
def bn = BarNumber();
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length_10 - 1, lastBar - bn);
def swingLow_10 = low < Lowest(low[1], length_10 - 1) and low == GetValue(Lowest(low, length_10), -offset);


def swingHigh_10 = high > Highest(high[1], length_10 - 1) and high == GetValue(Highest(high, length_10), -offset);
# identify the very last swing high point
def highPointOneBarNumber = HighestAll(if swingHigh_10 then bn else 0);
def highPointOneValue = if bn == highPointOneBarNumber then high else highPointOneValue[1];


Plot Up = SwingLow_10;
Up.SetLineWeight(1);
Up.SetDefaultColor(Color.Orange);
#Up.SetDefaultColor(Color.Uptick);
Up.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#Up.Hide();


Plot Down = SwingHigh_10;
Down.SetLineWeight(1);
Down.SetDefaultColor(Color.Orange);
#Down.SetDefaultColor(Color.Downtick);
Down.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#Down.Hide();
 
Solution
I would like a label that says whether the swing high or swing low was the last condition to be met. Thanks in advance.

input length_10 = 10;
def bn = BarNumber();
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length_10 - 1, lastBar - bn);
def swingLow_10 = low < Lowest(low[1], length_10 - 1) and low == GetValue(Lowest(low, length_10), -offset);


def swingHigh_10 = high > Highest(high[1], length_10 - 1) and high == GetValue(Highest(high, length_10), -offset);
# identify the very last swing high point
def highPointOneBarNumber = HighestAll(if swingHigh_10 then bn else 0);
def highPointOneValue = if bn == highPointOneBarNumber then high else highPointOneValue[1];


Plot Up = SwingLow_10...
I would like a label that says whether the swing high or swing low was the last condition to be met. Thanks in advance.

input length_10 = 10;
def bn = BarNumber();
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length_10 - 1, lastBar - bn);
def swingLow_10 = low < Lowest(low[1], length_10 - 1) and low == GetValue(Lowest(low, length_10), -offset);


def swingHigh_10 = high > Highest(high[1], length_10 - 1) and high == GetValue(Highest(high, length_10), -offset);
# identify the very last swing high point
def highPointOneBarNumber = HighestAll(if swingHigh_10 then bn else 0);
def highPointOneValue = if bn == highPointOneBarNumber then high else highPointOneValue[1];


Plot Up = SwingLow_10;
Up.SetLineWeight(1);
Up.SetDefaultColor(Color.Orange);
#Up.SetDefaultColor(Color.Uptick);
Up.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#Up.Hide();


Plot Down = SwingHigh_10;
Down.SetLineWeight(1);
Down.SetDefaultColor(Color.Orange);
#Down.SetDefaultColor(Color.Downtick);
Down.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#Down.Hide();



this will display a label that lists how many bars ago was the last pivot.
the label is colored, green for high pivot, red for a low pivot.


Code:
# pivots_prev_cnt_00

#https://usethinkscript.com/threads/static-label.12692/
#UnAnswered Static label
#SJP07  Sep 16, 2022

#I would like a label that says whether the swing high or swing low was the last condition to be met. Thanks in advance.


# ref  robert payne code
#https://usethinkscript.com/threads/zigzag-high-low-with-supply-demand-zones-for-thinkorswim.172/#post-7048
#ZigZag High Low with Supply & Demand Zones for ThinkorSwim


input length_10 = 10;
def bn = BarNumber();
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length_10 - 1, lastBar - bn);
def swingLow_10 = low < Lowest(low[1], length_10 - 1) and low == GetValue(Lowest(low, length_10), -offset);


def swingHigh_10 = high > Highest(high[1], length_10 - 1) and high == GetValue(Highest(high, length_10), -offset);
# identify the very last swing high point
def highPointOneBarNumber = HighestAll(if swingHigh_10 then bn else 0);
def highPointOneValue = if bn == highPointOneBarNumber then high else highPointOneValue[1];


Plot Up = SwingLow_10;
Up.SetLineWeight(1);
Up.SetDefaultColor(Color.Orange);
#Up.SetDefaultColor(Color.Uptick);
Up.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#Up.Hide();


Plot Down = SwingHigh_10;
Down.SetLineWeight(1);
Down.SetDefaultColor(Color.Orange);
#Down.SetDefaultColor(Color.Downtick);
Down.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#Down.Hide();

# determine which pivot is most recent
# count bars since

def lobn = if swingLow_10 then bn else lobn[1];
def hibn = if SwingHigh_10 then bn else hibn[1];

def isrecent_hi = ( hibn > lobn);

def pivbarz = (bn - max(lobn, hibn));

addlabel(1,
("recent pivot was " + pivbarz + " bars ago"),
(if isrecent_hi then color.green else color.red));
#

DuAjRJo.jpg
 
Solution
Could you add an arrow and indicate the highs and lows with an arrow for the last green bar before the swing low and the last red bar before the swing high.

I have included a screenshot as a reference.

Thank you in advance!
 

Attachments

  • Screenshot 2023-08-22 at 11.46.36 PM.png
    Screenshot 2023-08-22 at 11.46.36 PM.png
    182.9 KB · Views: 41

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