I write some code but don't know how to make it work
IITJV: I know that I cannot put [n] behind BarDir.
Since you are computing bar n, you must. Make BarDir a buffer.
double BarRange = High[n] - Low[n];
It is called Bar Direction. My idea is that if the current bar has C higher than Midpoint, it will be equal to 1 and vice versa. But if that bar is a perfect Doji (C = O and C = Midpoint), it will be equal to Direction of the Previous Bar. That's when the problem arose and I don't know how to solve it.
I know that I cannot put [n] behind BarDir. I just want to show that I want it to work like that so...
Can you guys show me the way to make it work?
Thank you in advance!