Download MetaTrader 5

Is there something that I'm doing wrong?

To add comments, please log in or register
Paul
526
Paul  
It's been a while since I've been back to coding, but the following code doesn't seem  to return the values I'm looking for, just zeros.
        double vDO=iOpen("NZDUSD",1440,0);       // Daily Open
        double vDC=iClose("NZDUSD",1440,0);      // Daily Close     
        
        Alert("vDO =  ",vDO,"    vDC =  ",vDC);  

No matter where I place the code within an EA or indicator, I just get zeros.  Can I not assign a value of iOpen or iClose to a variable anymore?


Thanks!

Carl Schreiber
6691
Carl Schreiber  

Make sure the symbols appear in the marketwatch.

Check SymbolSelect().

Paul
526
Paul  
I've never had a problem before using this code this way.
Alert("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,0),", ",  iOpen("USDCHF",PERIOD_H1,0),", ",
                                      iHigh("USDCHF",PERIOD_H1,0),", ",  iLow("USDCHF",PERIOD_H1,0),", ",
                                      iClose("USDCHF",PERIOD_H1,0),", ", iVolume("USDCHF",PERIOD_H1,0));
The above code works.  Not sure why the previous code doesn't.  I can usually add this code anywhere within an EA or indicator.  Inside loops or outside.  But no matter where I place it now, even with different brokers, I get nothing but zeros.
Keith Watford
Moderator
9641
Keith Watford  
Yellowbeard:
It's been a while since I've been back to coding, but the following code doesn't seem  to return the values I'm looking for, just zeros.
        double vDO=iOpen("NZDUSD",1440,0);       // Daily Open
        double vDC=iClose("NZDUSD",1440,0);      // Daily Close     
        
        Alert("vDO =  ",vDO,"    vDC =  ",vDC); 

No matter where I place the code within an EA or indicator, I just get zeros.  Can I not assign a value of iOpen or iClose to a variable anymore?


Thanks!

Is there a symbol called "NZDUSD" with the brokers that you have used?

The code should work if there is

whroeder1
14785
whroeder1  
If your chart isn't exactly "EURUSD" then it can't work. Broker's use a variety of naming patterns: EURUSD, EURUSDm, EURUSDi, "EURUSD.", "EURUSD..", "EUR.USD", "EUR/USD", "EURUSD.stp", EURUSDct, "EURUSD.G", "EURUSD+", and EURUSDpro at least. Don't hard code things; just use the predefined _Symbol.
Paul
526
Paul  

Ah!  My broker uses NZDUSDpro.  That did the trick!  Never dawned on me.

Thank you, very much!

To add comments, please log in or register