I am using callFunction to call a modified ATR function that works great when added to a bar chart. It shows up in its own window under the price data.
var AvgVol
function preMain() {
setPriceStudy(true);
setColorPriceBars(true);
setDefaultBarFgColor(Color.black);
}
function main(nInputLength,nOffset,nNumberBars) {
if (nInputLength == null) {
nInputLength = 70;
}
if (nOffset == null) {
nOffSet = -1;
}
if (nNumberBars == null) {
nNumberBars = 19;
}
AvgVol = callFunction("Trendstat/TCMATR.efs", "main", 20) ;
debugPrintln("------------------");
debugPrintln("AvgVol:" + AvgVol);
}
This is the separate TCMATR function that is being called. Tested it by itself and it works fine. Called from the Main function up above, I get NaN. Searched the EFS web-based stuff and came up empty on this error code.
/* TCMATR.efs */
/**********/
var AryTTR = null;
var iCount = 0;
function preMain() {
setPriceStudy(false);
setCursorLabelName("TCM - ATR",0);
debugClear()
}
function main(nInputPeriod){
// the nInputPeriod can't less than 2
if (nInputPeriod == null){
nInputPeriod = 20;
}
var vState = getBarState();
if(vState == BARSTATE_ALLBARS){
iCount = 0;
}
if (AryTTR == null){
AryTTR = new Array(nInputPeriod);
}
var dH = high(-1);
var dL = low(-1);
var dC = close(-2);
var ATRHigh = Math.max(dH,dC);
var ATRLow = Math.min(dL,dC);
var TodayTrueRange = ATRHigh - ATRLow ;
if (iCount < nInputPeriod){
AryTTR.shift();
AryTTR.push(TodayTrueRange);
iCount++;
return;
}
else{
var PATR = ref(-1); // Previous ATR
if (PATR == null){
var iSum=0;
for(i=0;i<AryTTR.length;i++){
iSum = iSum + AryTTR[i];
}
return iSum/nInputPeriod;
}
else{
var CATR = (PATR*(nInputPeriod-1)+TodayTrueRange)/nInputPeriod;
//debugPrintln("------------------------");
//debugPrintln("nInputPeriod:" + nInputPeriod);
//debugPrintln("TodayTrueRange:" + TodayTrueRange);
//debugPrintln("PATR:" + PATR);
//debugPrintln("CATR:" + CATR);
return CATR;
}
}
}
Thanks
Mon_Trader
var AvgVol
function preMain() {
setPriceStudy(true);
setColorPriceBars(true);
setDefaultBarFgColor(Color.black);
}
function main(nInputLength,nOffset,nNumberBars) {
if (nInputLength == null) {
nInputLength = 70;
}
if (nOffset == null) {
nOffSet = -1;
}
if (nNumberBars == null) {
nNumberBars = 19;
}
AvgVol = callFunction("Trendstat/TCMATR.efs", "main", 20) ;
debugPrintln("------------------");
debugPrintln("AvgVol:" + AvgVol);
}
This is the separate TCMATR function that is being called. Tested it by itself and it works fine. Called from the Main function up above, I get NaN. Searched the EFS web-based stuff and came up empty on this error code.
/* TCMATR.efs */
/**********/
var AryTTR = null;
var iCount = 0;
function preMain() {
setPriceStudy(false);
setCursorLabelName("TCM - ATR",0);
debugClear()
}
function main(nInputPeriod){
// the nInputPeriod can't less than 2
if (nInputPeriod == null){
nInputPeriod = 20;
}
var vState = getBarState();
if(vState == BARSTATE_ALLBARS){
iCount = 0;
}
if (AryTTR == null){
AryTTR = new Array(nInputPeriod);
}
var dH = high(-1);
var dL = low(-1);
var dC = close(-2);
var ATRHigh = Math.max(dH,dC);
var ATRLow = Math.min(dL,dC);
var TodayTrueRange = ATRHigh - ATRLow ;
if (iCount < nInputPeriod){
AryTTR.shift();
AryTTR.push(TodayTrueRange);
iCount++;
return;
}
else{
var PATR = ref(-1); // Previous ATR
if (PATR == null){
var iSum=0;
for(i=0;i<AryTTR.length;i++){
iSum = iSum + AryTTR[i];
}
return iSum/nInputPeriod;
}
else{
var CATR = (PATR*(nInputPeriod-1)+TodayTrueRange)/nInputPeriod;
//debugPrintln("------------------------");
//debugPrintln("nInputPeriod:" + nInputPeriod);
//debugPrintln("TodayTrueRange:" + TodayTrueRange);
//debugPrintln("PATR:" + PATR);
//debugPrintln("CATR:" + CATR);
return CATR;
}
}
}
Thanks
Mon_Trader
Comment