Hello Steve,
Yep, create four global variables.
var nHcntr = 0;
var nLcntr = 0;
var bH = false;
var bL = false;
The first two will store counts for the number of times a new high or low occurs. The two booleans will be used for real time processing so that only one new high or low occurence is counted for any single bar. In other words, it will prevent the cntr variables from incrementing every time a new high or low occurs during the bar or interval.
If you want the count to reset for each day, then reset these two variables to 0 inside your check for the new day (i.e. getDay(0) != getDay(-1)) at the top of main.
Somewhere at the top of main, add a check for new bar and reset the two booleans.
Next, add two if statements just before you do the Math.max and .min calls for vHigh and vLow. These statements will test for a new breach of the high or low and increment the counters accordingly. If one of the conditions evaluates to true you need to set the corresponding boolean to true, which will prevent the count from incrementing again until the next bar starts.
At this point nHcntr and nLcntr should have the numbers you're looking for. You can then use drawTextRelative() and place the number above or below the bar.
Yep, create four global variables.
var nHcntr = 0;
var nLcntr = 0;
var bH = false;
var bL = false;
The first two will store counts for the number of times a new high or low occurs. The two booleans will be used for real time processing so that only one new high or low occurence is counted for any single bar. In other words, it will prevent the cntr variables from incrementing every time a new high or low occurs during the bar or interval.
If you want the count to reset for each day, then reset these two variables to 0 inside your check for the new day (i.e. getDay(0) != getDay(-1)) at the top of main.
Somewhere at the top of main, add a check for new bar and reset the two booleans.
PHP Code:
if (getBarState() == BARSTATE_NEWBAR) {
bH = false;
bL = false;
}
Next, add two if statements just before you do the Math.max and .min calls for vHigh and vLow. These statements will test for a new breach of the high or low and increment the counters accordingly. If one of the conditions evaluates to true you need to set the corresponding boolean to true, which will prevent the count from incrementing again until the next bar starts.
PHP Code:
if (bH == false && h > vHigh) {
bH = true;
nHcntr++;
}
if (bL == false && l < vLow) {
bL = true;
nLcntr++;
}
Comment