Download MetaTrader 5

Trader's Kit: Drag Trade Library

11 May 2012, 07:14
Комбинатор
8
2 455

Introduction

At the time of development, there already existed some products that to a certain extent implemented the functionality provided by the library or had similar features. I cannot say whether the library is better or worse than those. It loses out to some of them in functionality, e.g. to well-known Autograph, and to others - in convenience. However Drag Trade Library has its peculiarities and the product will hopefully be in demand.


1. Purpose of Development

It was initially planned to create an Expert Advisor that would trade and handle orders directly on a chart using the mouse and control objects while retaining user friendliness and a minimalistic interface. That said, a major feature of the Expert Advisor was the fact that it was developed entirely in the original language of the terminal being therefore safe for the users since it could not contain malicious code. Besides, the Expert Advisor was originally intended to be free software.

Work on the project gave rise to the library that combined the above features and could easily be integrated into virtually any EA. In addition, the library code contains a lot of useful functions that can be utilized outside the library framework.


2. Structure

The library functionality can be divided into four blocks:

  1. Trading block
  2. Information block
  3. Order handling block
  4. Settings block


Fig. 1. Library functionality

The EA's functionality is displayed based on the same block division principle - user interface is divided into 3 independent blocks that can be used jointly and independently by disabling and enabling the required blocks as may be necessary during operation. Moreover, this approach allows to save resources getting wasted when processing unnecessary logical blocks or to even use minimum resources when functionality blocks are disabled. All functionality blocks are disabled by default.


2.1. Principles of enabling/disabling blocks

All block drawing and processing functions are located in the Expert Advisor. However the information and most control and information objects are not drawn in the main tool window. The drawing space is provided by pseudoindicators that also serve to enable and disable the functionality blocks. This means that if a certain indicator is present in the chart, the respective functionality block of the Expert Advisor is enabled and operating.

The indicators as such are not used. Their only purpose is to provide drawing space.


Fig 2. Auxiliary indicators

There are some limitations on the use of indicators. Any external indicators can be dragged on to pseudoindicator windows but not the other way round as the presence of a window is determined by the pseudoindicator name and the respective functionality block will simply not get enabled.


3. User Interface

3.1. Expert Advisor settings

The settings were taken out of the library to form a separate functionality block. This enabled us to actually single out and place the entire functionality in the library and make settings externally both before and during the operation of the Expert Advisor. In addition, the settings can be divided into separate logical blocks without skimping on specification.

The process itself consists in applying the appropriate script to the required chart.

At the moment, there are 3 setting scripts:

  • DragTrade_CommentsSettings.mq4 – comments settings (logs displayed in the trading subwindow).
  • DragTrade_ObjectsSettings.mq4 – general user interface settings - style of control and information objects.
  • DragTrade_TradeSettings.mq4 – library trading settings.

The script provides a description for every property so there should be no problem figuring out how they are set.

The implementation of this feature is based on the use of global variables of the terminal for storing the settings. This imposes some limitations on its use - lines cannot be passed in this manner as the maximum size of transmitted information is limited and equals to the double type, i.e. 8 bytes.

An example of setting the Expert Advisor properties can be seen below. Settings for comment and object output are changed for a running Expert Advisor:

To be able to freely test strategies in the tester without being afraid of resetting or changing parameters for online trading, there is a different parameter passing for online and test mode. Setting the parameters for the one will not affect the other.

Therefore, if you want to change the default parameters in the tester, you should use the similar scripts for the test mode:

  • DragTrade_TesterCommentsSettings.mq4 – comment settings (logs displayed in the trading subwindow).
  • DragTrade_TesterObjectsSettings.mq4 – general user interface settings - style of control and information objects.
  • DragTrade_TesterTradeSettings.mq4 – library trading settings.
3.2. Functionality

So, the interface is divided into 3 independent areas which can be disabled:

  • DragTrade_Infobar (Information block)
  • DragTrade_OrdersBar (Order handling block)
  • DragTrade_Toolbar (Trading block)

As a whole it looks like this:


Let us have a more detailed look at every one of them.

3.2.1. Information panel

The information panel is an area for displaying information. This is the most uncomplicated part of the functionality. It displays general account or instrument information as well as current library settings.

Fig. 3. Information panel

Information for display can easily be expanded which will however require modifications of the library code.

If it does not scare you off, the functionality is represented by the following functions: void ClearInformation() and void DrawInformation()

3.2.2. Panel of orders

This panel displays information on current (open) instrument orders and contains controls for handling them.

Fig 4. Panel of orders

What you can do by enabling this panel:

  • close any order from the list of orders placed for a certain currency pair (hereinafter in accordance with the EA magic number settings), including market and pending orders.
  • close all buy orders
  • close all sell orders
  • delete all pending orders
  • delete and close all orders

The following video provides a graphic demonstration of the functionality of this panel:

3.2.3. Trading panel

This panel is used to display trading functionality. It is the most important and necessary panel as it contains the main functionality of the library. Getting this panel enabled gives you an opportunity to place orders and handle them using certain controls directly on the chart.


Fig. 5. Trading panel

What you can do by enabling this panel:

  • Place and close market orders.
  • Open pending orders, both stop and limit. Since I have not yet found a good enough way of setting stop levels for pending orders, they are currently missing and can only be set using the built-in terminal features (i.e. order modification window).
  • Delete pending orders
  • Change stop levels of orders.
  • Change trigger price of limit and stop orders.

Market orders are placed as follows:

  • set the stop loss price of the future order using the price pointer
  • superpose the controls for "Open Market Order"

A market order is closed by simply dragging any of the stop levels to the other side of the price.

The video below shows examples of handling market orders

Handling buy orders:




Handling sell orders:




Pending orders are placed as follows:

  • set the trigger price of the future order using the price pointer
  • superpose the controls for "Open Stop Order" if you want to place a stop order or for "Open Limit Order" if you want to place a limit order.

A pending order is closed by simply dragging the order line to the other side of the price.

The video below shows examples of handling pending orders.

Handling stop orders:




Handling limit orders:



4. Integration into the Expert Advisor

And finally, the most interesting part.

It is in fact very simple. The integration process is considerably simplified due to the fact that only the necessary minimum of settings is passed to the library during integration; the remaining settings are covered by external scripts.

The simplest example of an Expert Advisor can be demonstrated by a shell turning the library into an Expert Advisor. It will appear as follows:

//+------------------------------------------------------------------+
//|                                      DragTrade_Example_v_1.0.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, TheXpert"
#property link      "theforexpert@gmail.com"

extern int      Magic          = 1111;
extern int      EAMagic        = 1234;
extern int      TimesToRepeat  = 3;
extern int      Slippage       = 3;

#include <DragTrade_v_1.0/DragTradeLib_v_1.0.mqh>

bool Testing;

int init()
{
   Testing = IsTesting();
   DragTrade_Init(Magic, EAMagic, TimesToRepeat, Slippage, "Drag Trade Example");

   Comment_("Test Example of using Drag Trade Library");

   return(0);
}

int deinit()
{
   DragTrade_Deinit();
   return(0);
}

int start()
{
   DragTrade_Start();
   
   return(0);
}

The above code can be applied as a ready to use Expert Advisor to trade using the mouse.

Events in this code are handled with every new tick.

The main library integration points:

  • Functions init and deinit are essential and required to be in the Expert Advisor.
  • Include the library head file DragTradeLib_v_1.mqh and make sure that the library components are all in proper places.
  • The following library functions shall be called in the corresponding EA functions:
  1. DragTrade_Init
  2. DragTrade_Deinit
  3. DragTrade_Start

The DragTrade_Init function is as follows:

   void DragTrade_Init(int magic, int eaMagic, int timesToRepeat, int slippage, string ordersComment = "");

Let us have a detailed look at the parameters to be passed:

  • int magic – the magic number used by the library. Orders placed using the library will bear this number. If the value passed is equal to -1, the orders will open with magic number 0 and the filtering option by the magic number will not be available during display.
  • int eaMagic – the magic number of the strategy. It is introduced so that the orders placed automatically and manually could be distinguished by the strategy implemented. If you want the strategy to be able to "see" these orders, you can set identical magic numbers or implement traceability of two different magic numbers. If the value is -1, additional magic number will not be used.
  • int timesToRepeat – trading parameter. The number of attempts to place an order if the cause of error allows to retry immediately.
  • int slippage – trading parameter. Slippage.
  • string ordersComment – the comment for orders placed using the library.

If you want a quick execution of commands, the EA's start function can be looped:

int start()
{
   while (!IsStopped())
   {
      DragTrade_Start();
      Sleep(200);
   }
   return(0);
}

It will however be impossible to test such an Expert Advisor in the tester - it will freeze up.

A solution can be found by making a provision for a different behavior of the tester:

int start()
{
   if (Testing)
   {
      DragTrade_Start();
   }
   else
   {
      while (!IsStopped())
      {
         RefreshRates();
         
         DragTrade_Start();
         Sleep(200);
      }
   }
   
   return(0);
}

The standard package attached to the article contains this particular simplest Expert Advisor.

Besides that, the package includes a standard Expert Advisor MACD Sample featuring the integrated library and the library trading functions.

Apart from the functions required for integration, the DragTradeLib_v_1.0.mqh file provides a whole set of functions that may prove useful in the implementation of trading strategies which are used by the library and can be used to implement your code.


5. Library Installation

The installation is simple - you need to unzip the attached archive into your terminal folder, restart the terminal if it was working, so that the executable files appear in the list of available files in the terminal.


6. License

/* =============================================================================================== */
/* Copyright (c) 2010 Andrey Nikolaevich Trukhanovich (aka TheXpert)                               */
/*                                                                                                 */
/* Permission is hereby granted, free of charge, to any person obtaining a copy of this software   */
/* and associated documentation files (the "Software"),                                            */
/* to deal in the Software without restriction, including without limitation the rights            */
/* to use, copy, modify, merge, publish, distribute,                                               */
/* sublicense, and/or sell copies of the Software, and to permit persons                           */
/* to whom the Software is furnished to do so, subject to the following conditions:                */
/*                                                                                                 */
/*                                                                                                 */
/* The above copyright notice and this permission notice shall be included                         */
/* in all copies or substantial portions of the Software.                                          */
/*                                                                                                 */
/* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS                        */
/* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,                     */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR          */
/* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER                                     */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR         */
/* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                   */
/* =============================================================================================== */

Conclusion

The library was tried out while working with a real account and proved itself to be a useful, reliable and stable tool.

Once again, I would like to express my profound gratitude to Viktor Khabibulaevich Rustamov. He was the originator of the idea of creating the library, as well as a tester and a valuable source of advice in the implementation of the idea.

There is quite a lot of code so small errors and faults are quite likely to be present. I would really appreciate if you let me know about them.

And I will try to provide feasible (not guaranteed) code maintenance. Further project developments under the license terms by other people will get my full support. Any comments and suggestions with regard to the library will be taken into account to the extent possible in future versions.

Good luck and trade easy!


Translated from Russian by MetaQuotes Software Corp.
Original article: https://www.mql5.com/ru/articles/1354

Attached files |
Last comments | Go to discussion (8)
prasadFx
prasadFx | 28 Apr 2016 at 18:34

hiii 

first appreciate ur work, but i put all the file in correct folders and alll the file compiled but indicator window is empty nothing there,

help me.

 

Комбинатор
Комбинатор | 28 Apr 2016 at 18:51

Hello. Thank you.

Indicators won't work until you place main expert on the chart.

But I think all the system won't work correctly because it's old and written for old terminals. Lots of changes have been made since then. 

prasadFx
prasadFx | 29 Apr 2016 at 20:09
Комбинатор:

Hello. Thank you.

Indicators won't work until you place main expert on the chart.

But I think all the system won't work correctly because it's old and written for old terminals. Lots of changes have been made since then. 

Thank u so much for that. it works fine after adding main expert, if u can send me link of updated system.

 thanks again for ur comment.  

Комбинатор
Комбинатор | 29 Apr 2016 at 20:48
Wow, that's nice surprize! Glad that it works, there's no updated system
prasadFx
prasadFx | 29 Apr 2016 at 21:07
Комбинатор:
Wow, that's nice surprize! Glad that it works, there's no updated system
Yea,im so happy, what a nice system . ur knowledge is very good , i go through some of codes, appreciate it.u put all source code to see whats inside it. . it's nice. but i wanted to do small modification. can u do that plz send mail to me prasadmx@gmail.com 
Step on New Rails: Custom Indicators in MQL5 Step on New Rails: Custom Indicators in MQL5

I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.

Here Comes the New MetaTrader 5 and MQL5 Here Comes the New MetaTrader 5 and MQL5

This is just a brief review of MetaTrader 5. I can't describe all the system's new features for such a short time period - the testing started on 2009.09.09. This is a symbolical date, and I am sure it will be a lucky number. A few days have passed since I got the beta version of the MetaTrader 5 terminal and MQL5. I haven't managed to try all its features, but I am already impressed.

Using text files for storing input parameters of Expert Advisors, indicators and scripts Using text files for storing input parameters of Expert Advisors, indicators and scripts

The article describes the application of text files for storing dynamic objects, arrays and other variables used as properties of Expert Advisors, indicators and scripts. The files serve as a convenient addition to the functionality of standard tools offered by MQL languages.

How to create an indicator of non-standard charts for MetaTrader Market How to create an indicator of non-standard charts for MetaTrader Market

Through offline charts, programming in MQL4, and reasonable willingness, you can get a variety of chart types: "Point & Figure", "Renko", "Kagi", "Range bars", equivolume charts, etc. In this article, we will show how this can be achieved without using DLL, and therefore such "two-for-one" indicators can be published and purchased from the Market.