I am performing the null check but it still does not work. I am trying to combine a triangular moving average study with a bar colouring study.
I am getting the error on line 17 (var vLastTMA =...)
Any help would be much appreciated.
function preMain() {
setPriceStudy(true);
setStudyTitle("MA Price Bars");
setCursorLabelName("TMAPB");
setColorPriceBars(true);
setDefaultPriceBarColor(Color.black);
var fp1 = new FunctionParameter("nInputLength", FunctionParameter.NUMBER);
fp1.setName("Length");
fp1.setLowerLimit(1);
fp1.setDefault(15);
}
function main(nInputLength) {
var nMA = triMA(nInputLength, 0);
var vClose = close(0);
var vLastTMA = nMA.getValue(MAStudy.MA,-1);
if(nMA == null || vClose == null || vLastTMA == null) return;
if((nMA > vClose) && (nMA < vLastTMA)) {
setPriceBarColor(Color.red);
}
if ((nMA < vClose) && (nMA > vLastTMA)) {
setPriceBarColor(Color.green);
}
return nMA;
}
function triMA(Length, Offset)
{
var MAvg = null;
var TMA = null;
var vTMA = 0.0;
var vMAvg = 0.0;
var Len1 = 0.0;
var Len2 = 0.0;
var Len = 0.0;
var LenRnd = 0.0;
Len = Length / 2;
LenRnd = Math.round(Len);
if (LenRnd != Len )
{
Len1 = LenRnd;
Len2 = LenRnd;
}
if (LenRnd == Len )
{
Len1 = LenRnd;
Len2 = LenRnd + 1;
}
if (MAvg == null) MAvg = new MAStudy(Len1, Offset, "OHLC/4", MAStudy.SIMPLE);
if(MAvg.getValue(MAStudy.MA) == null) return;
if (TMA == null) TMA = new MAStudy(Len2, 0, MAvg, MAStudy.MA, MAStudy.SIMPLE);
vTMA = TMA.getValue(MAStudy.MA);
return (vTMA);
}
I am getting the error on line 17 (var vLastTMA =...)
Any help would be much appreciated.
function preMain() {
setPriceStudy(true);
setStudyTitle("MA Price Bars");
setCursorLabelName("TMAPB");
setColorPriceBars(true);
setDefaultPriceBarColor(Color.black);
var fp1 = new FunctionParameter("nInputLength", FunctionParameter.NUMBER);
fp1.setName("Length");
fp1.setLowerLimit(1);
fp1.setDefault(15);
}
function main(nInputLength) {
var nMA = triMA(nInputLength, 0);
var vClose = close(0);
var vLastTMA = nMA.getValue(MAStudy.MA,-1);
if(nMA == null || vClose == null || vLastTMA == null) return;
if((nMA > vClose) && (nMA < vLastTMA)) {
setPriceBarColor(Color.red);
}
if ((nMA < vClose) && (nMA > vLastTMA)) {
setPriceBarColor(Color.green);
}
return nMA;
}
function triMA(Length, Offset)
{
var MAvg = null;
var TMA = null;
var vTMA = 0.0;
var vMAvg = 0.0;
var Len1 = 0.0;
var Len2 = 0.0;
var Len = 0.0;
var LenRnd = 0.0;
Len = Length / 2;
LenRnd = Math.round(Len);
if (LenRnd != Len )
{
Len1 = LenRnd;
Len2 = LenRnd;
}
if (LenRnd == Len )
{
Len1 = LenRnd;
Len2 = LenRnd + 1;
}
if (MAvg == null) MAvg = new MAStudy(Len1, Offset, "OHLC/4", MAStudy.SIMPLE);
if(MAvg.getValue(MAStudy.MA) == null) return;
if (TMA == null) TMA = new MAStudy(Len2, 0, MAvg, MAStudy.MA, MAStudy.SIMPLE);
vTMA = TMA.getValue(MAStudy.MA);
return (vTMA);
}
Comment