Dynamic Cloud for ORB

C4men

Member
OK I feel like this should be a much simpler solve than it has proved to be. Need help.

I have a working ORB indicator that plots 3 lines:
  • plot Range_High = Range_Top;
  • plot Range_Low = Range_Below;
  • plot Range_Mid = (Range_High + Range_Low)/2;

I want to create a cloud that dynamically changes colors based on price action, using the lines/plots above.

1. NO cloud color until price closes above or below the opening range
2. Find the first break of the opening range

3a. If this first break of ORB is a break of the range low, then the cloud is RED and the cloud is painted between the MID and the LOW
3b. The cloud would stay RED until there is a close above the range high - then the cloud would switch to green (but still using the MID and LOW)

4a. If the first break of the ORB is a break of the range high, then the cloud is GREEN and the cloud is painted between the MID and the HIGH
4b. The cloud would stay GREEN until there is a close below the range low - then the cloud would switch to RED (but still using the MID and HIGH)

For the life of me, I cannot figure this out.
I've tried if/then statements in my addcloud, two separate addcloud, etc.

But I am doing something wrong and would love some help.

But I'm clueless at this point on adding "conditional/dynamic" cloud using AddCloud (or multiple AddCloud)

Code:
#------ Inputs for ORB plots
input PeriodStartTime = 0930;
input PeriodEndTime = 0939;

#------ Definitions for ORB plots
def Range_Top = if SecondsFromTime(PeriodEndTime) >= 0 then Range_Top[1] else
if SecondsFromTime(PeriodStartTime) == 0 then high else
if SecondsFromTime(PeriodStartTime) < 0 then Double.NaN else
if SecondsFromTime(PeriodStartTime) > 0 and SecondsFromTime(PeriodEndTime) <= 0
and high > Range_Top[1] then high else Range_Top[1];

def Range_Below = if SecondsFromTime(PeriodEndTime) >= 0 then Range_Below[1] else
if SecondsFromTime(PeriodStartTime) == 0 then low else
if SecondsFromTime(PeriodStartTime) < 0 then Double.NaN else
if SecondsFromTime(PeriodStartTime) > 0 and SecondsFromTime(PeriodEndTime) <= 0
and low < Range_Below[1] then low else Range_Below[1];

plot Range_High = Range_Top;
plot Range_Low = Range_Below;
plot Range_Mid = (Range_High + Range_Low)/2;
 
Last edited by a moderator:
Solution
@C4men

Ruby:
#------ Inputs for ORB plots
input PeriodStartTime = 0930;
input PeriodEndTime = 0939;

#------ Definitions for ORB plots
def Range_Top = if SecondsFromTime(PeriodEndTime) >= 0 then Range_Top[1] else
if SecondsFromTime(PeriodStartTime) == 0 then high else
if SecondsFromTime(PeriodStartTime) < 0 then Double.NaN else
if SecondsFromTime(PeriodStartTime) > 0 and SecondsFromTime(PeriodEndTime) <= 0
and high > Range_Top[1] then high else Range_Top[1];

def Range_Below = if SecondsFromTime(PeriodEndTime) >= 0 then Range_Below[1] else
if SecondsFromTime(PeriodStartTime) == 0 then low else
if SecondsFromTime(PeriodStartTime) < 0 then Double.NaN else
if SecondsFromTime(PeriodStartTime) > 0 and...

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

@C4men

Ruby:
#------ Inputs for ORB plots
input PeriodStartTime = 0930;
input PeriodEndTime = 0939;

#------ Definitions for ORB plots
def Range_Top = if SecondsFromTime(PeriodEndTime) >= 0 then Range_Top[1] else
if SecondsFromTime(PeriodStartTime) == 0 then high else
if SecondsFromTime(PeriodStartTime) < 0 then Double.NaN else
if SecondsFromTime(PeriodStartTime) > 0 and SecondsFromTime(PeriodEndTime) <= 0
and high > Range_Top[1] then high else Range_Top[1];

def Range_Below = if SecondsFromTime(PeriodEndTime) >= 0 then Range_Below[1] else
if SecondsFromTime(PeriodStartTime) == 0 then low else
if SecondsFromTime(PeriodStartTime) < 0 then Double.NaN else
if SecondsFromTime(PeriodStartTime) > 0 and SecondsFromTime(PeriodEndTime) <= 0
and low < Range_Below[1] then low else Range_Below[1];

plot Range_High = Range_Top;
plot Range_Low = Range_Below;
plot Range_Mid = (Range_High + Range_Low) / 2;

def start = SecondsTillTime(PeriodStartTime) == 0;
def CC = if start then 0
else if Crosses(close, Range_High, CrossingDirection.ABOVE) and CC[1] == 0 then 1
else if Crosses(close, Range_Low, CrossingDirection.BELOW) and CC[1] == 0 then 2
else if Crosses(close, Range_Low, CrossingDirection.BELOW) and CC[1] == 1 then 3 
else if Crosses(close, Range_High, CrossingDirection.ABOVE) and CC[1] == 2 then 4
else CC[1];

plot CCP = CC;
CCP.Hide();

AddCloud(if CCP == 1 then Range_High else Double.NEGATIVE_INFINITY,  if CCP == 1 then Range_Mid else Double.NEGATIVE_INFINITY, Color.GREEN);
AddCloud(if CCP == 3 then Range_High else Double.NEGATIVE_INFINITY,  if CCP == 3 then Range_Mid else Double.NEGATIVE_INFINITY, Color.RED);

AddCloud(if CCP == 2 then Range_Mid else Double.NEGATIVE_INFINITY,  if CCP == 2 then Range_Low else
Double.NEGATIVE_INFINITY, Color.RED);
AddCloud(if CCP == 4 then Range_Mid else Double.NEGATIVE_INFINITY,  if CCP == 4 then Range_Low else
Double.NEGATIVE_INFINITY, Color.GREEN);
 
Solution
@C4men

Ruby:
#------ Inputs for ORB plots
input PeriodStartTime = 0930;
input PeriodEndTime = 0939;

#------ Definitions for ORB plots
def Range_Top = if SecondsFromTime(PeriodEndTime) >= 0 then Range_Top[1] else
if SecondsFromTime(PeriodStartTime) == 0 then high else
if SecondsFromTime(PeriodStartTime) < 0 then Double.NaN else
if SecondsFromTime(PeriodStartTime) > 0 and SecondsFromTime(PeriodEndTime) <= 0
and high > Range_Top[1] then high else Range_Top[1];

def Range_Below = if SecondsFromTime(PeriodEndTime) >= 0 then Range_Below[1] else
if SecondsFromTime(PeriodStartTime) == 0 then low else
if SecondsFromTime(PeriodStartTime) < 0 then Double.NaN else
if SecondsFromTime(PeriodStartTime) > 0 and SecondsFromTime(PeriodEndTime) <= 0
and low < Range_Below[1] then low else Range_Below[1];

plot Range_High = Range_Top;
plot Range_Low = Range_Below;
plot Range_Mid = (Range_High + Range_Low) / 2;

def start = SecondsTillTime(PeriodStartTime) == 0;
def CC = if start then 0
else if Crosses(close, Range_High, CrossingDirection.ABOVE) and CC[1] == 0 then 1
else if Crosses(close, Range_Low, CrossingDirection.BELOW) and CC[1] == 0 then 2
else if Crosses(close, Range_Low, CrossingDirection.BELOW) and CC[1] == 1 then 3
else if Crosses(close, Range_High, CrossingDirection.ABOVE) and CC[1] == 2 then 4
else CC[1];

plot CCP = CC;
CCP.Hide();

AddCloud(if CCP == 1 then Range_High else Double.NEGATIVE_INFINITY,  if CCP == 1 then Range_Mid else Double.NEGATIVE_INFINITY, Color.GREEN);
AddCloud(if CCP == 3 then Range_High else Double.NEGATIVE_INFINITY,  if CCP == 3 then Range_Mid else Double.NEGATIVE_INFINITY, Color.RED);

AddCloud(if CCP == 2 then Range_Mid else Double.NEGATIVE_INFINITY,  if CCP == 2 then Range_Low else
Double.NEGATIVE_INFINITY, Color.RED);
AddCloud(if CCP == 4 then Range_Mid else Double.NEGATIVE_INFINITY,  if CCP == 4 then Range_Low else
Double.NEGATIVE_INFINITY, Color.GREEN);

Holy crap you beautiful genius!!!

Thanks so very much!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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