• Join us

Advice and examples of MQL5 code using Standard Libray CIndicator and CTrade classes

To add comments, please log in or register


I'm trying to write the simplest EA in MQL5 and it's really not a fun experience.

Firstly I tried to write the EA from the ground up and find it incredibly cumbersome to do even the simplest things, for example to get a couple of prices:

      // get yesterday's open and close price     

      MqlRates rates[]; 

      int copied=CopyRates(TradeSymbol,TimeFrame,1+Shift,1,rates); // Always use 1+PeriodShift. 1 means we get yesterday's close (not current). PeriodShift gives optional extra lag



I do understand this is not the best way to get the prices, but I've seen it offered as a solution..

Or to get the value of a couple of moving averages:

      int handleMovAverageShortClose=iMA(TradeSymbol,TimeFrame,signalShortPeriod,1+PeriodShift,MODE_SMA,PRICE_CLOSE);   // note shift is 1 to retrieve yesterday close value       

      int handleMovAverageShortClosePreviousDay=iMA(TradeSymbol,TimeFrame,signalShortPeriod,2+PeriodShift,MODE_SMA,PRICE_CLOSE);   // note shift is 2 to retrieve day before yesterday close value                

      movAverageShortClose=GetIndicatorCurrentValue(handleMovAverageShortClose); // custom function to get the first value of the time series


Then I thought maybe the canned MT5 EA generation wizard might help, at the least by providing some working examples. This was a big mistake - the "simplifying" automatic EA generation wizard is a disaster because it produces code that is basically unreadable and impossible to modify. It's not even a useful learning experience. Does anyone use the bizarre Expert and Signal classes? Likewise with most of the articles on MQL5.com. These are poorly translated and claim to be logical and straightforward but rapidly vanish into a load of unnecessary, incomprehensible or pointless detail.

So now I'm back to building from the ground up.

This is made harder by there being no useful documentation or examples that I've found of some of the standard library classes that LOOK like they might be helpful. Even the function reference pages don't include a single example under the function definition.

Another gripe: the debugger is primitive, the backtesting debugging is terrible, the graphical display of trades and signals makes it incredibly hard to visualize the decisions of your code.

I'm posting this for two reasons. One is simply to see if I'm just missing the point, or do many other people experience the same issues.

Secondly, can anyone point me at some simple working examples using the standard library classes (CIndicator, CiClose, CSymbolInfo) to do basic things with market data (things I consider basic anyway and do all the time in other platforms).

Such as: retrieve a single price, retrieve an array of prices between two dates, divide a series of prices by another, retrieve a series of moving average prices, and do these things in an efficient way.


Sergey Golubev
Sergey Golubev  

Use Code Button to post a code or the part of the code (otherwise it is very difficult to read the text for example) - 

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button

Thank you.

To add comments, please log in or register