Best practices for coding MQ5 Indicators

 

Hi,

I just wanted to know if any experienced developer has made post / topic about best practices and patterns about creating Indicators.

Since information about EA/MQL5/Indicator is spread out across forum posts/articles/MQL5 documentation, I thought someone may already have created post about best practices that would enlighten about

- modularise code and how to manage variables which may be reused across different modules/classes

- facilitate easier testing within code

- improve performance of code in EA

- "watch out for this condition" and other warnings

- prevent edge conditions from breaking Indicators while functioning

- Unique aspects one has to take care of when dealing with different instruments - eg forex pairs to indices to commodities

- unique aspects one may have to account for , for different brokers

- other aspects that one learns only through hit and trial/ live running of EAs

- limitations 


If not perhaps experienced developers here can share their experience here. 

Thanks in advance!

Create Your Own Expert Advisor in MQL5 Wizard
Create Your Own Expert Advisor in MQL5 Wizard
  • www.mql5.com
The knowledge of programming languages is no longer a prerequisite for creating trading robots. Earlier lack of programming skills was an impassable obstacle to the implementation of one's own trading strategies, but with the emergence of the MQL5 Wizard, the situation radically changed. Novice traders can stop worrying because of the lack of programming experience - with the new Wizard, which allows you to generate Expert Advisor code, it is not necessary.
 

In general terms, there are no "best practices". The vast majority of coders here are not software developers and are usually self taught, so apply their own style and "practices". Also given that is trading, most tend to keep things to themselves.

Given that MQL is very similar to C and C++, you can however look into the "best practices" of coding C and C++ in general and apply it to MQL.

As for the specifics for Indicators and EAs, there are no "best practices". You will simply devise your own as you progress and gain experience while programming them.

 

As a side note, the following article aimed at Market products is also a good set of practices that should be applied to your own EAs as well ...

Articles

The checks a trading robot must pass before publication in the Market

MetaQuotes, 2016.08.01 09:30

Before any product is published in the Market, it must undergo compulsory preliminary checks in order to ensure a uniform quality standard. This article considers the most frequent errors made by developers in their technical indicators and trading robots. An also shows how to self-test a product before sending it to the Market.

 
Fernando Carreiro #:

As a side note, the following article aimed at Market products is also a good set of practices that should be applied to your own EAs as well ...


Thanks for this. 
I wonder what other developers have to add to this post about their experiences. 
 
Varun Maithani #:
Thanks for this. 
I wonder what other developers have to add to this post about their experiences. 

Your questions are too general. The answers are scattered in the forum. Unfortunately there is no easy way to find the good and useful topics which are drowned among thousands of repetitive, trivial or useless posts.

 
Varun Maithani #:
Thanks for this. 
I wonder what other developers have to add to this post about their experiences. 

As per my experience, the best practices of mql codes are pulbished in this user's publication

I used to write an incdicator in 2000 lines of codes but after exploring these codes I have been able to use best practice and covert my old codes of 2000 lines into 50 lines of code.

I think the best practice is to check for Errors, If something wrong happens then you would never know whats going wrong in indicator but if you write your code in a style which checks everything or inform errors then it is one of the example of writing code with best practice, example here is how noob coder writes code

ObjectCreate(chart_ID,name,OBJ_TEXT,sub_window,time,price);

Its valid but with good practice its written like this

  ResetLastError();
//--- create Text object
   if(!ObjectCreate(chart_ID,name,OBJ_TEXT,sub_window,time,price))
     {
      Print(__FUNCTION__,
            ": failed to create \"Text\" object! Error code = ",GetLastError());
      return(false);
     }
Vladimir Karputov
Vladimir Karputov
  • www.mql5.com
Профиль трейдера
 
Arpit T #:

As per my experience, the best practices of mql codes are pulbished in this user's publication

I used to write an incdicator in 2000 lines of codes but after exploring these codes I have been able to use best practice and covert my old codes of 2000 lines into 50 lines of code.

I think the best practice is to check for Errors, If something wrong happens then you would never know whats going wrong in indicator but if you write your code in a style which checks everything or inform errors then it is one of the example of writing code with best practice, example here is how noob coder writes code

Its valid but with good practice its written like this

Awesome, those articles will definitely help me improve my code. 
 
@Fernando Carriero
Just to clarify, my other thread(that was removed) was meant to be for EAs actually so it was not a duplicate thread. Originally this thread was only meant to be for Indicators as this forum subsection is for indicators. 
So i was expecting different suggestions /advice/articles for both of the different threads. 
Reason: