NOTE: MetaQuotes has updated their MQL4 language and our tools won´t work on MT4 Build 600 and greater, nevertheless all our tools offer the same features and advantages as usual. We highly recommend reading this blog post about updating MT4 to Build 600.

How to detect trade time in milliseconds with 4xGuardian

Feb 13, 2012

In order for 4xGuardian to be able to detect trade execution times in milliseconds you will need to make a small change to your expert advisor, only 2 lines of code,  so it can calculate the execution time with greater precision and send the information to 4xGuardian.

You can make the changes in one of two ways.

1 – Add to lines of code to every open, close or modified request.

Add this one line of code before all your OrderSend() , OrderClose()  and OrderModify() statements , all tree statements used the same line before it.

int TradeTime = GetTickCount();

And after the  OrderSend()   statement add the following line of code:

if (ticket > 0){ int TradeTimetook = GetTickCount()-TradeTime ; GlobalVariableSet ( "Z"+ticket +Symbol (), TradeTimetook );}
* note where ticket is the ticket number returned by the OrderSend()   statement.
 

And after the  OrderModify()   statement add the following line of code:

int TradeTimetook = GetTickCount()-TradeTime ; GlobalVariableSet ( "ZM"+ticket +Symbol (), TradeTimetook );
*Only run the above statement if  OrderModify() succeed,   the  note where ticket is the ticket number you are modifying .
 

And after the  OrderClose()   statement you add the fallowing line of code:

int TradeTimetook = GetTickCount()-TradeTime ; GlobalVariableSet ( "Y"+ticket +Symbol (), TradeTimetook );
*Only run the above statement if  OrderClose() succeed,  note where ticket is the ticket number you are closing.
 

 2 – Use a modifed version of MetaTrader trading fuctions.

Just  use our Drop-in replacement for  OrderSend() , OrderClose()  and OrderModify() , you only need to download and place the Trade funcions replacement.mqh file into your expert/include folder, then add the following line of code in to your expert advisor :

#include <Trade funcions replacement.mqh>

And then replace all the OrderSend() , OrderClose()  and OrderModify() statements with a lower case on the first letter to orderSend() , orderClose()  and orderModify() tru out your expert advisor.

As an example we have modified the MACD Sample.mq4  expert advisor that comes with Metatrader for your reference.

Trade funcions replacement
MACD Sample Milliseconds

This file contains most often used utility functions that are commonly needed in EAs, especially functions for robust order handling.

This program is a free software: you can redistribute it and/or modify. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTIES; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 
Share:

Comments: 0

Comments:

Currently there are no comments related to this article. You have a special honor to be the first commenter. Thanks!

Leave a Comment

WallStreet Forex Robot