› Forums › Development › Coders Supporting Coders
This topic has been reported for inappropriate content
Tagged: new mq4 coding style
- This topic has 58 replies, 15 voices, and was last updated 7 years, 10 months ago by
simplex.
- AuthorPosts
- March 3, 2015 at 10:57 am #5279
Thanks brother. I have finally found the solution by setting the TIME2 to future time, instead of using Bar. I use buffer to hold the rectangle information, then draw it after that. Thanks, smallcat
Great!

A good trader is a realist who wants to grab a chunk from the body of a trend, leaving top- and bottom-fishing to people on an ego trip. (Dr. Alexander Elder)
May 18, 2015 at 6:15 pm #6739Hi Guys!
Any coder knows that case: you download an interesting source, double click, and … horror formatting!
This is when uncrustify enters the stage. Uncrustify is a configurable open source C++ code beautifier – see here: http://uncrustify.sourceforge.net/I’ve been asked by PM for my uncrustify MQL settings file. Currently I’m running version 0.6.0. You’ll find a newer version on their sourceforge site, but I included the binary I’m running in that zip archive to avoid possible compatibility issues.
After unpacking in a folder of your choice (create a new one!), first have a look in files sx_*.txt and edit them according to your personal preferences. To check it, copy a poorly formatted MQL source to file in.mq4 and save it. Then run the batch file and open the new file created, result.mq4.
Note that the function header you defined will only be set if there’s no function header present.
The settings I find useful are defined in file simplex.cfg. Note: just my personal preferences – change it if you like to do so!
Look at the pics attached for an example of before and after.
That’s all – have fun!
simplex
Attachments:
You must be logged in to view attached files.A good trader is a realist who wants to grab a chunk from the body of a trend, leaving top- and bottom-fishing to people on an ego trip. (Dr. Alexander Elder)
May 19, 2015 at 2:05 am #6745This is great, thanks a lot simplex.
Will try it soon …September 4, 2015 at 4:45 am #7775hey guys i need a little help coding my EA,
i need a MAX SPREAD and money management (example i want every trade to be 1% of my account balance)
i need to be able to change the settings also
if you can finish the rest it would be much help i hope my English was good enough to understand
September 7, 2015 at 2:12 pm #7804example i want every trade to be 1% of my account balance
That part should be easy!
hey guys i need a little help coding my EA, i need a MAX SPREAD
Would be helpful if you posted your source in order to implement the changes, and if you provided some more detail about your desired MAX SPREAD feature.
simplex
-
This reply was modified 10 years, 7 months ago by
simplex. Reason: spelling
A good trader is a realist who wants to grab a chunk from the body of a trend, leaving top- and bottom-fishing to people on an ego trip. (Dr. Alexander Elder)
November 30, 2015 at 4:57 pm #9654Hi coders!
After the latest forced MT4 update to build 910 MT4 compiler is nagging with new warnings in strict compile mode when using structures. Excerpts from my code:
struct LOC_CURRENCY_VALUE { // extreme currency values structure int idx; // currency index double val; // extreme value }; LOC_CURRENCY_VALUE locCurPanel[3][2]; // initialize extremum structure for (int iDim = 0; iDim < 3; iDim++) { for (int iExt = 0; iExt < 2; iExt++) { locCurPanel[iDim][iExt].idx = -1; locCurPanel[iDim][iExt].val = 0.0; } } // ... more code here .. if (curPanel[ic][iDim].vel > locCurPanel[LCV_VEL][LCV_STR].val) { locCurPanel[LCV_VEL][LCV_STR].idx = ic; locCurPanel[LCV_VEL][LCV_STR].val = curPanel[ic][iDim].vel; }The structure is declared and then initialized in a loop. Later, when elements of that structure are used in the if statement, the compiler warns possible use of uninitialized variable ‘locCurPanel’.
Standard function ArrayInitialize() does not work on structures.
Overall code is working properly, and switching #property strict off is not an option for several reasons. Though also like to compile without warnings.
Any ideas what to do?
simplex
A good trader is a realist who wants to grab a chunk from the body of a trend, leaving top- and bottom-fishing to people on an ego trip. (Dr. Alexander Elder)
December 16, 2015 at 11:44 pm #10447Hi guys!
Can anyone provide John F. Ehlers SuperSmoother Filter as an MQ4 class instead of a function?
Or if not a class, then a multi-instance version of that filter coded in non-recursive style?
Best, s.
EDIT: cancel this request! After getting to bed a bit earler last night I did it myself this morning!

-
This reply was modified 10 years, 4 months ago by
simplex. Reason: cancel request
A good trader is a realist who wants to grab a chunk from the body of a trend, leaving top- and bottom-fishing to people on an ego trip. (Dr. Alexander Elder)
July 11, 2016 at 3:08 am #12803Looking for a function that will draw a line until it hits price
Edit: i think i have this worked out. writing it down so when i forget i can look here again
if (priceToStartDrawing>0) { bool flag = false end_Draw_index = start_drawPoint_index+1//will be minus if your most current bar in history is indexed as 0 while (end_Draw_index < mostCurrentIndexInHistory or !flag ) { if (high[end_Draw_index ]>priceToStartDrawing or end_Draw_index > mostCurrentIndexInHistory ) flag=true; //draw to the right until it hits price or it reaches the most current bar drawn end_Draw_index++// keep counting to the right//minus if your most current bar is indexed as 0 } if (flag) { drawline(name,0,time[end_Draw_index/*adjust*/],priceToStartDrawing,time,priceToStartDrawing,Color,etc }“I believe the very best money is made at the market turns. Everyone says you get killed trying to pick tops and bottoms and you make all
your money by playing the trend in the middle. Well for twelve years I have been missing the meat in the middle but I have made a lot of
money at tops and bottoms.”
– Paul Tudor JonesNovember 28, 2016 at 5:07 pm #13408Once again: we’ll see whether they are serious this time!
s.
A good trader is a realist who wants to grab a chunk from the body of a trend, leaving top- and bottom-fishing to people on an ego trip. (Dr. Alexander Elder)
November 30, 2016 at 12:46 pm #13410For anyone using mt4 and having to eventually recode indicators to suit mt5 this is going to be a pain
I have never used mt5 so cannot comment on whether it is more desirable, does it have more bells and whistles ???
Pip
skype : pipatronic
December 23, 2016 at 11:21 am #13474more on mt4/5 here
http://www.forexfactory.com/news.php?do=news&id=625331
and a MERRY CHRISTMAS TO YOU ALL

skype : pipatronic
December 23, 2016 at 1:38 pm #13475Interesting news, thanks for sharing it, @pipatronic.
Here’s the original story referenced by the FF article …
Sooner or later we’ll have to get used to the idea of migrating our mq4 code.
A good trader is a realist who wants to grab a chunk from the body of a trend, leaving top- and bottom-fishing to people on an ego trip. (Dr. Alexander Elder)
December 29, 2016 at 7:31 am #13477Hi everybody,
I’d like to modify one of the TZ indicators (for instance this one) in order to determine the width of the zone itself. All TZ indicators I’ve seen so far determine the height of a zone by looking back and forth to preceding and subsequent bars. Unfortnately, I have absolutely no idea how to do it (you know, I’m a quite unexperienced programmer). Additionally I’d like to add some stats (time/bars to next visit of a previous TZ, time/bars of revisit of entry point of previous TZ after the prize went through former TZ). Any help would be appreciated.
February 14, 2017 at 2:33 am #13590Hi everybody, I’d like to modify one of the TZ indicators (for instance this one) in order to determine the width of the zone itself. All TZ indicators I’ve seen so far determine the height of a zone by looking back and forth to preceding and subsequent bars. Unfortnately, I have absolutely no idea how to do it (you know, I’m a quite unexperienced programmer). Additionally I’d like to add some stats (time/bars to next visit of a previous TZ, time/bars of revisit of entry point of previous TZ after the prize went through former TZ). Any help would be appreciated.
Hi Anti, could you please tell us more about the Width ? And about time/bars to next visit of prev TZ, do you mean time to visit the CTZ, after the PTZ becomes CTZ ?
March 8, 2017 at 6:14 pm #13663Hi simplex,
don´t know if this is the right place here at penguin but I give it a try. I`m using the MT4 Node.js client/server bridge and it works very well so far. But I noticed if I remove the indicator fronm the chart that there is a lot of rest garbage in memory. These are the messages which are occur when we remove the indicator.
2017.03.08 18:50:42.164 sample_node_indi AUDNZD,M1: 289080 bytes of leaked memory
2017.03.08 18:50:42.164 sample_node_indi AUDNZD,M1: 1971 leaked strings left
2017.03.08 18:50:42.164 sample_node_indi AUDNZD,M1: 657 objects of type JSONString left
2017.03.08 18:50:42.164 sample_node_indi AUDNZD,M1: 1314 objects of type HashEntry left
2017.03.08 18:50:42.164 sample_node_indi AUDNZD,M1: 657 objects of type Hash left
2017.03.08 18:50:42.164 sample_node_indi AUDNZD,M1: 657 objects of type JSONNumber left
2017.03.08 18:50:42.164 sample_node_indi AUDNZD,M1: 657 objects of type JSONObject left
2017.03.08 18:50:42.164 sample_node_indi AUDNZD,M1: 3942 undeleted objects leftIs there a possibility to close the indicator in a proper way, without these messages. These messages only occurs if there was a minimum of one connection to the node server.
What do you think?Thank you and best Regards
March 12, 2017 at 1:55 pm #13679Hi Frika,
Since you’re addressing me directly: I’ve never worked with Node.js, so only can wish you ‘Good luck’ in fixing those issues. Maybe you could also place your question in that thread:
http://penguintraders.com/forums/topic/nodejs-mysql-connection-example/
And if you manage to fix it, that would definitely be worth to be posted, ok?
s.
A good trader is a realist who wants to grab a chunk from the body of a trend, leaving top- and bottom-fishing to people on an ego trip. (Dr. Alexander Elder)
April 4, 2017 at 9:42 am #13738Hi All,
This is a beginner question … i try to code an indicator, but it eats my CPU and memory resources … :( I try to optimize it by limiting the amount of bars to calculate, and also try to do the calculation not in every tick, but in every some seconds / minutes. I would like to ask, how to code it the right way ….
========
int bars_to_calculate = 1000;
double time_to_calculate = 0.5; // calculate in every 30 seconds (0.5 minute)
datetime begin_time = 0;int init()
{
begin_time = Time[0];
} // initstart() {
int counted_bars = IndicatorCounted();if (counted_bars <0) return(0);
int limit = MathMin(bars_to_calculate, Bars-counted_bars);if (TimeCurrent() > begin_time + (int)time_to_calculate*60)
{
begin_time = TimeCurrent();for (int i=limit; i>0; i–)
{
// do calculation here ….} // for
} // ifreturn(0);
} // start================
I want to make sure: is the calculation above right ?
That is the old style of MT4 coding. If i use the new style, can i just change these below :
use rates_total instead of Bars
use prev_calculated instead of IndicatorCounted()
use return (rates_total) instead of return(0) at start function
Or … is there some thing else must be changed ?
Tom.
April 4, 2017 at 2:03 pm #13739Hi Tom!
Did not look into your code in depth, yet I would suggest that you quit the old school standard of coding MT4 indicators ( int start()… int init() ). The sooner, the better!
Some day MetaQuotes will stop supporting MT4, and you will be forced to recode every MQ4 code you have in MQ5. This will require much less work if you code your MT4 programs according to the new standards (which are not so new anymore, right?)
To support your efforts, I’ll place a nonsense indicator, that follows my personal coding standards, as an attachment. Feel free to use, modify, report issues, report suggestions, whatever …
Best, simplex
Attachments:
You must be logged in to view attached files.A good trader is a realist who wants to grab a chunk from the body of a trend, leaving top- and bottom-fishing to people on an ego trip. (Dr. Alexander Elder)
April 4, 2017 at 2:09 pm #13741Ahh, one more thing: with
for (int i=limit; i>0; i–)
the current bar won’t be calculated. Should be i >= 0
A good trader is a realist who wants to grab a chunk from the body of a trend, leaving top- and bottom-fishing to people on an ego trip. (Dr. Alexander Elder)
April 4, 2017 at 5:17 pm #13742Thanks Simplex for the prototype and improvement. It is a great prototype

the current bar won’t be calculated. Should be : i >= 0
a) we must include current bar, although it is not finish yet …. agree
b) In this case, if we want to keep the amount of bar to 1000 (if it is smaller than Bars-IndicatorCounted() … ) , we need to begin with i=limit-1 ?
for (i=limit-1; i>=0; i–)
Regarding the MQH file, can we compile it (similar to EX4 format), or it must be always in source format (similar to MQ4) ?
Tom
-
This reply was modified 9 years ago by
thomas.
April 5, 2017 at 10:25 am #13746a) we must include current bar, although it is not finish yet …. agree
It depends on your specific indicator / EA logic, whether you decide to include the current bar or not.
b) In this case, if we want to keep the amount of bar to 1000 (if it is smaller than Bars-IndicatorCounted() … ) , we need to begin with i=limit-1 ?
Is it really important whether your indicator shows 1000 bars or 1001 bars?
Regarding the MQH file, can we compile it (similar to EX4 format), or it must be always in source format (similar to MQ4) ?
It’s the easiest way to include the mqh as a source file. You can also include it as a precompiled ex4 library. If you do so, you have to use additional compiler directives in your code to specify the functions required, like this:
#import “stdlib.ex4”
string ErrorDescription(int error_code);see here for details: https://docs.mql4.com/basis/preprosessor/import
s.
A good trader is a realist who wants to grab a chunk from the body of a trend, leaving top- and bottom-fishing to people on an ego trip. (Dr. Alexander Elder)
April 6, 2017 at 4:16 am #13747Thanks Simplex
Btw, you do you mean we should create a DLL file (may be using C# or C++), compile it, put it at Libraries folder ?
Or do you mean there is a additional compiler out there, so we can use it to compile the Mqh file, and put the compiled (Mqh becomes Ex4 now) file to Include folder ?-
This reply was modified 9 years ago by
thomas.
April 7, 2017 at 4:55 pm #13758Hi Thomas,
Both is possible.
If you would be able to create a ‘how to’ advice for setting up a working dll and integrating it into an mq4 project, I’d be very interested! From my personal point of view, an open source C compiler and open source development environment would be preferrable.
Best, s.
A good trader is a realist who wants to grab a chunk from the body of a trend, leaving top- and bottom-fishing to people on an ego trip. (Dr. Alexander Elder)
April 10, 2017 at 1:36 pm #13760Hi Simplex,
Some month ago i tried to build one based on this : https://www.xpworx.com/metatrader-mql-articles/mql4-articles/create-your-own-metatrader-extension-dll.php
but still have no success …. Still need time for this. And will try to look for opensource C compiler + development environment …
It is good to have own dll for MT4, but i think it is for future project (not in this month), i must collect information as much as possible first …
Thanks for your support. TomApril 20, 2017 at 4:59 am #13800@simplex, @xux99, @lowphat or other coders ….
I am stuck with iStochastic. Actually it is simple, but as a beginner in coding, i still can not find the solution to call the Stochastic line value with setting X,1,1 …for (i=limit; i>=0; i–) {
stoMain = iStochastic(Symbol(),0,14,1,1,MODE_SMA,1,MODE_MAIN,i);
stoSignal = iStochastic(Symbol(),0,14,1,1,MODE_EMA,1,MODE_SIGNAL,i);
}The above code just as example. The problem is that i just got an empty value for 0 (ZERO) result of Main or Signal line of Stochastic, if using Dperiod=1 and Slowing=1 (with : Close/Close as priceField). Other than 0 (zero) result of Stochastic line are no problem.
If i change the setiing of Kperiod, Dperiod, Slowing to : 14,3,3 as example, i can get the 0 (zero) result value of stochastic without problem.Why ???

-
This reply was modified 9 years ago by
thomas.
-
This reply was modified 10 years, 7 months ago by
- AuthorPosts
- You must be logged in to reply to this topic.