I have a piece of code / EFS that works fine.
I use it 2 times on a chart first based on High.
Then I edited it to be based on Low.
How do I change the code to combine so that one EFS will do / plot both lines?
setStudyTitle("Berts SELL");
setCursorLabelName("LR-L Curve");
and
setStudyTitle("Berts Buy");
setCursorLabelName("LR-H Curve");
NEW would be combined ...
setStudyTitle("Berts BUYnSELL");
setCursorLabelName("LR-L Curve");
setCursorLabelName("LR-H Curve");
------------------------------------------------------------
Here is the original code.
/************************************************** *****************
* Description : This Indicator plots the Linear Regression Curve
*
************************************************** ******************/
//Global Variables
var bInitialized = false;
function preMain()
{
setPriceStudy(true);
setStudyTitle("Berts SELL");
setCursorLabelName("LR-L 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.red);
// end of formula paramaters
}
function main(frLength,LineThickness,LineColor)
{
var len = frLength;
var vPrice = getValue("Low", 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;
}
I use it 2 times on a chart first based on High.
Then I edited it to be based on Low.
How do I change the code to combine so that one EFS will do / plot both lines?
setStudyTitle("Berts SELL");
setCursorLabelName("LR-L Curve");
and
setStudyTitle("Berts Buy");
setCursorLabelName("LR-H Curve");
NEW would be combined ...
setStudyTitle("Berts BUYnSELL");
setCursorLabelName("LR-L Curve");
setCursorLabelName("LR-H Curve");
------------------------------------------------------------
Here is the original code.
/************************************************** *****************
* Description : This Indicator plots the Linear Regression Curve
*
************************************************** ******************/
//Global Variables
var bInitialized = false;
function preMain()
{
setPriceStudy(true);
setStudyTitle("Berts SELL");
setCursorLabelName("LR-L 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.red);
// end of formula paramaters
}
function main(frLength,LineThickness,LineColor)
{
var len = frLength;
var vPrice = getValue("Low", 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