Code snippets

 

A thread for some code snippets (functions and similar) that will work with this new metatrader 4

 

A time filter that will for any case of time limitation. It is an overloaded function (to call it using just hours, hours and minutes or hours, minutes and seconds). It will not work with old builds of metatrader. Works with new metatrader 4 and metatrader 5. Handles all the time combination cases within a day with no problem

_time_filter.mq4

Seeing how easy is to overload a function, look at the way how IndicatorSetInteger(), IndicatorSetDouble() and IndicatorSetString (and all sort of similar cases are made) and try to guess why was it necessary to make 3 different calling ways when it could simply be overloaded

Files:
 

A function that can automatically find out a prefix and / or suffix used by broker.

It assumes that broker has EURUSD in his symbols (otherwise it will return error).

Also, I have seen that some brokers are using suffix or prefix for forex symbols while they are not using it for rest (CFDs, Futures and CFD for indices), in which case suffix or prefix should be searched only for symbols that get 0 as a return from MarketInfo(Symbol(), MODE_PROFITCALCMODE) - forex symbols

_automatic_suffix_and_prefix.mq4
 

I like the idea

KimIV used to do that for old metatrader. We need something like that for the new one

 
whisperer:
I like the idea KimIV used to do that for old metatrader. We need something like that for the new one

KinIV did a great job

Pity that they did not keep him at metaquotes instead of some moderators that have no idea what are they talking about. Anyway, we are going to have snippets compatible with this new mql here. Seems that they are needed

 

A very simple way to calculate NonLag MA + it is suitable to calculate values of anything (without distorting the oldest bars calculated - in that case it simply adapts to available bars and calculates just as many bars as it is available - like on the example picture)

_nonlag_ma.mq4
Files:
nlm.gif  75 kb
 

During the testing of this new metatrader 4, by try and error, came to conclusion that maximal number of buffers is 128

Here is one example that shows how those 128 buffers can be used in a very simple way (the start() - or OnCalculate() - function has in effect only 4 lines of code to draw maximum 128 values on chart)

_128_buffers.mq4

Files:
 

For people using momentum :

Momentum is a very useful indicator. But probably the biggest problem it has is that it can create a lot of false signals simply because it is not smooth. This is one way how it can be solved without adding any lag at all (on the contrary : in some cases it is faster than momentum). Here is a comparison : red is the soothed momentum, blue is the regular momentum (same period, same price)

_smoothed_momentum.mq4

and, as a plus, it can be applied to any value (not just price)

Files:
 

There is something wrong with the last link, Smoothed momentum couldn't be downloaded. I've tested my browser with other links from this page, they are working fine.

 
zefx:
There is something wrong with the last link, Smoothed momentum couldn't be downloaded. I've tested my browser with other links from this page, they are working fine.

Zefx, just tried it and it worked for me.

 
zefx:
There is something wrong with the last link, Smoothed momentum couldn't be downloaded. I've tested my browser with other links from this page, they are working fine.

No problem for me either

Reason: