Draw Vertical Line for Awesome Oscillator

rajaodu1

Member
VIP
HI @SleepyZ

As you helped to create vertical lines for MACD crossover (link for reference), can you please help me to create vertical lines for Awesome oscillator? Thanks

https://usethinkscript.com/threads/draw-vertical-line-for-macd-crossover.9318/#post-149337

1736215146529.png


Code:
declare lower;
declare zerobase;

plot ZeroLine = 0;
ZeroLine.SetDefaultColor(GetColor(5));

plot AO1 = Average(hl2, 5) - Average(hl2, 34);
AO1.SetPaintingStrategy(PaintingStrategy.LINE);
AO1.SetLineWeight(3);
AO1.AssignValueColor(if AO1 > AO1[1] then Color.GREEN else Color.RED);
 
Solution
All four category of vertical lines similar to MACD crossover vertical line

DefineGlobalColor("Above-Above", Color.GREEN);
DefineGlobalColor("Above-Below", Color.LIME);
DefineGlobalColor("Below-Below", Color.RED);
DefineGlobalColor("Below-Above", Color.PINK);

Here are directional changes, up or dn, depicted by optional labels, bubbles and/or vertical lines.
The bubbles and lines are limited to show by input limit_lines_bubbles
Code:
declare lower;
declare zerobase;

input limit_lines_bubbles = 6;

plot ZeroLine = 0;
ZeroLine.SetDefaultColor(GetColor(5));

plot AO1 = Average(hl2, 5) - Average(hl2, 34);
AO1.SetPaintingStrategy(PaintingStrategy.LINE);
AO1.SetLineWeight(3);
AO1.AssignValueColor(if AO1 >...
All four category of vertical lines similar to MACD crossover vertical line

DefineGlobalColor("Above-Above", Color.GREEN);
DefineGlobalColor("Above-Below", Color.LIME);
DefineGlobalColor("Below-Below", Color.RED);
DefineGlobalColor("Below-Above", Color.PINK);
 
All four category of vertical lines similar to MACD crossover vertical line

DefineGlobalColor("Above-Above", Color.GREEN);
DefineGlobalColor("Above-Below", Color.LIME);
DefineGlobalColor("Below-Below", Color.RED);
DefineGlobalColor("Below-Above", Color.PINK);

Here are directional changes, up or dn, depicted by optional labels, bubbles and/or vertical lines.
The bubbles and lines are limited to show by input limit_lines_bubbles
Code:
declare lower;
declare zerobase;

input limit_lines_bubbles = 6;

plot ZeroLine = 0;
ZeroLine.SetDefaultColor(GetColor(5));

plot AO1 = Average(hl2, 5) - Average(hl2, 34);
AO1.SetPaintingStrategy(PaintingStrategy.LINE);
AO1.SetLineWeight(3);
AO1.AssignValueColor(if AO1 > AO1[1] then Color.GREEN else Color.RED);

def up = AO1 > AO1[1];
def dn = AO1 < AO1[1];
def count = if BarNumber() == 1 then 0 else if !IsNaN(close) and ((dn[1] and up) or (up[1] and dn)) then count[1] + 1 else count[1];
def cond  = HighestAll(count) - count + 1;

def last_cross = if cond[1] == 2 and cond == 1 and AO1 > AO1[1] then 1 else if cond[1] == 2 and cond == 1 and AO1 < AO1[1] then 0 else last_cross[1];

DefineGlobalColor("Above-Above", Color.GREEN);
DefineGlobalColor("Below-Below", Color.RED);

input label =  yes;
AddLabel(label and last_cross == 1, "Last Direction :  UP "
, GlobalColor("Above-Above"));
AddLabel(label and last_cross == 0, "Last Direction :  DN "
, GlobalColor("Below-Below"));

input bubbles = yes;
input bubbleoffset = 3;
AddChartBubble(bubbles and cond <= limit_lines_bubbles and dn[1] and up, AO1 , "Up" , GlobalColor("Above-Above"), no);
AddChartBubble(bubbles and cond <= limit_lines_bubbles and up[1] and dn, AO1, "Dn" ,  GlobalColor("Below-Below"), yes);

input verticalline = yes;
AddVerticalLine(verticalline and cond <= limit_lines_bubbles and dn[1] and up , "", GlobalColor("Above-Above"), Curve.LONG_DASH);
AddVerticalLine(verticalline and cond <= limit_lines_bubbles and up[1] and dn, "", GlobalColor("Below-Below"), Curve.LONG_DASH);

#
 
Solution
HI @SleepyZ

Thanks. Instead of 2 category as Up and down. Can you please add 4 category as shown in the picture.
1. Up and above zero line
2. Down and above zero line
3. Up and below zero line
4. Down and below zero line

Thanks again for your support.


1736267031148.png
 
HI @SleepyZ

Thanks. Instead of 2 category as Up and down. Can you please add 4 category as shown in the picture.
1. Up and above zero line
2. Down and above zero line
3. Up and below zero line
4. Down and below zero line

Thanks again for your support.

Here you go

Code:
declare lower;
declare zerobase;

input limit_lines_bubbles = 6;

plot ZeroLine = 0;
ZeroLine.SetDefaultColor(GetColor(5));

plot AO1 = Average(hl2, 5) - Average(hl2, 34);
AO1.SetPaintingStrategy(PaintingStrategy.LINE);
AO1.SetLineWeight(3);
AO1.AssignValueColor(if AO1 > AO1[1] then Color.GREEN else Color.RED);

def up = AO1 > AO1[1];
def dn = AO1 < AO1[1];
def count = if BarNumber() == 1 then 0 else if !IsNaN(close) and ((dn[1] and up) or (up[1] and dn)) then count[1] + 1 else count[1];
def cond  = HighestAll(count) - count + 1;

def last_cross = if cond[1] == 2 and cond == 1 and AO1 > AO1[1] then 1 else if cond[1] == 2 and cond == 1 and AO1 < AO1[1] then 0 else last_cross[1];

def last_cross_ = if cond[1] == 2 and cond == 1 and AO1 > 0 then 1 else if  cond[1] == 2 and cond == 1  then 0 else last_cross_[1];

DefineGlobalColor("Above-Above", Color.GREEN);
DefineGlobalColor("Above-Below", Color.LIME);
DefineGlobalColor("Below-Below", Color.RED);
DefineGlobalColor("Below-Above", Color.PINK);


input label =  yes;
AddLabel(label and last_cross == 1, "Last Direction :  UP  when " + (if last_cross_ then  " Above 0 line" else " Below 0 line")
, if last_cross_ == 1 then GlobalColor("Above-Above") else GlobalColor("Above-Below"));
AddLabel(label and last_cross == 0, "Last Direction :  DN when " + (if last_cross_ then  " Above 0 line" else " Below 0 line")
, if last_cross_ == 0  then GlobalColor("Below-Below") else GlobalColor("Below-Above"));


input bubbles = yes;
input bubbleoffset = 3;
AddChartBubble(bubbles and cond <= limit_lines_bubbles and dn[1] and up, AO1 , "Up" , if AO1 > 0  then GlobalColor("Above-Above") else GlobalColor("Above-Below"), no);
AddChartBubble(bubbles and cond <= limit_lines_bubbles and up[1] and dn, AO1, "Dn" ,  if AO1 < 0 then GlobalColor("Below-Below") else GlobalColor("Below-Above"), yes);

input verticalline = yes;
AddVerticalLine(verticalline and cond <= limit_lines_bubbles and dn[1] and up , "", if AO1 > 0 then GlobalColor("Above-Above") else GlobalColor("Above-Below"), Curve.LONG_DASH);
AddVerticalLine(verticalline and cond <= limit_lines_bubbles and up[1] and dn, "", if AO1 < 0  then GlobalColor("Below-Below") else GlobalColor("Below-Above"), Curve.LONG_DASH);

#
 

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