Hi,
I have problem with negative offset-moving average. After I insert the indicator, the negative offset-ma work only for historical bars not for the new bars.
If I insert the indicator Moving Average from Basic Studies with Offset -2 it show me the correctly values realtime, but I cant use the code, it dont work, what do I wrong?
I need the -2 value for an crossover-alert.
I have problem with negative offset-moving average. After I insert the indicator, the negative offset-ma work only for historical bars not for the new bars.
PHP Code:
function preMain()
{
setPriceStudy(true);
setStudyTitle("offset - test");
setShowCursorLabel(true);
setPlotType(PLOTTYPE_LINE,0);
setPlotType(PLOTTYPE_LINE,1);
setDefaultBarFgColor(Color.green,0);
setDefaultBarFgColor(Color.red,1);
setDefaultBarThickness(2,0);
setDefaultBarThickness(2,1);
//setComputeOnClose(true);
fp1 = new FunctionParameter("MA1", FunctionParameter.NUMBER);
fp1.setDefault(89);
fp2 = new FunctionParameter("MA2", FunctionParameter.STRING);
fp2.setDefault(34);
}
var bInit = false;
function main(MA1, MA2)
{
if (bInit == false)
{
myMA1 = offsetSeries(sma(MA1, close()), 2);
myMA2 = offsetSeries(ema(MA2, close()), -2);
bInit = true;
}
return new Array(myMA1.getValue(0), myMA2.getValue(0));
}
I need the -2 value for an crossover-alert.
Comment