I have managed to create efs files of ADX and RSI which are smoothed using Rafter's Least Square Method, but am unable to figure out how to do it with the CCI function since I can't access prior bar data easily. I assume I would have to build an array of CCI data and then continually update it for each bar, shifting the prior information back as a new bar of data is inserted, but I have been unable to do this effectively. The CCI period is not important as I can change that anytime....I am merely interested in how to build this kind of efs from a builtin function which doesn't give prior bar data like RSI.
Here is what I've got for the Rafter Smoothed RSI.
// Smoothing RSI using Rafter's Least Square Method
// First input is length of the Least Square, the second input is the smoothing factor
var study = new RSIStudy(17, "HLC/3");
function preMain()
{
setPriceStudy(false);
setStudyTitle("T_RSI(17)");
setCursorLabelName("T_RSI");
setDefaultBarFgColor(Color.RGB(111,200,100),0);
setDefaultBarThickness(2,0)
addBand(10, PS_DOT, 2, Color.RGB(111,200,100));
addBand(90, PS_DOT, 2, Color.RGB(111,200,100));
addBand(50, PS_DASH, 3, Color.black)
}
function main(nInputLength,nInputBarPlus)
{
var len = 1;
var BarPlus = 1;
if (nInputLength != null) len = nInputLength;
if (nInputBarPlus != null) BarPlus = nInputBarPlus;
var i = 0;
var vPrice;
var joy = new Array(len);
//---Generate RSI Values
for(i = 0; i < len; i++) {
if (i==0)
vPrice = study.getValue(RSIStudy.RSI, i);
else vPrice = study.getValue(RSIStudy.RSI,-i);
joy[i] = vPrice;
}
//---Smooth using Rafters Technique
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;
for (i = 0; i < len; i++)
{
SumY += joy[i];
Sum1 += i * joy[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 Sm_RSI = Intercept + Slope * (len - 1 - BarPlus);
return (Sm_RSI);
}
Here is what I've got for the Rafter Smoothed RSI.
// Smoothing RSI using Rafter's Least Square Method
// First input is length of the Least Square, the second input is the smoothing factor
var study = new RSIStudy(17, "HLC/3");
function preMain()
{
setPriceStudy(false);
setStudyTitle("T_RSI(17)");
setCursorLabelName("T_RSI");
setDefaultBarFgColor(Color.RGB(111,200,100),0);
setDefaultBarThickness(2,0)
addBand(10, PS_DOT, 2, Color.RGB(111,200,100));
addBand(90, PS_DOT, 2, Color.RGB(111,200,100));
addBand(50, PS_DASH, 3, Color.black)
}
function main(nInputLength,nInputBarPlus)
{
var len = 1;
var BarPlus = 1;
if (nInputLength != null) len = nInputLength;
if (nInputBarPlus != null) BarPlus = nInputBarPlus;
var i = 0;
var vPrice;
var joy = new Array(len);
//---Generate RSI Values
for(i = 0; i < len; i++) {
if (i==0)
vPrice = study.getValue(RSIStudy.RSI, i);
else vPrice = study.getValue(RSIStudy.RSI,-i);
joy[i] = vPrice;
}
//---Smooth using Rafters Technique
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;
for (i = 0; i < len; i++)
{
SumY += joy[i];
Sum1 += i * joy[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 Sm_RSI = Intercept + Slope * (len - 1 - BarPlus);
return (Sm_RSI);
}
Comment