# direction of current bar

53

How does one determine the direction (up/down) of the current bar. Close[0] > Open[0] should work but Close value appears to be empty until the bar is complete. I imagine I should be trying to get the most recent value rather than Close. How can I do that?
1401

Try Close[1] > Open[0] or Close[1] < Open[0]
7111

rlarz:
How does one determine the direction (up/down) of the current bar. Close[0] > Open[0] should work but Close value appears to be empty until the bar is complete. I imagine I should be trying to get the most recent value rather than Close. How can I do that?
The Close[0] value is not empty, it is the last Bid and so it changes until the bar is completed!
53

Thank you deysmacro. I don't understand why, but it does work.

Edit: I take that back (not the thank you); I was checking more bars and noticed it was working more by coincidence.

1081

rlarz:
How does one determine the direction (up/down) of the current bar. Close[0] > Open[0]

This is not a good solution because at the beginning of a new bar, the direction will change and change.

could be

```Close[0] > Close[1]; up same problem

Close[0] > Close[1] - spread*Point ; up

Close[0] > Open[1]; up

((Close[0] + Open[0])/2)> ((Close[1] + Open[1])/2)```
53

Using a loop with Close[i] > Open[i] = 1 & Close[i] < Open[i] = -1 works fine in an indicator but returns EMPTY_VALUE when the indicator is used in an EA. I tried comparing the Open with the Bid (and with Ask) but that doesn't work either. I'm not interested in the previous bar. All I want to know is if the current bar is up or down at the moment and I want it to work in an EA.
5003

rlarz:
Using a loop with Close[i] > Open[i] = 1 & Close[i] < Open[i] = -1 works fine in an indicator but returns EMPTY_VALUE when the indicator is used in an EA. I tried comparing the Open with the Bid (and with Ask) but that doesn't work either. I'm not interested in the previous bar. All I want to know is if the current bar is up or down at the moment and I want it to work in an EA.
```#define NEUTRAL 0
#define UP 1
#define DOWN 2

int digits;

int OnInit()
{
if(_Digits==3) digits=2;
else           digits=4;

int Direction()
{
int direction=NEUTRAL;
static double price[3];
price[2]=price[1];
price[1]=price[0];

if(price[0]>price[2])   direction=UP;
if(price[0]<price[2])   direction=DOWN;
return(direction);
} ```
53

pipPod:

I don't understand. How can comparing the current price with previous prices tell me whether or not the current bar is up or down. I don't want to know how it compares with previous bars; I just want to know if the current price (often called Last in other languages) is greater than or less than the current bar's Open.

I also tried using this function in the EA:

```double GetBarDirection()
{
if(Open[0]>Bid) return -1.0;
else if(Open[0]<Bid) return 1.0;
else return 0.0;
}
```

It doesn't work either. All bars = 0.0;

53

pipPod:

I just realized what your code is doing. That seems to be working. Thanks!

Edit: I spoke too soon again. On closer examination, bars that are obviously down (Red on my chart) are sometimes classified as up bars and vice versa. Unfortunately, the discrepancies are not consistent.

1081

nice solution piPod