Page 1 of 1

SNS DEVELOPER TOOL SERIES (SNS DTS)

Posted: Tue Dec 01, 2009 7:30 pm
by snscott
TARGET AUDIENCE: MT4 PROGRAMMERS

I'm going to put utility libraries here in this thread.

These are NOT indicators, but are IMPORTABLE utility functions and "objects" that can help make some tasks easier for developers.

For each library, I will include the source code (MQ4) file, and a MQH file with the #IMPORTS in it that you can then simply #INCLUDE in your own indicators.


Two very important points to keep in mind:

The #INCLUDE (MQH) files need to be placed in the experts:INCLUDES folder. The MQH files are simple text files and do not need to be compiled.

The #IMPORT (MQ4 Libraries) files need to be placed in the experts:LIBRARIES folder. The MQ4 files, after placed into the LIBRARIES folder, do need to be compiled.

SNS_OBJECTLIBRARY

Posted: Tue Dec 01, 2009 7:39 pm
by snscott
SNS_ObjectLibrary
Version 2.0 11/29/2009

This is the source code (MQ4) and #include (MQH) file for the "utilities" library that I use in most of my indicators. It is an accumulation of commonly used functionality that I found I was typing or cut-n-pasting over and over again so I decided to gather all that common stuff together into one #IMPORT file.

Obviously, this library will be modified and expanded over time as I add more commonly used functions.

Any cool/useful and reusable functions like this that you have that you think would fit in here and you'd like to share, send me a note and I'll certainly consider adding it to this library.



[hr]By no means did I write all these utility functions myself - several of them come from indicators written by various other coders
[hr]

REMINDER: Library files go into the experts/LIBRARIES folder and the #include (NQH) files go into the experts/INCLUDES folder.

[hr]
VERSION HISTORY

11/29/2009 v2.0 Initial public release of source code

[hr]

SNS_TABLE_OBJECT

Posted: Tue Dec 01, 2009 7:47 pm
by snscott
SNS_TABLE_OBJECT

This utility is an attempt to make it easier for developers to provide tables of data in their indicators . Commonly referred to as "gauges".

Normally a developer has to painstakingly code several OBJECT creation and setting calls for each and every item shown on a data chart.

Using this #import-able Table Object, developers simply have to provide arrays of information such as row and column coordinates and font settings for each "cell" in the table. Then, putting data into any given cell is as simple as:

Code: Select all

Table.SetText(2,3,"Something");


While MQL4 is not an "object oriented" programming language like JAVA or C#, I have tried to maintain the spirit of OOP in how I created the API for this utility/tool. The convention I have tried to consistently follow, in an attempt to make my MQL4 code "feel" more like an object oriented language, is to use naming for variables and functions like this:

<object name>.<variable or function>

For example:

Code: Select all

Table.SetText(int row, int col, string text);



I have also provided two example indicators using the Table Object Library. One, SNS_#TABLE is a pretty simple "do nothing" example that puts a 2 row, 3 column gauge on the screen. It demonstrates the case where you want to provide externally adjustable settings to everything in your table such as coordinates and font settings. This simple example provides "cut-and-paste" reusable code that you can easily lift and drop into your own indicators.

The other sample is a modified version of the TRO_DRAGON_MONEY_MANGEMENT indicator renamed to SNS_MONEY_MGMT and provides a subset of the market/money management information that TRO's full-blown indicators provides (I shortened it down to the bits of data that I, personally, was particularly interested in).

Note that there seems to be some bug in MT4 in indicators that make use of some of the MARKETINFO() calls which results in the information not displaying until you open the indicator for editing and then close it without changing anything. I'm still trying to track down what is causing this, but it is an issue with or without the Table Object.

REMINDER: Library files go into the experts/LIBRARIES folder and the #include (MQH) files go into the experts/INCLUDES folder.

[hr]
VERSION HISTORY

11/30/2009 v1.0 [BETA] Beta Release
12/03/2009 v1.0a [BETA] Fixed bug with location of mqh file

[hr]

SNS_TABLE_OBJECT v1.0a [BETA]

Posted: Thu Dec 03, 2009 9:17 pm
by snscott
SNS_TABLE_OBJECT
Version 1.0a [BETA] 12/03/2009

Fixed a small, but annoying bug with where it looked for the MQH library/header file to include.

[hr]
Note to new MT4 programmers:

MQL4 allows for two ways of using the #INCLUDE directive which affects where the compiler looks for the MQH header file to include.

Code: Select all

#include "file_name
#include <file_name>


The MQL4 preprocessor replaces the above line(s) with the content of the specified MQH file. In other words, it INLCUDES the contents of the MQH file in-whole at that point.

Surrounding the file name with <angle brackets> mean that the MQH file will be taken from the default directory (usually MT4/experts/include). The current directory is not searched.

If the file name is enclosed in "quotation marks", the search will be performed in the current directory (where the main file of the source code is located). The standard default directory is not searched.

So, obviously, using <angle brackets> is much better (IMHO) than using quotation marks. In the original release of this code, I accidentally left the include using quotation marks. Version 1.0a fixes that by replacing the quotes with brackets.

[hr]

Sorry for any inconvenience this may have caused. :oops: (But that is the nature of BETA releases)

Updated version located in orignal SNS_TABLE_OBJECT post in this thread.

Posted: Fri Dec 04, 2009 3:51 am
by frang0nve
Hi Steven,

Thanks for sharing. Perhaps it's a stupid question... But I can't find SNS_TABLE_OBJECT.MQH in the SNS_TABLE_OBJECT.zip file.

Cheers

Francisco

Posted: Fri Dec 04, 2009 4:25 am
by snscott
frang0nve wrote:Thanks for sharing. Perhaps it's a stupid question... But I can't find SNS_TABLE_OBJECT.MQH in the SNS_TABLE_OBJECT.zip file.


DOH! Oops_Smile

It's in there now. Sorry about that. I'll get the kinks worked out of this "process" sooner or later.