How to add a cloud to the range of an inside bar.


Category:
0
0

Hey Pete, what i’m trying to basically do is add a clouds to my chart, green cloud for a green bar and red cloud for a red bar.  I want this cloud to stretch from that bar to the right of every inside bar.  I was able to make the script to determine and inside bar, but I’m not sure how to put the cloud like I want.

 

def lo = low;
def hi = high;
def vo = volume;

def s = if hi[1] > hi and lo[1] < low then 1 else 0;
plot insideCandle = s;
insideCandle.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
insideCandle.SetLineWeight(3);
insideCandle.AssignValueColor(Color.WHITE);

 

Attached is how I would like the chart to look but I don’t know how to make a cloud that is the

Attachments:
Marked as spam
Posted by (Questions: 10, Answers: 15)
Asked on July 5, 2020 5:27 pm
186 views
0
Private answer

The basic premise of your question has already been posted and solved in the forum, on two occasions:

https://www.hahn-tech.com/ans/plot-high-and-low-of-previous-inside-bar/

https://www.hahn-tech.com/ans/plot-horizontal-line-across-previous-days-high-low-for-inside-bars/

If you had searched for this solution before posting this question you would have located both of those posts already. Then you might have copied the link from the second post and included that code and link in your request. Because the code from that post does everything you have requested, with the exception of the cloud.

So you start with the code provided in the second link I included above. You only need to add a single line to add a cloud to the high and low plotted from that solution. Details about how to write the line of code that adds the cloud is found here:

https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/AddCloud

Here is the full and complete code, taking the code from the previous solution and adding the one line of code that adds the cloud to the chart:

def insideBar = high < high[1] and low > low[1];
AssignPriceColor(if insideBar then Color.WHITE else Color.CURRENT);
plot insideHigh = if insideBar then high else if insideBar[1] then high[1] else Double.NaN;
insideHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
insideHigh.SetDefaultColor(Color.CYAN);
insideHigh.SetLineWeight(3);
plot insideLow = if insideBar then low else if insideBar[1] then low[1] else Double.NaN;
insideLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
insideLow.SetDefaultColor(Color.MAGENTA);
insideLow.SetLineWeight(3);
AddCloud(insideHigh, insideLow, Color.GRAY, Color.BLACK);

Why do people do this?

def lo = low;
def hi = high;
def vo = volume;

What is the point? I see this all the time and there is absolutely no good reason to do this. So stop it.

And why did you create a variable name of "s"? What does "s" stand for? What is wrong with spelling it out? Why do I see so many people writing such rotten code?

Check this out. You can replace 5 lines of code from your original source and replace it with a single line:

plot insideBar = high[1] > high and low[1] < low;

Done. See how much easier that code is to write? See how much easier it is to read?

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on July 5, 2020 6:27 pm