RangeBound1
New member
Hello,
#====Main Issue====#
I want to identify a range high/low then compare every candle after that to those values.
If there is a close outside of the high/low, the drawing ends.
If there is a new high/low, but the candle closes within the prev high/low of the range, expand the drawing to include the new high/low.
I don't have a way to store the high/low value and compare them. The best I could find was https://stackoverflow.com/questions/56518594/how-to-create-a-variable-that-retains-its-value , but nothing seems to make sense.
I do not want to use a Highest/Lowest (high/low, input), as I want to compare to the previous range instead of manually entering a lookback value.
Thank you in advance for any assistance you can provide on this.
#====Summary of Project====#
Here is what I am trying to accomplish:
I hope the image works. If not, here is the web link .
The concept is to determine when candles are in a range, mark the high and low of the range as a horizontal line.
As the chart progresses, expand the drawing.
If a new candle breaks the high or low, but closes within the range, redraw the range to include the new high or low.
Paint candles that close within the range as grey (discretionary), paint candles that close outside of the range as blue (discretionary).
Example, a range is created with a high of 10.00 and a low of 9.75.
The next candle made a new high of 10.05 but closed at 10.00, within the range.
The range should be redrawn to include the high of 10.05.
The new redrawn range will then be 10.05 to 9.75.
If a candle closes outside of the marked range, it is considered a trending candle. The drawing then ceases until the next range is formed.
The definitions are as follows:
A range begins when 1 bar closes within the high and low of the previous.
The range high is initiated as the highest value of the current bar and previous.
The range low is initiated as the lowest value of the current bar and previous.
The range ends when a bar closes outside of the range high or low.
If a bar makes a new high above the range, but closes within, the range expands to include the new high and the current candle is considered part of the range.
(and vice versa for the low)
#====Current Code====#
Here is the code I have so far, along with an image of its current display.
#====Main Issue====#
I want to identify a range high/low then compare every candle after that to those values.
If there is a close outside of the high/low, the drawing ends.
If there is a new high/low, but the candle closes within the prev high/low of the range, expand the drawing to include the new high/low.
I don't have a way to store the high/low value and compare them. The best I could find was https://stackoverflow.com/questions/56518594/how-to-create-a-variable-that-retains-its-value , but nothing seems to make sense.
I do not want to use a Highest/Lowest (high/low, input), as I want to compare to the previous range instead of manually entering a lookback value.
Thank you in advance for any assistance you can provide on this.
#====Summary of Project====#
Here is what I am trying to accomplish:
I hope the image works. If not, here is the web link .
The concept is to determine when candles are in a range, mark the high and low of the range as a horizontal line.
As the chart progresses, expand the drawing.
If a new candle breaks the high or low, but closes within the range, redraw the range to include the new high or low.
Paint candles that close within the range as grey (discretionary), paint candles that close outside of the range as blue (discretionary).
Example, a range is created with a high of 10.00 and a low of 9.75.
The next candle made a new high of 10.05 but closed at 10.00, within the range.
The range should be redrawn to include the high of 10.05.
The new redrawn range will then be 10.05 to 9.75.
If a candle closes outside of the marked range, it is considered a trending candle. The drawing then ceases until the next range is formed.
The definitions are as follows:
A range begins when 1 bar closes within the high and low of the previous.
The range high is initiated as the highest value of the current bar and previous.
The range low is initiated as the lowest value of the current bar and previous.
The range ends when a bar closes outside of the range high or low.
If a bar makes a new high above the range, but closes within, the range expands to include the new high and the current candle is considered part of the range.
(and vice versa for the low)
#====Current Code====#
Here is the code I have so far, along with an image of its current display.
Rich (BB code):
#========
plot insidebar = close < high[1] and close > low[1];
plot trendbar = !insidebar;
AssignPriceColor(if insidebar then Color.RED else Color.BLUE);
plot prevbarinside = close[1] < high[2] and close[1] > low[2];
plot testlow;
plot testhigh;
if (insidebar is true and prevbarinside is false)
{
testlow = lowest(low,2);
testhigh = highest(high,2);
}
else
{
testlow = double.NaN;
testhigh = double.NaN;
}
testlow.setPaintingStrategy(paintingStrategy.HORIZONTAL);
testlow.setDefaultColor(color.WHITE);
testhigh.setPaintingStrategy(paintingStrategy.HORIZONTAL);
testhigh.setDefaultColor(color.WHITE);
Last edited: