Search code examples
mql4metatrader4

Market info (spread) returns 0 when executed for different symbol


I'm coding an expert advisor on windows 10 with metatrader4.

My code:
I'm iterating through all symbols to get their spreads.

// for(i...
string name = SymbolName(i, false)
double spread = MarketInfo(name, MODE_SPREAD);

Print("Symbol " + name + ": " + DoubleToStr(spread, 4));

Testing env:
I'm using the strategy-tester aka backtester which has to be set to a specific symbol. In my case I've set it to AUDUSD.

My unexpected output (journal):

// everything else is also 0.0000
Symbol EUREUC: 0.0000
Symbol EURCHF: 0.0000
Symbol EURCAD: 0.0000
Symbol EURAUD: 0.0000
Symbol CHFJPY: 0.0000
Symbol CADJPY: 0.0000
Symbol CADCHF: 0.0000
Symbol AUDUSD: 24.0000
Symbol AUDNZD: 0.0000
Symbol AUDJPY: 0.0000
Symbol AUDCHF: 0.0000
Symbol AUDCAD: 0.0000

The problem:
As you can see the only spread I get is the one from AUDUSD, the symbol I've set the strategy-tester to work on. Is there any chance to get the spread for different symbols than the one I've set the tester to?

I've tried it with different symbols. I'm always getting the spread for the selected one, but no spreads for all others.

Thank you very much!


Solution

  • MT4:

    Only single-currency testing is allowed. Multitimeframe testing is allowed. There is no limitation in real time (e.g., you can compute the dollar index and display it in the indicator window).

    MT5:

    No limitations at all, both single currency and multi-currency testing is allowed, same in real time. Do not forget to bool result=SymbolSelect( symbol[i], true); for all the currencies you need at start of the test. If result is false - most likely you've forgotten about suffix or have a typo. Visually you will have the main chart (the one selected in Tester - Symbol & Tf) but other charts are available on the next charts in tester.

    Is it difficult to switch from MT4 to MT5? It depends.
    It seems like it is more headache with indicators (MT4: arrays are set as series so close[0] is current bid, MT5: vice versa so time[0] is the earliest known date); in such a case you need to set both series as true or false all the time, and some more inconveniences there.
    Another problem might be if you use an MT4 indicator or library and you do not have source code of it. Nobody is to help you in such a case, I am afraid.
    If using DLLs, keep in mind MT4 is 86x-, MT5 is 64x- based architecture.
    For expert advisors a special library MT4Orders.mqh by fxsaber can be downloaded at the official website in codebase section and then write in MT4-style.