This is quite simple, I thought .. but this one is making be think this is VB6 all over again.
I am running a counter starting at bar 1. I don't always increment it but for this example I am. This is an isolated and simplifier example.
It did not include in the images, but the close price is different for each bar. You can look at the bars and see that. This should be easy to reproduce,
Despite the line assigning the counter the value of 1 when the Barnumber is 1 (BarNumber() == 1 then 1), the value in the counter is 0. The value is not NaN.
Attached is an image showing the code and the result.
Troubleshooting isolated the problem to (close == close[1]). If I replaced that expression with (1 == 2), I get the expected result.
Apparently even though the first condition of the if statement is true, it still evaluates close[1] which does not exist. But it does not produce an error.
I tried using CompoundValue like this
The counter initialized properly on bar 1, but it did not increment on bar 2. Proper incrementing started on bar 3. See images
Any thoughts would be appreciated
I am running a counter starting at bar 1. I don't always increment it but for this example I am. This is an isolated and simplifier example.
It did not include in the images, but the close price is different for each bar. You can look at the bars and see that. This should be easy to reproduce,
Code:
# MDLN < use this symbol to easily get to bar #1
def pC = if BarNumber() == 1 then 1 else if (close == close[1]) then pC[1] else pC[1] + 1;
AddChartBubble(yes, high, BarNumber() + " " + pC + " " + isNAN(pC), Color.WHITE);
Despite the line assigning the counter the value of 1 when the Barnumber is 1 (BarNumber() == 1 then 1), the value in the counter is 0. The value is not NaN.
Attached is an image showing the code and the result.
Troubleshooting isolated the problem to (close == close[1]). If I replaced that expression with (1 == 2), I get the expected result.
Apparently even though the first condition of the if statement is true, it still evaluates close[1] which does not exist. But it does not produce an error.
I tried using CompoundValue like this
Code:
# MDLN < use this symbol to easily get to bar #1
def pC = CompoundValue(1, pC[1] + 1, 1);
AddChartBubble(yes, high, BarNumber() + " " + pC + " " + isNAN(pC), Color.WHITE);
The counter initialized properly on bar 1, but it did not increment on bar 2. Proper incrementing started on bar 3. See images
Any thoughts would be appreciated