English

## direction of current bar

 14 rlarz 2014.11.03 10:01   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?
 1211 deysmacro 2014.11.03 10:14 #   Try Close[1] > Open[0] or Close[1] < Open[0]
 2031 gooly 2014.11.03 10:22 #   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!
 14 rlarz 2014.11.03 10:27 #   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.
 250 ffoorr 2014.11.03 10:36 #   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)```
 14 rlarz 2014.11.03 11:06 #   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.
 32 pipPod 2014.11.03 11:44 #   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];    price[0]=NormalizeDouble(Ask,digits);       if(price[0]>price[2])   direction=UP;    if(price[0]
 14 rlarz 2014.11.03 11:50 #   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]
 14 rlarz 2014.11.03 12:12 #   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.
 250 ffoorr 2014.11.03 13:18 #   nice solution piPod