Friday, October 16, 2009

My first MQL5 coding impressions

MQL5 is in beta test, and I've been playing around with it for a few hours to see what it's like.  It's great fun, and I can see the enormous potential for MetaTrader 5.

I know MetaTrader 4 backwards, and am also reasonably experienced in C++, but there is much in MQL5 that needs to be learnt.  The trading functions are completely different, and so is the coding of indicators.  It's not particularly useful to import MQL4 code into the MQL5 editor and attempt to convert it inline because the conversion needs to touch on the entire coding structure.  The search is on for the equivalents to anything that doesn't exist, like IsOptimization() or TimeToStr().  Other functions exist but need to be used differently, like StringConcatenate.

I guess one could write a whole lot of pseudo MT4 function calls such as this
bool IsTesting()
{
  return(MQL5_TESTING);
}

This may assist in converting MQL4 code, but it's probably simpler to re-write the simpler ones.

A startling change is that all inbuilt indicators return a handle, not a value. This handle is then used to copy results to an array. The reason for this is to make it easier and more efficient to code indicators of indicators.

Here's my first indicator.  The new concept in indicators is OnCalculate(), which is called for each new tick.  For some weird reason the arrays in OnCalculate are from left to right.  This indicator I wrote shows a fast and slow Fractal Moving Average (FRAMA) and places arrows at the open of each bar following an MA cross event.

I'm now working thorugh the complexities of which bar is which to use this indicator to control an Expert Advisor.

Here's a useful MQH include file which converts error codes and OrderSend results to strings.

2 comments:

  1. I would like to advise that you use the best Forex broker: AvaTrade.

    ReplyDelete
  2. Forex trading is much more easier when its done by a forex robot and EA Builder allows you to create your own free expert advisor.

    ReplyDelete