Trouble Plotting Standard Deviation from Different Time Frame


New member
Still learning here it seems.

I have the standard deviation code, I just want to plot the middle regression line off the 4H chart on another Time Frame.

It's still drawing the line of the time frame I am currently in.

Can someone point out where I went astray?

Eventually I gong to input other deviations and time frames but need to get this one first. I took out the other inputs to try and simplify the code.

input length = 21;
input agg = aggregationPeriod.FOUR_HOURS;

def price = close(period = agg);

def regression;
def stdDeviation;
if (fullRange) {
    regression = InertiaAll(price);
    stdDeviation = stdevAll(price);
} else {
    regression = InertiaAll(price, length);
    stdDeviation = stdevAll(price, length);

plot MiddleLine = regression;


Well-known member
It seems to work for me. I set the aggregation at 1 hour, and the length at 60 on a 3 minute chart. That gives me the last three hours plotted. If I set the length to 65, I still only get the last 3 hours. When I set it to 90 I get four hours. This makes sense to me in a way.

Cool idea.

Happy Trading

Similar threads