MQL4 and error 4106 with gold

 

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. ONLY ON SOME BROKERS, when trying to execute orders on gold, I get error 4106 unknown symbol. 

Symbol is visible in marketwatch, and if I try to open manually it works fine. 

bool SymbolExists(string symbol)
{
   RefreshRates();

        // if symbol is not recognized
        if( SymbolInfoDouble(symbol,SYMBOL_BID) <= 0 ||
           SymbolInfoInteger(symbol, SYMBOL_TRADE_MODE) == SYMBOL_TRADE_MODE_DISABLED )
           {
              // I retry using another function
              MqlTick tick;
              double valuebid;
              ResetLastError();
              if( SymbolInfoTick(symbol,tick) ){             
                  valuebid = tick.bid;
                  Print("Ritento, "+ symbol + " " + DoubleToStr(valuebid) );
                  return true;
              } else {
                  PrintFormat("%s: Error: %d",__FUNCTION__, GetLastError());
                  return false;
              }
           }
        else return true;
    }


I always try both with SymbolInfoDouble and retry with SymbolInfoTick if it fails. 

Any idea why there's such a behavior only on some brokers?

thanks

 

Your posted code works with the passed symbol; irrevalent. You are passing an invalid symbol.

Are you sure it is visible?

Broker's use a variety of naming patterns: EURUSD, EURUSDc, EURUSDct, EURUSDecn, EURUSDi, EURUSDm, EURUSDme, EURUSDpro, EURUSDt, "EUR.USD", "EUR/USD", "EURUSD!", "EURUSD#", "EURUSD.", "EURUSD..", "EURUSD.c", "EURUSD.cfx", "EURUSD.G", "EURUSD.i", "EURUSD.r", "EURUSD.SBe", "EURUSD.stp", "EURUSD+", "EURUSD-5", "EURUSD-m", "EURUSD-sb", etc., Financial symbols with '-', '=', '_' and '+'

If the pattern your broker uses doesn't match the pattern of your signal provider's broker, you can't copy the signal/open a trade.

If the naming pattern of your charts isn't exactly "BasQuo" then hard coded symbols fails.

Don't hard code things; just use the predefined _Symbol, or remove the adornments during processing.

 

thank you for your answer William. 

It's a multi-currency EA, so I have to pass it "hardcoded". But I double checked, it's nothing fancy, I tried to execute XAUUSD and in the marketwatch there's XAUUSD.


I'm 100% sure it's visible, it's the first thing I checked. 

Then I also made sure there are no suffixes or prefixes in the name. 


The strange thing is that same EA, same broker, works fine in demo account and not in real (Icmarket and bdswiss for example). 


I'm starting to doubt that it's a broker's limitation on trading gold with EA, even if it sounds very strange.