FileWrite() Question | Please Help

 

Hello Forum,

I am trying to modify one of the more common files out there that creates a .csv file and dumps it to the file system. The dump works fine, but I want to change what gets dumped. I trade all six (6) major JPY pairs in a basket. I have a couple .mql files that dump iCustom history data to the file system where I then link to it through Excel - all that works just fine.

I would now like to dump OHLC data into a single .csv file for all six (6) pairs using just one .mql file. I can already do this using iCustom with no problem. But, I don't seem to understand the syntax for using iOpen(), iHigh(), iLow() and iClose(), such that I am able to specify the number of bars to dump in each pair.

For each JPY pair, I need to dump the most recent into a .csv file:

800 bars of M1 OHLC

1 bar of M5 OHLC

1 bar of 15 OHLC

1 bar of 30 OHLC

80 bars of H1 OHLC

1 bar of H4 OHLC

1 bar of D1 OHLC

1 bar of W1 OHLC

1 bar of MN1 OHLC

Here's the code segment of the Filewrite() that I'm having problems with:

// Dumps 800 rows of M1 OHLC

FileWrite(handle, iOpen("GBPJPY",PERIOD_M1,i));

This does work and it dumps the number of bars specified by the external variable, which is an integer called NumBars. The problem is that, if I enter a value for the variable NumBars when the indicator is loaded to the chart, the indicator will dump that same number of bars for each timeframe and that is not what I need.

As you can see above, I need a different number of bars for each timeframe. So, I need a way to specify the number of bars to dump, somewhere inside the Filewrite() itself. I tried the following:

FileWrite(handle,

iOpen("GBPJPY",PERIOD_M1,800),

iOpen("GBPJPY",PERIOD_M5,1),

iOpen("GBPJPY",PERIOD_M15,1),

iOpen("GBPJPY",PERIOD_M30,1),

iOpen("GBPJPY",PERIOD_H1,80),

iOpen("GBPJPY",PERIOD_H4,1),

iOpen("GBPJPY",PERIOD_D1,1),

iOpen("GBPJPY",PERIOD_W1,1),

iOpen("GBPJPY",PERIOD_MN,1));

Of course, this did not work. The character in the i() function is seen by MQL as the number of bars to offset, not the number of bars to dump. So, how do I get these i() functions (open, high, low and close) to dump a specific number of history bars, instead of always looking at external variable NumBars?

Thanks for the help!

Reason: