PHP Code:
function preMain()
{
setStudyTitle("SEB LinRegSlope");
setCursorLabelName("Slope", 0);
setCursorLabelName("ZeroLine", 1);
setDefaultBarFgColor(Color.red, 0);
setDefaultBarFgColor(Color.cyan, 1);
}
function main(Length)
{
if (Length == null) Length = 21;
var SL = 0.0;
var Close = getValue("Close", 0, - Length);
var SumBars = Length * (Length - 1) * .5;
var SumSqrBars = (Length - 1) * Length * (2 * Length - 1) / 6;
var Sum1 = 0.0;
var SumY = 0.0;
var i = 0;
for (i = 0; i < Length; i++)
{
Sum1 += i * Close[i];
SumY += Close[i];
}
var Sum2 = SumBars * SumY;
var Num1 = Length * Sum1 - Sum2;
var Num2 = SumBars * SumBars - Length * SumSqrBars;
SL = Num1 / Num2;
return new Array(SL, 0);
}
i was thinking about an oldSL and SL and if SL is bigger than the oldSL than the trend is upwards and when SL < oldSL than downwards...
does anybody know how i have to code this...
thanks and regards erilein
Comment