I am writing a script that needs to update the returned values as new bars come in.
Here is an example EFS to demonstrate and reproduce the problem I am having.
It's a simple EFS that returns the number of bars away it is from the current bar. When the script is first loaded, all values are correct. Once a new bar comes in, all values are now wrong (off by 1). So, the bar that was 5 bars away from the current bar should now be "6" when a new bar comes in, and so on.
Should I use efsInternal() in this situation? How do I make them auto-update?
Once I get that working as expected, I will then need to handle having drawText() labels also auto-update as new bars come in. (not in the script below)
Any help is greatly appreciated!
Here is an example EFS to demonstrate and reproduce the problem I am having.
It's a simple EFS that returns the number of bars away it is from the current bar. When the script is first loaded, all values are correct. Once a new bar comes in, all values are now wrong (off by 1). So, the bar that was 5 bars away from the current bar should now be "6" when a new bar comes in, and so on.
Should I use efsInternal() in this situation? How do I make them auto-update?
Once I get that working as expected, I will then need to handle having drawText() labels also auto-update as new bars come in. (not in the script below)
Any help is greatly appreciated!
PHP Code:
function preMain()
{
setStudyTitle("Bars From Current");
setCursorLabelName("BFC", 0);
setPriceStudy(true);
setShowCursorLabel( true );
setShowTitleParameters(false);
}
var bInit = false;
var studyBarsFromCurrent = null;
function main()
{
if(!bInit)
{
studyPivotSwings = efsInternal("BarsFromCurrent");
bInit = true;
}
return studyPivotSwings.getValue(0);
}
function BarsFromCurrent()
{
var FoundCurBar = false;
var BarCount = 0;
// Loop until we reach the current bar
do
{
FoundCurBar = (close(BarCount) == null);
if (!FoundCurBar)
BarCount++;
}
while(!FoundCurBar)
return BarCount-1; // subtract 1 to force 0-based
}
Comment