you didn't answer my questions, so i still don't know what you are trying to do, so it's hard to steer you in the right direction.
my guess is you want to draw a new line for each quarter period, so you need a way to reset the line to some new start price, bar, time,...
here is a study that may help
...identifies the first bar of a time period , yellow arrow
...finds the lowest low during some 2nd agg period ( default is day), red arrow
...draws yellow diagonal lines, each one starting from the lowest low of the period
problems,
...if there are 2+ bars with the same low, may not plot correctly
...by using a price for the slope increment, when looking at stocks priced near $1, the lines will appear vertical.
for more consistent lines, on many stocks, may want to use a percentage of the stock price, as the slope increment.
there is a bubble line commented out. i use them to display variable values, to help debug scripts.
Ruby:
# test2_period
def na = double.nan;
def bn = barnumber();
input agg = AggregationPeriod.DAY;
def cls = close(period = agg);
# without the check for bn == 1, it errors and is always 1.
# because on bar 1, it tries to read a previous bar value, and there isn't one.
def periodstart = if bn == 1 then 0 else if ( cls[1] == cls ) then 0 else 1;
# when the bar is the last bar in a period, it will be different than the next
def periodend = if bn == 1 then 0 else if ( cls[0] == cls[-1] ) then 0 else 1;
plot z = periodstart;
z.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down);
z.SetDefaultColor(Color.yellow);
#addchartbubble(1,low, cls[1] + "\n" + cls + "\n" + periodstart , color.cyan, no);
# start a line on the lowest price durign an agg period
def lowday = (low(period = agg));
# look for the bar with the low
def lowz =
if periodend then na
else if low == lowday then low
else lowz[1];
# look for the barnumber of the low
def lowzbn =
if periodend then na
else if low == lowday then bn
else lowzbn[1];
input slope = 0.5;
plot diag = lowz + (( bn - lowzbn)* slope);
diag.SetDefaultColor(Color.yellow);
diag.SetStyle(Curve.MEDIUM_DASH);
plot w = ( lowzbn == bn );
w.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_up);
w.SetDefaultColor(Color.red);
#
#