Help for SymbolInfoTick()

 

I have this code in my EA and I am puzzled by the results. Please can someone tell me where my thinking is wrong as I thought that this should load the current chart prices etc. or if it failed print the error statement and error code. It normally prints the ask price correctly and has never printed the error message and error code, however, every few days prints the price as 0.0. what am I doing or thinking wrong

void OnTick()
 { 
  MqlTick myprice;
  MqlTradeRequest myrequest;
  MqlTradeResult myresult;
  ZeroMemory(myrequest);
  myrequest.action = TRADE_ACTION_DEAL;
  myrequest.sl = 0;
  myrequest.tp = 0;
  myrequest.symbol = _Symbol;
  myrequest.magic = 0;
  myrequest.type_filling = ORDER_FILLING_FOK;
  myrequest.deviation = 10;
  if(!SymbolInfoTick(_Symbol, myprice))
   {
    Print("No price error#",GetLastError());
    return;
   }
  Print(myprice.ask);

OOP in MQL5 by Example: Processing Warning and Error Codes
OOP in MQL5 by Example: Processing Warning and Error Codes
  • 2010.05.26
  • KlimMalgin
  • www.mql5.com
The article describes an example of creating a class for working with the trade server return codes and all the errors that occur during the MQL-program run. Read the article, and you will learn how to work with classes and objects in MQL5. At the same time, this is a convenient tool for handling errors; and you can further change this tool according to your specific needs.
 
BigAl:

I have this code in my EA and I am puzzled by the results. Please can someone tell me where my thinking is wrong as I thought that this should load the current chart prices etc. or if it failed print the error statement and error code. It normally prints the ask price correctly and has never printed the error message and error code, however, every few days prints the price as 0.0. what am I doing or thinking wrong

If you just need print Ask use this:

MqlTick last_tick;
SymbolInfoTick(_Symbol,last_tick);
double Ask=last_tick.ask;
Print ("Ask=",DoubleToString(Ask,_Digits));
See the article Migration from MQL4 to MQL5, 3. Predefined Variables.
 
paladin800:

If you just need print Ask use this:

See the article Migration from MQL4 to MQL5, 3. Predefined Variables.

Thanks for that it was useful, however, I do want to use the value immediately at this part of the EA. The print was to prove to myself myprice.ask was actually 0.0

I just can not understand how myprice.ask can be zero immediately after calling SymbolInfoTick(_Symbol, myprice) or in your code SymbolInfoTick(_Symbol, last_tick)

Am I missing something or is this a BUG!

If it is a bug, does anyone know how to report it please.

 
BigAl:

Thanks for that it was useful, however, I do want to use the value immediately at this part of the EA. The print was to prove to myself myprice.ask was actually 0.0

I just can not understand how myprice.ask can be zero immediately after calling SymbolInfoTick(_Symbol, myprice) or in your code SymbolInfoTick(_Symbol, last_tick)

Am I missing something or is this a BUG!

If it is a bug, does anyone know how to report it please.

1. If you want to report, you can report to Service Desk. Just go to your profile by clicking your username and look for Service Desk on the left side.

2. Since you say this "It normally prints the ask price correctly and has never printed the error message and error code, however, every few days prints the price as 0.0. what am I doing or thinking wrong" . What broker does your MT5 use ? Try another broker - by adding new broker like click this one and see if the error still occur.

3. For Vista/7/8, we usually install MT outside C:\Program\Files, like C:\My other program\... or whatever. See if that also help

 
phi.nuts:

1. If you want to report, you can report to Service Desk. Just go to your profile by clicking your username and look for Service Desk on the left side.

2. Since you say this "It normally prints the ask price correctly and has never printed the error message and error code, however, every few days prints the price as 0.0. what am I doing or thinking wrong" . What broker does your MT5 use ? Try another broker - by adding new broker like click this one and see if the error still occur.

3. For Vista/7/8, we usually install MT outside C:\Program\Files, like C:\My other program\... or whatever. See if that also help

Thanks for the info - will try your suggestions and if all fails will go to the service desk.
 

Hi,

Interesting that you've got this problem with SymbolInfoTick(), as I'm experiencing exactly the same problem with SymbolInfoDouble(). I was also recommended to go to a different broker which for me is out of the question. So I use the following function to determine any problems and if there are problems, exit and wait for the next tick:

// Gets SymbolInfoDouble and checks for data validity...
double getSymbolInfoDouble(string symbol, ENUM_SYMBOL_INFO_DOUBLE requiredInfo) {

    // If the Expert is being tested or optimised, simply return the requested value - otherwise,
    // validate the data...
    double returnDouble;
    if (MQL5InfoInteger(MQL5_TESTING) || MQL5InfoInteger(MQL5_TESTER) || MQL5InfoInteger(MQL5_OPTIMIZATION))
        returnDouble = SymbolInfoDouble(symbol, requiredInfo);

    else {  
        // Check Symbol validity...
        if (! checkSymbolValidity(symbol))
            return(-1);

        // Enable the required Symbol in the MarketWatch window (can't get Symbol data
        // without doing this...)
        if (! enableSymbolInMarketWatchWindow(symbol)) 
            return(-1);

        // Get the required info and normalize...
        bool errorOccurred = false;
        bool result = SymbolInfoDouble(symbol, requiredInfo, returnDouble);
        if (! result) {
            SetUserError(GET_SYMBOL_INFO_DOUBLE_1);
            errorOccurred = true;
        }    

        // Check to make sure that the info actually contains something useful...
        if (errorOccurred == false && returnDouble <= 0) {
            SetUserError(GET_SYMBOL_INFO_DOUBLE_2);
            errorOccurred = true;
        }

        if (errorOccurred) {
            string description = "";
            switch (requiredInfo) {
                case(SYMBOL_BID):           description = "SYMBOL_BID"; break;
                case(SYMBOL_ASK):           description = "SYMBOL_ASK"; break;
                case(SYMBOL_POINT):         description = "SYMBOL_POINT"; break;
                case(SYMBOL_VOLUME_MIN):    description = "SYMBOL_VOLUME_MIN"; break;
                case(SYMBOL_VOLUME_STEP):   description = "SYMBOL_VOLUME_STEP"; break;
                default:                    description = "NO_DESCRIPTION_AVAILABLE"; break;
            }

            setErrorDetails(symbol + ":" + description + " = " + returnDouble);
            return(-1);
        }
    }    

    // Normalize...
    // DIGITS MUST BE RETRIEVED IN THIS MANNER AS 'symbol' COULD BE
    // ANY SYMBOL - NOT JUST THE CHART ONE.
    long digits;
    bool result = SymbolInfoInteger(symbol, SYMBOL_DIGITS, digits);
    if (! result) {
        SetUserError(GET_SYMBOL_INFO_DOUBLE_3);
        setErrorDetails(symbol);
        return(-1);
    }

    return(NormalizeDouble(returnDouble, digits));
}

I don't know if you reported this problem? I've currently got a thread going with the Service Desk re: this issue. Apart from being asked to try a few things, I haven't receive any real answers as yet though...

 
cowil:

Hi,

Interesting that you've got this problem with SymbolInfoTick(), as I'm experiencing exactly the same problem with SymbolInfoDouble(). I was also recommended to go to a different broker which for me is out of the question. So I use the following function to determine any problems and if there are problems, exit and wait for the next tick:

I don't know if you reported this problem? I've currently got a thread going with the Service Desk re: this issue. Apart from being asked to try a few things, I haven't receive any real answers as yet though...

Perhaps you should use GetLastError() instead creating user defined error .
 
cowil:

Hi,

Interesting that you've got this problem with SymbolInfoTick(), as I'm experiencing exactly the same problem with SymbolInfoDouble(). I was also recommended to go to a different broker which for me is out of the question. So I use the following function to determine any problems and if there are problems, exit and wait for the next tick:

I don't know if you reported this problem? I've currently got a thread going with the Service Desk re: this issue. Apart from being asked to try a few things, I haven't receive any real answers as yet though...

Thanks for the info very useful. I have noticed that when the demo system opens for trading on a sunday I get a 0 price when my EA starts executing. however, the third tick seems to be safe. In addition, if the demo system restarts during the week I get the same problem.
 
BigAl:
Thanks for the info very useful. I have noticed that when the demo system opens for trading on a sunday I get a 0 price when my EA starts executing. however, the third tick seems to be safe. In addition, if the demo system restarts during the week I get the same problem.

Simply add this to your OnTick() :

    if(!SymbolInfoTick(_Symbol, tick)) return;

Apparently, a tick is generate not only when bid or ask change. Is the market close or open when you receive an ask price of 0 ?

 
angevoyageur:

Simply at this to your OnTick() :

Apparently, a tick is generate not only when bid or ask change. Is the market close or open when you receive an ask price of 0 ?

Sorry but I am not exactly sure - but I think it happens AS the market is opening
 
Alain Verleyen #:

Simply add this to your OnTick() :

Apparently, a tick is generate not only when bid or ask change. Is the market close or open when you receive an ask price of 0 ?

That return statement really made sense to abandon the tick and wait for a better one.