I try the array function in inside of do while as below code. But can’t solve the one particular array value to default and executive with one if condition. That “bi” array see the below code.
Please help “bi” array need to default within conditions executive.
Typically if you don’t get answers it means that your question is totally unclear to the readers. And quite frankly I have absolutely no idea what you mean with “how to default array fix”?
If you try again to describe what you need, with some more clarity, then somebody may be able to help.
Ganesan: I’m not sure anyone understands what you’re trying to achieve, and the diagram was only marginally helpful. Perhaps you could try explaining your goal without using pseudo-code. How would you explain your goal to another trader who is NOT a programmer?
if this bar's closing price is higher than the previous 2 bars
CC[bar] = 1
else if this bar's closing price is lower than the previous 2 bars
CC[bar] = 2
Otherwise
CC[bar] = something other value
Could you clarify your CC array? What are the possible values in the CC array? Are you trying to measure a numeric quantity, or capture a categorical state?
TIPS:
It might be possible to convert your code to array expressions. Using vectorized array operations is usually easier to understand, is less likely to have bugs, and is also much faster than writing loops.
Make sure the CC array is always assigned a value at every position in the array. Do not skip over some positions.
Move invariant expressions outside loops. For example, LastValue(BarIndex()) never changes and can be computed once before the loop.
The key to writing the code is ability to express one’s idea CLEARLY in plain language.
If your description lacks clarity you can’t code it. You first need to crystalize idea in your mind and be able to describe it clearly (in the way @Steve has shown). Only once you are able to describe idea in plain sentences with pure mathematical quality somebody may be able to transfer your idea into the code.