- How do I get Volume[0] ?
- Multi Timeframe Indicators
- Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6.
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?
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)
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]<price[2]) direction=DOWN; return(direction); }
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;
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.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use