Hi,
I've got this below that I found on here somewhere, and I'd like to turn it into an ascillator to measure the different between this bar and the bar x-number ago. But I'm stuck with htis one. :-( can any one help at all please?
many thanks
Natalie
function preMain()
{
setPriceStudy(false);
setStudyTitle("LSMA");
setCursorLabelName("LSMA");
setDefaultBarThickness(1);
}
var vPrice = null;
var vInit = false;
function main(nLength,nOffset)
{
if (nLength == null) nLength = 40;
if (nOffset == null) nOffset = 2;
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;
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);
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;
}
I've got this below that I found on here somewhere, and I'd like to turn it into an ascillator to measure the different between this bar and the bar x-number ago. But I'm stuck with htis one. :-( can any one help at all please?
many thanks
Natalie
function preMain()
{
setPriceStudy(false);
setStudyTitle("LSMA");
setCursorLabelName("LSMA");
setDefaultBarThickness(1);
}
var vPrice = null;
var vInit = false;
function main(nLength,nOffset)
{
if (nLength == null) nLength = 40;
if (nOffset == null) nOffset = 2;
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;
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);
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