Whenever I have Woodie's Least Square Moving Average on a chart, and try to change time periods, or ticker symbols, it locks up the system from 45 seconds to ten minutes!
Being a moron when it comes to any kind of programming, I am unable to spot any obvious problem with the script.
Any help?
*************************
Copyright © eSignal, 2003
**************************
Description: Calculates the Least Square Moving Average (LSMA)
based on theories of "Woodie".
MA Length = 25
MA Offset = 0
MA Source = HLC/3
*/
function preMain()
{
setPriceStudy(true);
setStudyTitle("Woodies LSMA");
setCursorLabelName("LSMA");
setDefaultBarThickness(2);
}
var vPrice = null;
var vInit = false;
function main(nLength,nOffset)
{
if (nLength == null) nLength = 25;
if (nOffset == null) nOffset = 0;
if (vInit == false) {
vPrice = new Array(nLength);
vInit = true;
}
vClose = close();
vHigh = high();
vLow = low();
if (vClose == null) return;
if (vHigh == null) return;
if (vLow == null) return;
if (getBarState() == BARSTATE_NEWBAR) {
vPrice.pop();
vPrice.unshift(vHLC3);
}
vHLC3 = (vClose + vHigh + vLow) / 3;
vPrice[0] = vHLC3;
if (vPrice[nLength-1] == null) return;
debugPrintln(vPrice[nLength-1]);
//debugPrintln ("sadfs");
var Num1 = 0.0;
var Num2 = 0.0;
var SumBars = nLength * (nLength - 1) * 0.5;
var SumSqrBars = (nLength - 1) * nLength * (2 * nLength - 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;
for (i = 0; i < nLength; i++)
{
if(getCurrentBarIndex() > -5 && getCurrentBarIndex() != 0) debugPrintln(vPrice[i]);
SumY += vPrice[i];
Sum1 += i * vPrice[i];
}
Sum2 = SumBars * SumY;
Num1 = nLength * Sum1 - Sum2;
Num2 = SumBars * SumBars - nLength * SumSqrBars;
if (Num2 != 0) Slope = Num1 / Num2;
Intercept = (SumY - Slope * SumBars) / nLength;
var LinearRegValue = Intercept + Slope * (nLength - 1 - nOffset);
return LinearRegValue;
}
Being a moron when it comes to any kind of programming, I am unable to spot any obvious problem with the script.
Any help?
*************************
Copyright © eSignal, 2003
**************************
Description: Calculates the Least Square Moving Average (LSMA)
based on theories of "Woodie".
MA Length = 25
MA Offset = 0
MA Source = HLC/3
*/
function preMain()
{
setPriceStudy(true);
setStudyTitle("Woodies LSMA");
setCursorLabelName("LSMA");
setDefaultBarThickness(2);
}
var vPrice = null;
var vInit = false;
function main(nLength,nOffset)
{
if (nLength == null) nLength = 25;
if (nOffset == null) nOffset = 0;
if (vInit == false) {
vPrice = new Array(nLength);
vInit = true;
}
vClose = close();
vHigh = high();
vLow = low();
if (vClose == null) return;
if (vHigh == null) return;
if (vLow == null) return;
if (getBarState() == BARSTATE_NEWBAR) {
vPrice.pop();
vPrice.unshift(vHLC3);
}
vHLC3 = (vClose + vHigh + vLow) / 3;
vPrice[0] = vHLC3;
if (vPrice[nLength-1] == null) return;
debugPrintln(vPrice[nLength-1]);
//debugPrintln ("sadfs");
var Num1 = 0.0;
var Num2 = 0.0;
var SumBars = nLength * (nLength - 1) * 0.5;
var SumSqrBars = (nLength - 1) * nLength * (2 * nLength - 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;
for (i = 0; i < nLength; i++)
{
if(getCurrentBarIndex() > -5 && getCurrentBarIndex() != 0) debugPrintln(vPrice[i]);
SumY += vPrice[i];
Sum1 += i * vPrice[i];
}
Sum2 = SumBars * SumY;
Num1 = nLength * Sum1 - Sum2;
Num2 = SumBars * SumBars - nLength * SumSqrBars;
if (Num2 != 0) Slope = Num1 / Num2;
Intercept = (SumY - Slope * SumBars) / nLength;
var LinearRegValue = Intercept + Slope * (nLength - 1 - nOffset);
return LinearRegValue;
}
Comment