Awesome Oscillator + The Zone for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
ab6lJ4X.png

Author message: [My add is the bar color and option to change the fast and slow length :)]
The Zone is mention in New Trading Dimensions by Bill Williams , PhD .
The Zone is used for Entry Signal
Green Zone are painting Green when Awesome Oscillator (AO) and Accelerater/Decelerator ( AC ) are both increasing.
Red Zone are painting Red when Awesome Oscillator (AO) and Accelerater/Decelerator ( AC ) are both decreasing.
Gray Zone are painting Gray when AO and AC in difference changing

Gray Zone are indicate the indecision between bulls and bears.
Bill Williams , PhD . mention that Green Zone or Red Zone usually happen 6-8 bars Continuously.
(in my opinion, it happen lower than in intraday time frame)

The First Bar that change to be Green or Red color is the Signal Bar.
Entry Signal is the second bar in the same color as the Signal bar happen with Volume
Price go higher the high of previous Green Bar is Buy Signal. Entry Buy (Long) and place Stop at 1 tick lower the Low of previous bar.
Price go lower the Low of previous Red Bars is Sell Signal. Entry Sell (Short) and place Stop at 1 tick higher the High of previous bar.
Can Entry from 2nd bar to 5th bar.
Do not Entry if Green Bars or Red Bars completed 5 bars continuously.
This indicator have AO , AC and Zone in 1 tools and there are counter to show the number of Green bar or Red bar.
Green counter will happen when AO >0 and Green zone because AO > 0 show uptrend condition.
Red Counter will happen when AO < 0 and Red Zone because AO <0 show downtrend condition.
When we entry , we should follow the trend. So I design to non-show the counter if zone is against the trend.
#WaveRiders
Code:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0
#// Copyright by © WaveRiders
#https://www.tradingview.com/script/axNQ0vK4/
#// Awesome Oscillator + The Zone
#study(title="AO-Zone" , shorttitle = "AOZ")
# Converted and mod by Sam4Cok@Samer800 - 10/2022
declare lower;
input ShowCounter = yes;
input BarColor = no;
input FastPeriod = 5;
Input SlowPeriod = 34;

def zG;
def zR;

def na = Double.NaN;
#//calculate AO, AC
def ao = SimpleMovingAvg(hl2, FastPeriod) - SimpleMovingAvg(hl2, SlowPeriod);
def ac = ao - SimpleMovingAvg(ao, FastPeriod);

#//Green Zone , Red Zone and Gray Zone
def GreenZone = ao > ao[1] and ac > ac[1];
def RedZone   = ao < ao[1] and ac < ac[1];

#//Plot AO
plot Accelerater = ac;    # color = change(ac) <= 0 ? #ffb330 : #1ccaff
Accelerater.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
Accelerater.AssignValueColor(if ac <= ac[1] then CreateColor(255,255,0)
            else CreateColor(0,221,255));
Accelerater.SetLineWeight(2);

plot Awesome = ao;       # color = change(ao) <= 0 ? #872323 : #007F0E
Awesome.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Awesome.AssignValueColor(if ao <= ao[1] then CreateColor(135,35,35)
            else CreateColor(0,127,14));
#Awesome.AssignValueColor(if ao > 0 then if ao > ao[1] then Color.GREEN else Color.DARK_GREEN
#                     else if ao < ao[1] then Color.RED else Color.DARK_RED);

#//Fill Zone Background
AddCloud(if isNaN(close) then na else Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY,CreateColor(42,42,42));

AddCloud(if GreenZone then Double.POSITIVE_INFINITY else
         if RedZone then Double.NEGATIVE_INFINITY else na,
         if GreenZone then Double.NEGATIVE_INFINITY else Double.POSITIVE_INFINITY,
             Color.DARK_GREEN, Color.DARK_RED);

#//Zone counter
if ao > ao[1] and ac > ac[1]
then {
    zG = zG[1] + 1;
    zR = 0;
} else
if ao < ao[1] and ac < ac[1]
then {
    zG = 0;
    zR = zR[1] + 1;
} else {
    zG = 0;
    zR = 0;
}
AddLabel(ShowCounter and GreenZone and ao > 0,"Count(" + zG + ")", Color.GREEN);
AddLabel(ShowCounter and RedZone and ao < 0, "Count(" + zR + ")", CreateColor(247,82,95));

def GZone11 = if GreenZone and ao>0 then zG == 1 else na;#, title ='GZone1',
def GZone22 = if GreenZone and ao>0 then zG == 2 else na;#, title ='GZone1',
def GZone33 = if GreenZone and ao>0 then zG == 3 else na;#, title ='GZone1',
def GZone44 = if GreenZone and ao>0 then zG == 4 else na;#, title ='GZone1',
def GZone55 = if GreenZone and ao>0 then zG == 5 else na;#, title ='GZone1',

plot GZone1 = if GZone11 then 2 else na;
plot GZone2 = if GZone22 then 2 else na;
plot GZone3 = if GZone33 then 2 else na;
plot GZone4 = if GZone44 then 2 else na;
plot GZone5 = if GZone55 then 2 else na;
GZone1.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
GZone2.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
GZone3.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
GZone4.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
GZone5.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
GZone1.SetDefaultColor(Color.GREEN);
GZone2.SetDefaultColor(Color.GREEN);
GZone3.SetDefaultColor(Color.GREEN);
GZone4.SetDefaultColor(Color.GREEN);
GZone5.SetDefaultColor(Color.GREEN);

def RZone11 = if RedZone and ao<0 then zR == 1 else na;#, title ='RZone1',
def RZone22 = if RedZone and ao<0 then zR == 2 else na;#, title ='RZone1',
def RZone33 = if RedZone and ao<0 then zR == 3 else na;#, title ='RZone1',
def RZone44 = if RedZone and ao<0 then zR == 4 else na;#, title ='RZone1',
def RZone55 = if RedZone and ao<0 then zR == 5 else na;#, title ='RZone1',

plot RZone1 = if RZone11 then -2 else na;
plot RZone2 = if RZone22 then -2 else na;
plot RZone3 = if RZone33 then -2 else na;
plot RZone4 = if RZone44 then -2 else na;
plot RZone5 = if RZone55 then -2 else na;
RZone1.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
RZone2.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
RZone3.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
RZone4.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
RZone5.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
RZone1.SetDefaultColor(Color.RED);
RZone2.SetDefaultColor(Color.RED);
RZone3.SetDefaultColor(Color.RED);
RZone4.SetDefaultColor(Color.RED);
RZone5.SetDefaultColor(Color.RED);
#---- Bar Color
def color = if ao>ao[1] and ac>ac[1] then 2 else
            if ao>ao[1] and ac<=ac[1] then 1 else
            if ao<=ao[1] and ac<=ac[1] then -2 else
            if ao<=ao[1] and ac>ac[1] then -1 else 0;
AssignPriceColor(if !BarColor then Color.CURRENT else
                 if color==2 then Color.GREEN else
                 if color==1 then Color.DARK_GREEN else
                 if color==-2 then Color.RED else
                 if color==-1 then Color.DARK_RED else Color.GRAY);
#---- END
 
Last edited by a moderator:
Hi @samer800 I just tried this script on 5 min (left) and 1 min (right) and the histogram is very small, how do I fix this? Thanks in advance!
 

Attachments

  • awesome error.PNG
    awesome error.PNG
    34.6 KB · Views: 14
Hi @samer800 I just tried this script on 5 min (left) and 1 min (right) and the histogram is very small, how do I fix this? Thanks in advance!
try the below:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0
#// Copyright by © WaveRiders
#https://www.tradingview.com/script/axNQ0vK4/
#// Awesome Oscillator + The Zone
#study(title="AO-Zone" , shorttitle = "AOZ")
# Converted and mod by Sam4Cok@Samer800 - 10/2022
declare lower;

input ShowCounter = yes;
input BarColor = no;
input FastPeriod = 5;
Input SlowPeriod = 34;

def zG;
def zR;

def na = Double.NaN;
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
#//calculate AO, AC
def ao = SimpleMovingAvg(hl2, FastPeriod) - SimpleMovingAvg(hl2, SlowPeriod);
def ac = ao - SimpleMovingAvg(ao, FastPeriod);

#//Green Zone , Red Zone and Gray Zone
def GreenZone = ao > ao[1] and ac > ac[1];
def RedZone   = ao < ao[1] and ac < ac[1];
#//Zone counter
if ao > ao[1] and ac > ac[1]
then {
    zG = zG[1] + 1;
    zR = 0;
} else
if ao < ao[1] and ac < ac[1]
then {
    zG = 0;
    zR = zR[1] + 1;
} else {
    zG = 0;
    zR = 0;
}
#-- LEvels
def sumUp = if ao > 0 then sumUp[1] + ao else sumUp[1];
def cntUp = if ao > 0 then cntUp[1] + 1 else cntUp[1];
def avgUp = if cntUp !=0 then (sumUp / cntUp / 4) else 0;
def sumDn = if ao < 0 then sumDn[1] - ao else sumDn[1];
def cntDn = if ao < 0 then cntDn[1] + 1 else cntDn[1];
def avgDn = if cntDn !=0 then (sumDn / cntDn / 4) else 0;

def GZone11 = if GreenZone and ao>0 then zG == 1 else na;#, title ='GZone1',
def GZone22 = if GreenZone and ao>0 then zG == 2 else na;#, title ='GZone1',
def GZone33 = if GreenZone and ao>0 then zG == 3 else na;#, title ='GZone1',
def GZone44 = if GreenZone and ao>0 then zG == 4 else na;#, title ='GZone1',
def GZone55 = if GreenZone and ao>0 then zG == 5 else na;#, title ='GZone1',

plot GZone1 = if GZone11 then ao + avgUp else na;
plot GZone2 = if GZone22 then ao + avgUp else na;
plot GZone3 = if GZone33 then ao + avgUp else na;
plot GZone4 = if GZone44 then ao + avgUp else na;
plot GZone5 = if GZone55 then ao + avgUp else na;
GZone1.SetPaintingStrategy(PaintingStrategy.SQUARES);
GZone2.SetPaintingStrategy(PaintingStrategy.SQUARES);
GZone3.SetPaintingStrategy(PaintingStrategy.SQUARES);
GZone4.SetPaintingStrategy(PaintingStrategy.SQUARES);
GZone5.SetPaintingStrategy(PaintingStrategy.SQUARES);
GZone1.SetDefaultColor(Color.GREEN);
GZone2.SetDefaultColor(Color.GREEN);
GZone3.SetDefaultColor(Color.GREEN);
GZone4.SetDefaultColor(Color.GREEN);
GZone5.SetDefaultColor(Color.GREEN);

def RZone11 = if RedZone and ao<0 then zR == 1 else na;#, title ='RZone1',
def RZone22 = if RedZone and ao<0 then zR == 2 else na;#, title ='RZone1',
def RZone33 = if RedZone and ao<0 then zR == 3 else na;#, title ='RZone1',
def RZone44 = if RedZone and ao<0 then zR == 4 else na;#, title ='RZone1',
def RZone55 = if RedZone and ao<0 then zR == 5 else na;#, title ='RZone1',

plot RZone1 = if RZone11 then ao - avgDn else na;
plot RZone2 = if RZone22 then ao - avgDn else na;
plot RZone3 = if RZone33 then ao - avgDn else na;
plot RZone4 = if RZone44 then ao - avgDn else na;
plot RZone5 = if RZone55 then ao - avgDn else na;
RZone1.SetPaintingStrategy(PaintingStrategy.SQUARES);
RZone2.SetPaintingStrategy(PaintingStrategy.SQUARES);
RZone3.SetPaintingStrategy(PaintingStrategy.SQUARES);
RZone4.SetPaintingStrategy(PaintingStrategy.SQUARES);
RZone5.SetPaintingStrategy(PaintingStrategy.SQUARES);
RZone1.SetDefaultColor(Color.RED);
RZone2.SetDefaultColor(Color.RED);
RZone3.SetDefaultColor(Color.RED);
RZone4.SetDefaultColor(Color.RED);
RZone5.SetDefaultColor(Color.RED);
#//Plot AO
plot Accelerater = ac;
Accelerater.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
Accelerater.AssignValueColor(if ac <= ac[1] then Color.YELLOW else Color.CYAN);
Accelerater.SetLineWeight(2);

plot Awesome = ao;
Awesome.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Awesome.AssignValueColor(if ao <= ao[1] then CreateColor(135,35,35) else CreateColor(0,127,14));

#//Fill Zone Background
AddCloud(if isNaN(close) then na else Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY,CreateColor(42,42,42));

AddCloud(if GreenZone then pos else
         if RedZone then neg else na,
         if GreenZone then neg else pos, Color.DARK_GREEN, Color.DARK_RED);


AddLabel(ShowCounter and GreenZone and ao > 0,"Count(" + zG + ")", Color.GREEN);
AddLabel(ShowCounter and RedZone and ao < 0, "Count(" + zR + ")", CreateColor(247,82,95));


#---- Bar Color
def color = if ao>ao[1] and ac>ac[1] then 2 else
            if ao>ao[1] and ac<=ac[1] then 1 else
            if ao<=ao[1] and ac<=ac[1] then -2 else
            if ao<=ao[1] and ac>ac[1] then -1 else 0;
AssignPriceColor(if !BarColor then Color.CURRENT else
                 if color==2 then Color.GREEN else
                 if color==1 then Color.DARK_GREEN else
                 if color==-2 then Color.RED else
                 if color==-1 then Color.DARK_RED else Color.GRAY);
#---- END
 

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