whitebear
whitebear

Reputation: 12433

Getting data from multiple Charts

I am trying to make a script getting data from multiple Charts on MT4.

I would like to get data from multiple Charts.

Such as getting today's MACD from EUR/USD and GBP/USD, then comparing two numbers.

Is it possible to handle multiple charts in the same script???

Upvotes: 1

Views: 2498

Answers (2)

Ian Ash
Ian Ash

Reputation: 1212

Yes it is possible using the iClose(), iOpen(), iHigh() and iLow() functions. In addition, there are functions to access most common indicators in a similar way: iADX(), iMACD(), iMA(), iMFI(), iMomentum() to name a few - see the MT4 docs for the full list.

For example, if your provider has an instrument named SP500_SB, then you can access the data from that chart using the following line of code without your code being attached to that chart.

iClose( "SP500_SB", Period(), 0 );

The first parameter is obviously the instrument name.

The second parameter is the timeframe you want to access, e.g. 5 min bars, 10 min bars, etc. In the code snippet above, the call will use whatever timeframe that is being used for the chart to which the script was attached.

The final parameter is an index into that data, i.e. in the above example read the first value in the list.

A big limitation (IMO) is that the Strategy Tester does not support accessing data outside of the attached chart, so you can't run multi-instrument code in the Strategy Tester which makes debugging and testing multi-instrument indicators or Expert Advisors really difficult.

Upvotes: 1

user3666197
user3666197

Reputation: 1

Yes, it is possible:

MetaTrader Terminal 4 uses a concept of running a particular piece of code "attached-on" the GUI-graph native-data, but recently there became several new functions ready to serve what you have asked for.

As requested, the MACD on "non-native" -- both EURUSD and GBPUSD -- independently of what is the "native" GUI-graph the script was launched at, one may use:

double aTodayMACDonEURUSD = iMACD( "EURUSD", PERIOD_D1, fEMA, sEMA, aSIG, PRICE_CLOSE, MODE_MAIN, 0 ),
       aTodayMACDonGBPUSD = iMACD( "GBPUSD", PERIOD_D1, fEMA, sEMA, aSIG, PRICE_CLOSE, MODE_MAIN, 0 );

using the call-interface signature details as documented:

double  iMACD( string       symbol,           // symbol
               int          timeframe,        // timeframe
               int          fast_ema_period,  // Fast EMA period
               int          slow_ema_period,  // Slow EMA period
               int          signal_period,    // Signal line period
               int          applied_price,    // applied price
               int          mode,             // line index
               int          shift             // shift
               );

This simply works, if your symbol strings do match the actual currency-pairs' names, as were defined by your FX Broker's Terms & Conditions.

Do not hesitate to ask more.

Upvotes: 1

Related Questions