the below images speak for themselves , Formula Parameter Length is set at 25 but i get the same problem with all settings,
Announcement
Collapse
No announcement yet.
Fault with EFS2 custom Linear Regression
Collapse
X
-
This stems from the chart not being able to go back and recalculate those older values (as by nature the Linear Regression older values change, and are not set in stone). Apparently the EFS1 Linear Regression study suffers from the same problem unless it's reloaded on each new bar.
The most current value will be correct, it's just the display of the plot is all wacky.
Let me see what I can do for Beta/2 or Beta/3.
-
Possible fix for efs2 Linear Regression
DionLoy
the linear regression older values seem good so i thought as a possible fix to get the chart to plot the lines correctly to use the drawLineRelative function instead of the return getSeries , have a look at the below code and see what you think i added a filter xMidLR1 for only the base linear regression line as all the lines will change at the same time, in theory anyway.
also i had to change the FunctionParameter "Length" setLowerLimit from 0 to 3 and the setDefault from 0 to 100 to get lines on loading of the efs.
PHP Code:/*********************************************************
By Alexis C. Montenegro for eSignal © December 2004
Use and/or modify this code freely. If you redistribute it
please include this and/or any other comment blocks and a
description of any changes you make.
**********************************************************/
var fpArray = new Array();
function preMain() {
setPriceStudy(true);
setStudyTitle("LinReg");
setCursorLabelName("LRUpr", 0);
setCursorLabelName("LRBas", 1);
setCursorLabelName("LRLwr",2);
setDefaultBarFgColor(Color.blue, 0);
setDefaultBarFgColor(Color.red, 1);
setDefaultBarFgColor(Color.blue, 2);
setPlotType(PLOTTYPE_LINE, 0);
setPlotType(PLOTTYPE_LINE, 1);
setPlotType(PLOTTYPE_LINE, 2);
setDefaultBarThickness(2, 0);
setDefaultBarThickness(2, 1);
setDefaultBarThickness(2, 2);
askForInput();
var x=0;
fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
with(fpArray[x++]){
setLowerLimit(3); // changed from 0 to 3 for wonky line fix
setDefault(100); // changed from 0 to 100 for wonky line fix
}
fpArray[x] = new FunctionParameter("StdDev", FunctionParameter.NUMBER);
with(fpArray[x++]){
setLowerLimit(0);
setDefault(1);
}
fpArray[x] = new FunctionParameter("Source", FunctionParameter.STRING);
with(fpArray[x++]){
addOption("open");
addOption("high");
addOption("low");
addOption("close");
addOption("hl2");
addOption("hlc3");
addOption("ohlc4");
setDefault("close");
}
fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
with(fpArray[x++]){
setName("Show Parameters");
setDefault(false);
}
}
var bInit = false;
var xUpLR = null;
var xMidLR = null;
var xLoLR = null;
var xMidLR1 = null; // added for wonky line fix
function main(Length,StdDev,Source,Params) {
if(bInit == false){
xUpLR = upperLinearReg(Length, StdDev,eval(Source)());
xMidLR = middleLinearReg(Length, StdDev,eval(Source)());
xLoLR = lowerLinearReg(Length, StdDev,eval(Source)());
setShowTitleParameters(eval(Params));
bInit = true;
}
if(getCurrentBarIndex()==0){
if( xMidLR.getValue(0) != xMidLR1){ // the following added for wonky line fix
clearLines();
drawLineRelative(-(Length-1), xUpLR.getValue(-(Length-1)), 0, xUpLR.getValue(0), PS_SOLID, 1, Color.blue,1);
drawLineRelative(-(Length-1), xMidLR.getValue(-(Length-1)), 0, xMidLR.getValue(0), PS_SOLID, 1, Color.red,2);
drawLineRelative(-(Length-1), xLoLR.getValue(-(Length-1)), 0, xLoLR.getValue(0), PS_SOLID, 1, Color.blue,3);
xMidLR1 = xMidLR.getValue(0);
}
}
return ;
// removed return new Array for wonky line fix.
//return new Array (getSeries(xUpLR),getSeries(xMidLR),getSeries(xLoLR));
}
Last edited by shogun; 03-16-2005, 11:57 AM.
Comment
-
Alexis
the only reason i changed the default Length fro 0 to 100 was i was getting a vertical line on loading of the efs as the first and third parameters of drawLineRelative where both the same,
i think the fault lies with the way getSeries() is retrieving the past data when there is more than one data input,but we are getting into territory which is way beyond my abilities.
i am finding efs2 much easier to understand as there is far less coding needed to achive the same results than with efs1.
Comment
Comment