I made a minor adjustment to the example to have it plot a new linear regression whenever the zigzaghighlow example changes direction. This was done with
Rich (BB code):
def cond = BarNumber() == max(highestall(signaldown), HighestAll(signalrevbot));
I get the gist of the script, not sure how the max of the highestall of both signals is the last barnumber, if it isn't measured by close etc.
I think the channel width should be a dynamic number for the stdev away from the mean (mid) both high and low, and that's something I'm always measuring in any regression periods. The barnumber is something I'd like it to track automatically to back when it happens, and I am assuming this 'cond' isn't that. However, it's a nice start to learn from.
Think Highest Arrow on the Chart and Lowest Arrow on the chart, however many days/bars back that is.
input showpivot = yes;
def highvar1 = HighestAll(var1);
rec highestvar1 = if var == highvar1 and var1[1] < var1[1] then high(period = Agg) else highestvar1[1];
plot highestVar1Point = if ShowPivot and highestvar1 <> 0 then highestvar1 else Double.NaN;
#plot same as low mark using lowest.
same for var2, var3 etc. all custom variables. They plot across the chart until replaced by similiar auto-calc.
Say 5d 5m chart etc. And for Var2 or Var3 etc their might be many many data plots in between all the bars, and measure all the data plots as they occur in that dataset, between said bars.
I was using inertia of those variables to grab the data for the channel in stdev and mean and calculate bar(nubmer) and entering length manuually to right of chart, instead of calculating barsback automatically (can't pass variables, constants only) - and plot it. But I cannot define a beginning and end automatically - starting at highest and stopping at lowest for example would be great (not running until the right of the chart unless I chose 'extendright' = on etc.
So a total of 6 lines will plot. I want to pick the beginning of each line as the starting point for the regression channel, either by Input/Switch or just automatically.
it seems to me you would have cond and cond1
Rich (BB code):
def cond = BarNumber() == max(highestall(signaldown), HighestAll(signalrevbot));
def cond1 = BarNumber() == min(lowestall(signaldown), lowestAll(signalrevbot));
and have 2 plot statements to begin or terminate at either of the two 'conditions', either having two slopes calculated.
Or even if it ran to the right of the chart from the last known selected condition (highest, lowest) of var1, var2, var3 etc. as we really want to preserve the slope of the dynamic stdev/mean of the latest dataset from set condition as the chart unfolds.
It kind of reminds me of Limbo by Mobius - am I far off?
# Calculations for line between extremes
def line = b + (slope * (barnumber - lownumber));
def linelow = a + (slopelow * (barnumber - highnumber));
def currentlinelow = if barnumber <= lownumberall
then linelow
else Double.NaN;
def currentline = if barnumber <= highnumberall
then line
else Double.NaN;
def FibFan = if downward
then currentlinelow
else if upward
then currentline
else Double.NaN;
.....