Sorry if I have posted it to the wrong forum, please feel free to move it to the right one.
You have posted to a correct forum.
Problem is, that you misunderstand the return value of SymbolInfoTick. It returns true in normal operation, so the second operand in your logical expression gets never invoked.
if(SymbolInfoTick(SYMB1,last_tick1)|| SymbolInfoTick(SYMB2,last_tick2))
You have posted to a correct forum.
Problem is, that you misunderstand the return value of SymbolInfoTick. It returns true in normal operation, so the second operand in your logical expression gets never invoked.
May be you are right Ovo but it seems my problem is with OnTick events more than with anything else.
This event is just not triggered for the second symbol and it seems to work only for active chart and one symbol only. I have rewritten my code a bit and I can get bid/ask for each symbol but since OnTick works only on one of them the bid and the ask for the second one are only updated when there is tick on the first one and either the bid or the ask for the second one have been changed between two ticks on the first one. Since I am testing it currently on OIL futures and these markets are very busy during their trading sessions these problems with the second symbol do not bother me too much. However for something less busy I will need to find a way to get updated bids and asks every time they are changed and no matter how many symbols I want to check at the same time.
May be you are right Ovo but it seems my problem is with OnTick events more than with anything else.
This event is just not triggered for the second symbol and it seems to work only for active chart and one symbol only. I have rewritten my code a bit and I can get bid/ask for each symbol but since OnTick works only on one of them the bid and the ask for the second one are only updated when there is tick on the first one and either the bid or the ask for the second one have been changed between two ticks on the first one. Since I am testing it currently on OIL futures and these markets are very busy during their trading sessions these problems with the second symbol do not bother me too much. However for something less busy I will need to find a way to get updated bids and asks every time they are changed and no matter how many symbols I want to check at the same time.
OnTick() is only generated for the symbol of the chart you are running your code. Please read the documentation.
See this article : https://www.mql5.com/en/articles/234
Don't worry about whether the other symbol has changed. When you get a new tick, you know the current pair has changed.
Look at other pair if you must. (Don't assume that Time[i] == iTime(otherPair,tf, i) always use iBarShift.)
Don't trade other pairs. You can't use any predefined variables, must poll other pairs, and can't use the tester.
Code your EA to trade just the current pair, then put it on multiple charts.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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 a spreadsheet/text file so I can see a history data or current trading data.
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?