I'm trying to set price (Open, High, Low or Close) as a user input so the user can apply William Rafter's moving trend to those values rather than just the close (as in the original formula by TSSupport).
I've substituted "Nval" for close in the original formula, but it doesn't seem to work. If I try to change the value to, say, high in the edit studies dialog, the study just disappears from the chart. If I clear the nval field in the edit studies dialog, the study reappears. The code I'm using is below. I've a horrible feeling I'm just doing something dumb.....
function preMain()
{
setStudyTitle("MLR");
setCursorLabelName("MLR", 0);
setDefaultBarFgColor(Color.green, 1);
setPriceStudy(true);
}
function main(n, nval) {
if(nval== null) {nval= close;}
if(n == null)
n = 20;
var sum = 0;
var i = 0;
var mt = 0;
for(i = n; i > 0; i--)
sum += (i - (n + 1) / 3) * nval(i - n);
wt = 6 / (n * (n + 1)) * sum
return wt;
}
I've substituted "Nval" for close in the original formula, but it doesn't seem to work. If I try to change the value to, say, high in the edit studies dialog, the study just disappears from the chart. If I clear the nval field in the edit studies dialog, the study reappears. The code I'm using is below. I've a horrible feeling I'm just doing something dumb.....
function preMain()
{
setStudyTitle("MLR");
setCursorLabelName("MLR", 0);
setDefaultBarFgColor(Color.green, 1);
setPriceStudy(true);
}
function main(n, nval) {
if(nval== null) {nval= close;}
if(n == null)
n = 20;
var sum = 0;
var i = 0;
var mt = 0;
for(i = n; i > 0; i--)
sum += (i - (n + 1) / 3) * nval(i - n);
wt = 6 / (n * (n + 1)) * sum
return wt;
}
Comment