Download MetaTrader 5
To add comments, please log in or register
They are making profit already using Freelance service. You can join them!
rlarz
53
rlarz 2014.11.03 09: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?
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.11.03 09:14  
Try Close[1] > Open[0] or Close[1] < Open[0]
Carl Schreiber
5927
Carl Schreiber 2014.11.03 09: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!
rlarz
53
rlarz 2014.11.03 09: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. 

ffoorr
982
ffoorr 2014.11.03 09: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)
rlarz
53
rlarz 2014.11.03 10: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.
Ernst Van Der Merwe
4397
Ernst Van Der Merwe 2014.11.03 10: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]<price[2])   direction=DOWN;
   return(direction);
  } 
rlarz
53
rlarz 2014.11.03 10: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]<Bid) return 1.0;
        else return 0.0;
}

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

rlarz
53
rlarz 2014.11.03 11: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.

ffoorr
982
ffoorr 2014.11.03 12:18  
nice solution piPod
/
To add comments, please log in or register