Hi there.
I'm trying to make a function that calculates the number of bars that appears after a condition happens.
The idea is simple. If a binary indicates 1 on current bar and 0 on the previous bar the no of bars counted should be zero. And if the condition mentioned didn't happen, we should get the previous bar count and sum one.
The problem is that I need the previous value calculated by the own function being calculated.
Is this possible?
I made a research in the forum and the materials in the support area but could find nothing. Every case I checked the problem with the previous value is with a global or local variable.
The result is:
Error: efsExternal: Cyclic dependency has been detected
Thanks in advance.
The code is below.
function preMain() {
setPriceStudy(false);
setStudyTitle("BS");
setCursorLabelName("BS", 0 );
setPlotType(PLOTTYPE_HISTOGRAM,0);
}
var bs = null;
function main() {
if(getBarState() == BARSTATE_NEWBAR ) {
var cond = efsExternal("B.F. - 2.2 - Highlight DM BIN.efs");
var cond0 = cond.getValue(0);
var cond_1 = cond.getValue(-1);
//The efsExternal above is a simple binary indicator that defines the condition wich starts the bar count
var bs_10 = efsExternal("BS.efs");
var bs_1 = bs_10.getValue(-1);
//Here is my try to get the previous value calculated in main()
if( cond0 == -1 && cond_1 != -1) {
bs = 0
} else { bs = bs_1 + 1
}
} else { bs = null
}
return bs;
}
I'm trying to make a function that calculates the number of bars that appears after a condition happens.
The idea is simple. If a binary indicates 1 on current bar and 0 on the previous bar the no of bars counted should be zero. And if the condition mentioned didn't happen, we should get the previous bar count and sum one.
The problem is that I need the previous value calculated by the own function being calculated.
Is this possible?
I made a research in the forum and the materials in the support area but could find nothing. Every case I checked the problem with the previous value is with a global or local variable.
The result is:
Error: efsExternal: Cyclic dependency has been detected
Thanks in advance.
The code is below.
function preMain() {
setPriceStudy(false);
setStudyTitle("BS");
setCursorLabelName("BS", 0 );
setPlotType(PLOTTYPE_HISTOGRAM,0);
}
var bs = null;
function main() {
if(getBarState() == BARSTATE_NEWBAR ) {
var cond = efsExternal("B.F. - 2.2 - Highlight DM BIN.efs");
var cond0 = cond.getValue(0);
var cond_1 = cond.getValue(-1);
//The efsExternal above is a simple binary indicator that defines the condition wich starts the bar count
var bs_10 = efsExternal("BS.efs");
var bs_1 = bs_10.getValue(-1);
//Here is my try to get the previous value calculated in main()
if( cond0 == -1 && cond_1 != -1) {
bs = 0
} else { bs = bs_1 + 1
}
} else { bs = null
}
return bs;
}
Comment