Draw a straight line between two points based on start/end variables and then calculate price rate of change over the bar length of the line
Hello all, I will do my best to explain clearly what I want to do:
I want to have two conditions that define the start and end point for a straight line to be drawn. For example, start_condition could be that RSI[1] is not oversold (meaning is not below 30) and RSI[0] is oversold, and end_condition could be that RSI[1] is oversold and RSI[0] is not oversold. (This is just an example to illustrate what I mean by a start condition and an end condition for the beginning candle and the ending candle that are used for drawing the straight line.)
Suppose in this above example that RSI stays oversold for 16 minutes on a 1 minute chart. That will mean that the line’s bar length is going to be 17 bars long (since the final bar will include the bar in which RSI crosses above the oversold threshold).
In addition to the straight line drawn on the chart between the start and end points, I also want the price rate of change calculated over the 17 bars (in this example case) that constitute the length of the line.
I’m not sure if this is an easy or difficult request. It would be ideal if each subsequent drawn line and rate of change calculation did not overwrite or repaint the previous drawn line and ROC calculation, at least up to some maximum limit of something like 5 lines. To not waste overwriting one of the lines based on a set of bars that was too small to form a significant line (e.g. in our example, this would be like if the RSI was only oversold for two bars consecutively), maybe it would also be necessary to have a minimum bar length of how many bars must occur between the start and end conditions in order for them to be valid (I think this would cause some lag for plotting the line, but maybe that is fine if the intervening bar requirement is a small number).
I’m not sure about the best way to go about this and think it may be more complicated than it first seems, but maybe I’m over-complicating it. Is my explanation clear and is there a simple way to do this? Many thanks to anyone who can offer some insight.
Edit: I should clarify that I think it would also be useful for the current line that is still unfinished (meaning the start condition has been met but an end condition has not been met yet) to plot in a different color and calculate the rate of change on an ongoing basis until the end condition occurs at which point the color appears like the other lines and also the rate of change calculation becomes set in stone.
Hello all, I will do my best to explain clearly what I want to do:
I want to have two conditions that define the start and end point for a straight line to be drawn. For example, start_condition could be that RSI[1] is not oversold (meaning is not below 30) and RSI[0] is oversold, and end_condition could be that RSI[1] is oversold and RSI[0] is not oversold. (This is just an example to illustrate what I mean by a start condition and an end condition for the beginning candle and the ending candle that are used for drawing the straight line.)
Suppose in this above example that RSI stays oversold for 16 minutes on a 1 minute chart. That will mean that the line’s bar length is going to be 17 bars long (since the final bar will include the bar in which RSI crosses above the oversold threshold).
In addition to the straight line drawn on the chart between the start and end points, I also want the price rate of change calculated over the 17 bars (in this example case) that constitute the length of the line.
I’m not sure if this is an easy or difficult request. It would be ideal if each subsequent drawn line and rate of change calculation did not overwrite or repaint the previous drawn line and ROC calculation, at least up to some maximum limit of something like 5 lines. To not waste overwriting one of the lines based on a set of bars that was too small to form a significant line (e.g. in our example, this would be like if the RSI was only oversold for two bars consecutively), maybe it would also be necessary to have a minimum bar length of how many bars must occur between the start and end conditions in order for them to be valid (I think this would cause some lag for plotting the line, but maybe that is fine if the intervening bar requirement is a small number).
I’m not sure about the best way to go about this and think it may be more complicated than it first seems, but maybe I’m over-complicating it. Is my explanation clear and is there a simple way to do this? Many thanks to anyone who can offer some insight.
Edit: I should clarify that I think it would also be useful for the current line that is still unfinished (meaning the start condition has been met but an end condition has not been met yet) to plot in a different color and calculate the rate of change on an ongoing basis until the end condition occurs at which point the color appears like the other lines and also the rate of change calculation becomes set in stone.
Last edited: