Add multiple lines and bubbles to chart


Category:
0
0

Hello,

I am wanting to add different lines and bubbles to the chart that match different levels of % change from the previous days close.  An example would be one line at 15% down from the previous days close and another at 17% from the previous days close.  I would like to have them be different colors as well.

If possible, have a list of 5 possible lines and user input for the percent change and color, and if nothing is picked, then no line would be displayed.

Thank you

Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on April 16, 2022 4:23 pm
93 views
0
Private answer

The lines you requested were provided in the previous post I found using the search function:

https://www.hahn-tech.com/ans/plot-line-on-intraday-at-percentage-of-previous-day-close/

So all we need to do is add the chart bubbles. Given my example, you can work out how to add whoever many lines and chart bubbles you want to display.

Here is the code from the solution I linked above:

input plusPercent = 20.0;
input minusPercent= 20.0;
def prevDailyClose = close(period = AggregationPeriod.DAY)[1];
plot upper = prevDailyClose * (1 + (plusPercent * 0.01));
plot lower = prevDailyClose * (1 - (minusPercent * 0.01));

To add the chart bubbles to this we must first assume that you intended to place those chart bubbles on the last bar of the chart.

Here is the new section of code which adds the chart bubbles to the last bar of each of the lines plotted on the chart:

input plusPercent = 20.0;
input minusPercent= 20.0;
def prevDailyClose = close(period = AggregationPeriod.DAY)[1];
plot upper = prevDailyClose * (1 + (plusPercent * 0.01));
plot lower = prevDailyClose * (1 - (minusPercent * 0.01));
def lastBar = IsNaN(close[-1]) and !IsNaN(close);
AddChartBubble(lastBar, upper, upper, upper.TakeValueColor(), yes);
AddChartBubble(lastBar, lower, lower, lower.TakeValueColor(), no);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on April 16, 2022 6:02 pm