Different method to write data to csv, is it valid?

 

Hi, I've found 2 method to write a data to csv. The first one is to do it like this,

void OnTick() {
        FileOpen(...);
        FileWrite(...);
        FileClose(...);
}

The other method is like this,

int OnInit() {
        FileOpen(...);
}

void OnTick() {
        FileWrite(...);
}

void OnDeinit() {
        FileClose(...);
}

I want to write a trade result for when I backtest a strategy or when the EA runs in live trading. I already have a code to run for backtesting and trying to create a new one that can be used for those purpose. I found the second method somewhere in the web and I kind of understand why the function is called in different event handler. Using the second method will make the file always open and be ready to be written but I don't know if there's a problem of doing so. I just want to clarify the second method is valid to use or not.

Thank you

Testing trading strategies on real ticks
Testing trading strategies on real ticks
  • www.mql5.com
The article provides the results of testing a simple trading strategy in three modes: "1 minute OHLC", "Every tick" and "Every tick based on real ticks" using actual historical data.