Please show your code attempt.
// Simple example #include <Trade\SymbolInfo.mqh> void OnStart() { CSymbolInfo oSymbol; if( oSymbol.Name( "EURUSD" ) ) { oSymbol.Refresh(); // do something }; };
Alain Verleyen #:
Please show your code attempt.
Please show your code attempt.
#include <Trade\SymbolInfo.mqh> CSymbolInfo ChartInfo; //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick(void) { ChartInfo.Name(Symbol()); ChartInfo.Refresh(); double ask = ChartInfo.Ask(); double bid = ChartInfo.Bid(); Print("Ask: ",ask," Bid: ",bid); }
It always returns zero. I haven't tried other functions yet
Kurren Kidd #:It always returns zero. I haven't tried other functions yet
You are not checking the return value from the Name method to check if it succeeded or not ...
Also, you need to use RefreshRates for the Ask and Bid.// Sample code #include <Trade\SymbolInfo.mqh> void OnStart() { CSymbolInfo oSymbol; if( oSymbol.Name( _Symbol ) ) { oSymbol.RefreshRates(); double dbAsk = oSymbol.Ask(), dbBid = oSymbol.Bid(); Print( "Ask: ", dbAsk, " Bid: ", dbBid ); }; };
2023.05.15 20:43:32.700 TestTicks (EURUSD,H1) Ask: 1.08763 Bid: 1.08762
Fernando Carreiro #:
You are not checking the return value from the Name method to check if it succeeded or not ...
Also, you need to use RefreshRates for the Ask and Bid.Thank you too! This was driving me nuts

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I've read the documentation and I understand you need to select a symbol using the Name method in order to use any of the functions of CSymbolInfo. What I don't understand is how to do that. Every function in the documentation says:
When I click on that all I get is:
Sorry if this is an obvious answer. A simple example would be great. Thank you for any help