forex software

Create and Test Forex Strategies

forex software

Skip to forum content

Forex Forum

Forex Software, Forex Strategies, Expert Advisors Generator

You are not logged in. Please login or register.


Forex Forum → Expert Advisor Modifications → Logging the spread in the comment field of each trade [MT4 CODE]

Pages 1

You must login or register to post a reply

RSS topic feed

Posts: 1

1 (edited by geektrader 2019-01-17 03:01:05)

Topic: Logging the spread in the comment field of each trade [MT4 CODE]

Hi,

I just thought I would share how I log the spread of every trade in the order comment field in MT4, which I am doing since a long time already to always being able to check at what spread each trade of each strategy was really executed at on average. I am using that data to adjust the spread for future backtests / optimizations of each strategy.

All you´ll have to do is to open the exported MQ4 code from EA Studio and replace this in the "OpenPosition" function:

string comment    = IntegerToString(Magic_Number);

with

string comment    = IntegerToString(Magic_Number) + ", Spread (points): " + DoubleToString((Ask - Bid) / _Point, 0);

Make sure that your Magic_Number (in the EA input settings) is not too long, as the order comment field at your broker can usually only hold 31 chars at the most. Alternatively, you can remove the Magic_Number from the order comment field as well, as it is anyway assigned in the Magic Number field of the trade already. Then the final code would look like this:

string comment    = "Spread (points): " + DoubleToString((Ask - Bid) / _Point, 0);

Have fun :-)

Posts: 1

Pages 1

You must login or register to post a reply

Forex Forum → Expert Advisor Modifications → Logging the spread in the comment field of each trade [MT4 CODE]

Similar topics in this forum