I go crazy - probably easy question ! Difference between 2 symbols

 

Hi,


i have a very simple question but i just can't figure it out. the syntax just doesn't work and i've already tried a lot of cominations.


i have two symbols in the market watch, the ws30m and the @YM.

so i want to calculate the spread:

double Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);   // i'm on the @YM - it's ok i get the ASK

double Ask2 = SymbolInfoDouble(_Symbol,SYMBOL_ASK);   // here i want to go with the WS30M

how to change the _Symbol or Symbol() with the WS30m - i tried so many combinations


difference = Ask - Ask2 ;  

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
To obtain the current market information there are several functions: SymbolInfoInteger(), SymbolInfoDouble() and SymbolInfoString(). The first parameter is the symbol name, the values of the second function parameter can be one of the identifiers of ENUM_SYMBOL_INFO_INTEGER, ENUM_SYMBOL_INFO_DOUBLE and ENUM_SYMBOL_INFO_STRING. Some symbols...
 

I have it...


double Ask2 = SymbolInfoDouble("WS30m",SYMBOL_BID);

   

epic fail - sorry

 

Another nifty way of doing this is to use the CSymbolInfo library and its functions. You would use something like this (not tested):

CSymbolInfo symbol;          //declare the symbol object

symbol.Name("Symbol1");      //select Symbol1
double Ask1 = symbol.Ask();  //get Ask Price

symbol.Name("Symbol2");      //select Symbol2
double Ask2 = symbol.Ask();  //get Ask Price

It's a bit easier to read and you can continue working on the symbol this way.

Also, I recommend not to call your variable Ask2 but then fill it with a bid price. Might hunt you further down the line.

Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 | //| Expert tick function                                             | //| test1                                                            |...
Reason: