![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
Hi guys,
I did some programming for metatrader before but it was a few years ago. Now I am back and I have MT5 and I want to build a robot for myself for arbitrage trading. But first I just want to test and get all required values and then use them in either a graph format or just as a spreadsheet/text file so I can see a history data or current trading data and analyze it.
The problem is I need to work with bid/ask values for two symbols at the same time so in every tick in any of two symbols that I am interested in I can do some simple calculation between bid of one symbol and ask of the other and vice versa. I have tried expert adviser sample code and added and modified some code with OnTick Event but it seems I am only getting data from a symbol the adviser is running on. Here is a code
void OnTick()
{
MqlTick last_tick1;
MqlTick last_tick2;
double spreadBuy;
double spreadSell;
//---
if(SymbolInfoTick(SYMB1,last_tick1)|| SymbolInfoTick(SYMB2,last_tick2))
{
spreadBuy=last_tick1.ask-last_tick2.bid;
spreadSell=last_tick2.bid-last_tick1.ask;
//Print(last_tick1.time,": Bid = ",last_tick1.bid, " Ask = ",last_tick1.ask);
Print(last_tick1.time,": Sell = ",spreadSell, ": Buy = ",spreadBuy);
}
else Print("SymbolInfoTick() failed, error = ",GetLastError());
//---
}
SYMB1 and SYMB2 are just a string variables that are in fact symbols codes.
Is there any way I can get the onTick event triggering on two symbols at the same time?
If not, how can I do what I want? I guess I can run two expert advisers(one on each symbol), storing all acquired data in the same file and then analyzing it. Is there any other simpler way?