Plot midpoint of previous daily high to low range


Category:
0
0

Hi Pete.  TOS has the chart study of DailyHighLow.  I would like to amend the script to also include the midpoint of the previous bar.  I have attached the script I attempted to create. Please let me know if this is something you can help with. Thank You!

Marked as spam
Posted by (Questions: 19, Answers: 18)
Asked on September 26, 2024 1:52 pm
12 views
0
Private answer

The solution is probably much simpler than you realize. The data is already there. All you have to do insert the mathematical formula to compute the mid point of the range.

Which is basically like this:

DailyLow + (DailyHigh - DailyLow) / 2

Here is the full solution, which has been adapted from the source code you provided:

input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;
plot DailyHigh;
plot DailyLow;
plot midpoint;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
DailyHigh = Double.NaN;
DailyLow = Double.NaN;
midpoint = Double.NaN;
} else {
DailyHigh = Highest(high(period = aggregationPeriod)[-displace], length);
DailyLow = Lowest(low(period = aggregationPeriod)[-displace], length);
midPoint = DailyLow + (DailyHigh - DailyLow) / 2;
}
DailyHigh.SetDefaultColor(GetColor(4));
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetDefaultColor(GetColor(4));
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
midpoint.SetDefaultColor(GetColor(4));
midpoint.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

Marked as spam
Posted by (Questions: 37, Answers: 4116)
Answered on September 26, 2024 1:59 pm