Below is the EFS for a LinRegCurve. It basically draws the mean/center LinReg for a given period.
The standard LinRegLine EFS draws an upper and lower line based on a varriable standard deviation input.
What I would like to add to the below EFS is an upper and lower curve based on a varriable standard deviation input and like the LinRegLines I'd like to be able to select curve thickness and color and have the option to remove the mean/center curve.
In effect what would be created is a curved channel + & - some StdDev based on the mean/center LinRegCurve.
I can use the wizard but this requires Editor talent that I do not have. I hope someone will find this modification usefull enough to post a revised EFS. Thanks in advance.
/************************************************** *****************
* Description : This Indicator plots the Linear Regression Curve
*
************************************************** ******************/
//Global Variables
var bInitialized = false;
function preMain()
{
setPriceStudy(true);
setStudyTitle("Linear Regression Curve");
setCursorLabelName("LR Curve");
// Number of Bars before signal is cancelled
var fp1 = new FunctionParameter( "frLength", FunctionParameter.NUMBER);
fp1.setName( "Length" );
fp1.setLowerLimit(0);
fp1.setDefault(20);
//Line thickness
var fp2 = new FunctionParameter( "LineThickness", FunctionParameter.NUMBER);
fp2.setName( "Line thickness" );
fp2.setLowerLimit( 1 );
fp2.setUpperLimit( 10 );
fp2.setDefault( 2 );
// Filter on Mean Swing Line
var fp3 = new FunctionParameter("LineColor", FunctionParameter.COLOR);
fp3.setName( "LineColor" );
fp3.setDefault(Color.navy);
// end of formula paramaters
}
function main(frLength,LineThickness,LineColor)
{
var len = frLength;
var vPrice = getValue("Close", 0, -len);
var Num1 = 0.0;
var Num2 = 0.0;
var SumBars = len * (len - 1) * 0.5;
var SumSqrBars = (len - 1) * len * (2 * len - 1) / 6;
var SumY = 0.0;
var Sum1 = 0.0;
var Sum2 = 0.0;
var Slope = 0.0;
var Intercept = 0.0;
var i = 0;
//script is initializing
if ( getBarState() == BARSTATE_ALLBARS ) {
return null;
}
//initialize once-only paramaters
if ( bInitialized == false ) {
setDefaultBarFgColor( LineColor, 0 );
setDefaultBarThickness( Math.round( LineThickness ), 0 );
bInitialized = true;
}
for (i = 0; i < len; i++)
{
SumY += vPrice[i];
Sum1 += i * vPrice[i];
}
Sum2 = SumBars * SumY;
Num1 = len * Sum1 - Sum2;
Num2 = SumBars * SumBars - len * SumSqrBars;
if (Num2 != 0) Slope = Num1 / Num2;
Intercept = (SumY - Slope * SumBars) / len;
var LinearRegValue = Intercept + Slope * (len - 1 );
return LinearRegValue;
}
The standard LinRegLine EFS draws an upper and lower line based on a varriable standard deviation input.
What I would like to add to the below EFS is an upper and lower curve based on a varriable standard deviation input and like the LinRegLines I'd like to be able to select curve thickness and color and have the option to remove the mean/center curve.
In effect what would be created is a curved channel + & - some StdDev based on the mean/center LinRegCurve.
I can use the wizard but this requires Editor talent that I do not have. I hope someone will find this modification usefull enough to post a revised EFS. Thanks in advance.
/************************************************** *****************
* Description : This Indicator plots the Linear Regression Curve
*
************************************************** ******************/
//Global Variables
var bInitialized = false;
function preMain()
{
setPriceStudy(true);
setStudyTitle("Linear Regression Curve");
setCursorLabelName("LR Curve");
// Number of Bars before signal is cancelled
var fp1 = new FunctionParameter( "frLength", FunctionParameter.NUMBER);
fp1.setName( "Length" );
fp1.setLowerLimit(0);
fp1.setDefault(20);
//Line thickness
var fp2 = new FunctionParameter( "LineThickness", FunctionParameter.NUMBER);
fp2.setName( "Line thickness" );
fp2.setLowerLimit( 1 );
fp2.setUpperLimit( 10 );
fp2.setDefault( 2 );
// Filter on Mean Swing Line
var fp3 = new FunctionParameter("LineColor", FunctionParameter.COLOR);
fp3.setName( "LineColor" );
fp3.setDefault(Color.navy);
// end of formula paramaters
}
function main(frLength,LineThickness,LineColor)
{
var len = frLength;
var vPrice = getValue("Close", 0, -len);
var Num1 = 0.0;
var Num2 = 0.0;
var SumBars = len * (len - 1) * 0.5;
var SumSqrBars = (len - 1) * len * (2 * len - 1) / 6;
var SumY = 0.0;
var Sum1 = 0.0;
var Sum2 = 0.0;
var Slope = 0.0;
var Intercept = 0.0;
var i = 0;
//script is initializing
if ( getBarState() == BARSTATE_ALLBARS ) {
return null;
}
//initialize once-only paramaters
if ( bInitialized == false ) {
setDefaultBarFgColor( LineColor, 0 );
setDefaultBarThickness( Math.round( LineThickness ), 0 );
bInitialized = true;
}
for (i = 0; i < len; i++)
{
SumY += vPrice[i];
Sum1 += i * vPrice[i];
}
Sum2 = SumBars * SumY;
Num1 = len * Sum1 - Sum2;
Num2 = SumBars * SumBars - len * SumSqrBars;
if (Num2 != 0) Slope = Num1 / Num2;
Intercept = (SumY - Slope * SumBars) / len;
var LinearRegValue = Intercept + Slope * (len - 1 );
return LinearRegValue;
}
Comment