Things Coders' Guru Never Taught Me

 

INTRODUCTION

I have learned a few things after thousands of hours fighting with MQL4 and I want to share some of it. Here is my qualifications: I am not a professional programmer but have written an EA that is 20 or 30 pages long. And yet it will backtest (on H1 with 1 minute data, on Ticks) in under 1 minute per year or about 100 trades. Also, after six months of forward (demo) testing and debugging it takes and closes trades exactly when and how it should.

If you have a good clear explanation of some part of Metatrader that the following sources do not explain well enough, this is the place to post it. Like WHEN or WHY or HOW you would use / not use some command or code or section. Give examples.

This thread is NOT, I repeat NOT to answer questions that are contained in one of the following areas:

Coders' Guru's lessons. MetaEditor help files. Metatrader help files. Search Forex-TSD threads especially “How to Code?”and “Ask!”. Do your homework, don't ask me!

If you post code, be a Pro: TEST IT FIRST to make sure it exactly does what you say.

There is little more frustrating to a new coder than solutions with bugs in them!

This is not the place for obscure tricks that only 0.1% of programs need.

It is not the place for how to use Metatrader.

It IS the place for widely useful programming insights.

Big Be

 

Nice thread Big Be.

Lots of useful information here for beginners, even useful to some who have coding experience.

 

ya well done

seriously, please tell us

about the guideline to DEBUG with IDE like Visual studio, eclipse

beside starting the few function is difficult, these IDE got developed over the years, make it really hard to modify any existing program esp the ex-programmers (IT people) are not as NICE and INFORMATIVE to other progremmers by hiding lots of comment -- i.e. the most difficult bit is searching (narrow down) the code that you are looking for [[ you mentioned print the variable value in this thread --- to assist debug/ understanding the code ]]

we will read your initiated thread again and hope to learn more programming , from you -- nice work !

 

Thank you wolfe, thank you xx3xxx.

It would be nice to have an IDE (interactive [or integrated] development environment).

I hope other coders add to this thread.

I don't know it all but I will add when I can.

 

Hi, Just pointing out that tip #19 is incorrect. The result will be a double.

 

Tested and confirmed. Changed #19. Thank you John.

 

Nice thread , can you give any more input on how to optimize code for working faster and more efficient? Im not doubting you but how can you have 25 "pages" of code run a full year worth of tick data in 1 min? Are DLL's involved?

It seems like you have another trick up your sleeve other then what you've already posted in regards to speed.

 

Wow nice! there was some very valuable information there that i had not thought about before..

Thanks for taking the time to share that and be so detailed, it's much appreciated.

Again thank you very much..

-Gmax111

 

How to Speed up your Metrader Program

gmax111,

Hmmm... I guess if I know a few things you don't know, I should bundle them up and call them “Programmer Guru Secrets”, and charge $97 a head. :-)

Seriously, your question was good, it prompted me to write another post:

It's largely a matter of being logical and exercising THOUGHT. (Oh no! Not that!)

1. Anything that does not need to be calculated or called every tick, should not be allowed to. Read the last third of Post 3, starting “Another potential problem...”

2. When putting together a sequence of conditions ("if" statements) or a sequence of filters (functions) -- for example entry filters, put the one first that is least often true. Put the one last that is most often true. As soon as a condition or filter is false, it should stop checking the rest. This way the program will not spend time checking conditions or filters any more often than really necessary. Estimate the others, from your knowledge of your program and charted results, and sequence them in between.

3. If two items are about equal, put the one with the least iCustom variable calls first.

4. Each filter should, after the initial direction has been established, check only for Long or Short trades, not both.

5. Some indicators are extremely inefficient and run from beginning to end every time called (every tick). A poorly written indicator can slow down your Expert Advisor 100 times or more. Of course they should use the “IndicatorCounted” code.

If it has a continuously incremented value that is vital, you may have to use code which remembers the key variables. This article explains how:

"Multiple Null Bar Re-Count in Some Indicators"

At: Multiple Null Bar Re-Count in Some Indicators - MQL4 Articles

You may have to re-study it a few times to understand it, then try it.

6. Don't check exit conditions if 0 trades are open. (If OrdersTotal() == 0).

Big Be

 

Hi

Pls, I'd like you to tell how to speed up the strategy tester for my EA.

Once my EA has been triggered on a certain bar, it cannot be triggered again on that same bar. So, how can I stop it from analysing my EA (and maybe, sprint off to the next bar) once a trade has been triggered on that bar (while using the tick mode on the strategy tester)?

Does, for example, including the function "Sleep" in the code make this happen?

Thanks.

Jim.

 

Sleep might work, but see Post 3.

Big Be

Reason: