Hi,
The code below creates a linear regression trendline and two bands at 95% and 5% of the frequency distribution of the Price-Trendline difference. The line are plottable in the chart.
It works well in explorer and and dates can be changed in the date from/to in the anaysis window.
When I plot the lines in the chart, all the calulations apply to the historical time series. Is there is a short way to apply the calculation only to what I can see on the chart ?
I have read On Balance Volume Indicator - Use only the visible bars but not sure does the job I'm looking for.
It would require to modify all the formulas to
only_visible = any_indicator - FirstVisibleValue( any_indicator );
Is this the only way?
Any help would be welcome.
BI=BarIndex(); x = Cum(1);
logC=log(Close); DateN=DateNum();
pds = LastValue( x );
a = LastValue( LinRegIntercept( logC, pds) );
b = LastValue( LinRegSlope( logC, pds ) );
y = a + b * x ;
trendline= exp(y);
diff=(c-trendline)/trendline; //
Per95= EndValue( Percentile(diff,pds,95));
Per05= EndValue( Percentile(diff,pds,05));
Band95=trendline*(1+Per95);
Band05=trendline*(1+Per05);
Plot(C, "Close", colorBlack, styleline );
Plot( trendline, "TrendLine", colorBlue, styleDashed);
Plot( Band95, "95%", colorRed, styleDashed );
Plot( band05, "5%", colorRed,styleDashed );
// ==============
Filter= (Status("actionEx"));
//AddColumn(DateNum(), "date Num",1.0);
AddColumn(c,"Close",1.3);
AddColumn(trendline,"Trend Line",1.3);
AddColumn(Band95, "95%",1.3);
AddColumn(Band05, "05%",1.3);
//other
AddColumn(x,"x",1.0);
AddColumn(pds,"Periods",1.0);
AddColumn(a,"Inter",1.3);
AddColumn(b,"Slope",1.3);
AddColumn(diff,"Diff",1.3);
AddColumn(Band95, "Band95",1.3);
AddColumn(Band05, "Band05",1.3);