SymbolInfoDouble(symbol_1, SYMBOL_BID) and SymbolInfoDouble(symbol_1, SYMBOL_ASK) return 0

 

When i use two code below, i get zero (0) return. I using it in OnTimer:

double bid = SymbolInfoDouble(symbol_1, SYMBOL_BID);
double ask = SymbolInfoDouble(symbol_1, SYMBOL_ASK);

This is my full code: 

void Make_Type_4(string symbol_1, double vol, string type_comment, int type_buy_sell, double sl, double tp, int iscloser)
  {
   if(acc == 1)
      symbol_1 += "c";
   else
      if(acc == 2)
         symbol_1 += "m";
   double bid = SymbolInfoDouble(symbol_1, SYMBOL_BID);
   double ask = SymbolInfoDouble(symbol_1, SYMBOL_ASK);
   double price_first = 0.0;
   double price_sl_first = 0.0;
   double price_tp = 0.0;
   if(type_buy_sell == OP_SELL)
     {
      price_first = bid;
      price_sl_first = ask + sl;
      price_tp = bid - tp;

     }
   else
      if(type_buy_sell==OP_BUY)
        {
         price_first = ask;
         price_sl_first = bid - sl;
         price_tp = ask + tp;
        }
   Print("Bid: " + bid + ", ask: " + ask);
   string comment = type_comment + "=";
   int k1 = 0;
   if(MarketInfo(symbol_1, MODE_TRADEALLOWED))
     {
      if(OrderSend(symbol_1, type_buy_sell, vol, price_first, 20, price_sl_first, price_tp, comment, 0,0, clrNONE)<0)
        {
         k1 = GetLastError();
         Print("Tao lenh loi. Ma loi: ", k1);
        }
     }
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void main_check()
  {
//Get request in my hosting
   response = requests.get(ngrok_link + "/getLast?server=" + sv + "&typetest=" + typeTest).text;
   while(response != "")
     {
      //Data processing
      countNothing = 0;
      countGet++;
      string s[];
      double vol = 0.01;
      Split_String(response, s);
      string symbol_t = s[1];
      //Create stop loss and take profit
      double nSL = StrToDouble(s[4]);
      double nTP = 0.0;
      if(typeTest == 3 || typeTest == 9)
         nTP = nSL * 0.5 + MarketInfo(symbol_t, MODE_SPREAD) * MarketInfo(symbol_t, MODE_POINT) * 0.5;
      else
         if(typeTest == 4 || typeTest == 10)
            nTP = nSL * 1 + MarketInfo(symbol_t, MODE_SPREAD) * MarketInfo(symbol_t, MODE_POINT) * 1;
         else
            if(typeTest == 5 || typeTest == 11)
               nTP = nSL * 1.5 + MarketInfo(symbol_t, MODE_SPREAD) * MarketInfo(symbol_t, MODE_POINT) * 1.5;
            else
               if(typeTest == 6 || typeTest == 12)
                  nTP = nSL * 2 + MarketInfo(symbol_t, MODE_SPREAD) * MarketInfo(symbol_t, MODE_POINT) * 2;
               else
                  if(typeTest == 7 || typeTest == 13)
                     nTP = nSL * 2.5 + MarketInfo(symbol_t, MODE_SPREAD) * MarketInfo(symbol_t, MODE_POINT) * 2.5;
                  else
                     if(typeTest == 8 || typeTest == 14)
                        nTP = nSL * 3 + MarketInfo(symbol_t, MODE_SPREAD) * MarketInfo(symbol_t, MODE_POINT) * 3;
      if(typeTest < 9)
         Make_Type_4(s[1], vol, s[2], s[3], nSL, nTP, s[5]);
      else
         Make_Type_4(s[1], vol, s[2], !StrToInteger(s[3]), nSL, nTP, s[5]);
     }
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   EventSetTimer(1);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTimer()
  {
   ResetLastError();
   if(Seconds() > 10 && Minute() % 5 == 0)
      main_check();
  }

This code get from 10-15 string (i call "command string") every 5 minute.

Example: String "1=XAUUSD=11*60=1=10.705=0" is set a order in case " XAUUSD", comment "11*60", type sell (1 is sell, 0 is buy), sl is  10.705 + Spread (see up code), tp is input (see up code)

When i run code, i see the 3-5 string first get 0 when call 2 code 

double bid = SymbolInfoDouble(symbol_1, SYMBOL_BID);
double ask = SymbolInfoDouble(symbol_1, SYMBOL_ASK);

After it, code run normal.

Any one have solution to fix it, thank you! 

 
Trần Thanh: When i run code, i see the 3-5 string first get 0 when call 2 code 
double bid = SymbolInfoDouble(symbol_1, SYMBOL_BID);
double ask = SymbolInfoDouble(symbol_1, SYMBOL_ASK);

  1. You didn't state what symbol_1 is. You didn't state what the current chart is. You didn't state that symbol_1 is in Market Watch.


  2.      How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

  3. You said it returns zero, but you didn't state what the error code is.

    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

  4. On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)

 
William Roeder #:
  1. You didn't state what symbol_1 is. You didn't state what the current chart is. You didn't state that symbol_1 is in Market Watch.


  2.      How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

  3. You said it returns zero, but you didn't state what the error code is.

    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

  4. On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)

Ok, after i check number 2, i think error in case XAUUSD. I will back soon after thinking fixed

MQL4 and error 4106 with gold
MQL4 and error 4106 with gold
  • 2020.09.04
  • www.mql5.com
Hi everybody, I'm having this problem since long time now, and I'm not able to find a solution. I'm not sure it's my software problem or broker's...
 

Yeah, i think solution is very simple.


The problem in symbol XAUUSD. I open XAUUSD in windows Market Watch and that is solution.

It is very easy.

Reason: