Debugging While BackTesting The EA

May 15, 2013 at 2:48 PM

I basically want to backtest my EA. So I do the following steps.
  1. Start the Shell application
  2. Open MT4
  3. Click on View -> Strategy Tester (to bring up the tester)
  4. Choose "Expert_Net" the advisor used for Tradeplatform.Net
  5. Set my breakpoint in my code for the "Start" Function in Visual Studio
  6. Attach Visual Studio to the "Shell" process by clicking on Tools -> Attach to Process
  7. Click Start on the tester.
Problem is my debug doesnt get hit.
What am I doing wrong? I basically want to back test my EA and set breakpoints to see the information I am getting back.

Can somebody please assist me. Pictures or Videos are welcome. People understand better with pictures.

Thank you :)
May 15, 2013 at 9:20 PM
Hi Nivash,

If I assume:
  1. MACrossExpert EA is the one you want to run in debug mode
  2. You are using the source code version of the of TradePlatform
  3. In Expert_NET.mq4 the System_NET_ApplicationName = "MACrossExpert"
Then the following process should get you up and running:
  1. VS2012: Open TradePlatform.MT4.SDK.sln
  2. VS2012: Set Start Up Project to TradePlatform.MT4.SDK.Shell
  3. VS2012: Put a breakpoint in MACrossExpert.Start method
  4. VS2012: Run Debug
  5. MT4: Run MT4 and close any open charts
  6. MT4: Open Strategy Tester
  7. MT4: Setup test in non-optimised, Visual mode (this may not be necessary but it's the way I've been doing it thus far) - picture of settings below
  8. MT4: Start the test
  9. VS2012: Check to see if breakpoint set up in Step 3 is hit
May 17, 2013 at 2:03 PM
Hi Bendyarm

Thank you for your reply, I only had a chance to test this out today and I am still NOT successful in this matter. Here is the tester logs.

15:48:54 2013.05.03 04:53 Expert_NET EURUSD,M1: dll calls are not allowed; 'ws2_32.dll'-'closesocket'
15:48:54 2013.05.03 04:53 Expert_NET EURUSD,M1: expert stopped
15:49:29 2013.05.03 13:54 Expert_NET EURUSD,M1: dll calls are not allowed; 'ws2_32.dll'-'closesocket'____
15:49:29 2013.05.03 13:54 Expert_NET EURUSD,M1: expert stopped
15:49:30 Expert_NET inputs: System_NET_Port=2007;

I am not sure what I am doing wrong. But I did follow your steps.

if I put the breakpoint and add the EA to the chart while forward testing it, it works 100%, my breakpoint gets hit every time.

My challenge is backtesting, let me know if you need any information regarding how I am trying to do this. I am happy to help and get this working.

Thank you
May 18, 2013 at 10:58 AM
Hi Nivash,

Your log states 'dll calls are not allowed' - have you enabled DLL imports in MT4?

I guess that you have if you can successfully debug while forward testing. However, if not, you can do so by doing the following:
  1. MT4 - Navigate to Tools -> Options
  2. MT4 - Select Expert Advisors Tab
  3. MT4 - Check 'Allow DLL Imports'
May 20, 2013 at 6:54 AM
Hi Bendyram

Thank you for your help, its working now (followed the steps in your previous reply above). If anybody else needs to debug in a backtest, they should just follow your steps.

Thanks again.
Oct 19, 2013 at 4:48 PM

I have a similar problem.

if I associate a graphic Expert_NET everything works fine and I can debug. But it does not work in backtest

I'm using:
.NET Bridge Shell

The attempt to test mt4, I can see that invokes the Start method of Expert_NET.mq4 because I modified the code like this:

int start ()
Bridge_NET_API_Start ();
Alert ("start");

and in the daily alerts I can see "start", but in visual studio nothing happens.

Can anyone help me?
Oct 22, 2013 at 1:44 PM
HI, Alx26b

I had to do the following to get my app to debug during a backtest.

MT4 - Navigate to Tools -> Options
MT4 - Select Expert Advisors Tab
MT4 - Check 'Allow DLL Imports'

Please paste your log file here as I was asked above, so other users can also try and help.
But the above worked for me.
Oct 23, 2013 at 7:00 PM
Hi, Nivash

thanks for your reply.

I had already done that as you indicate above, but did not work.

I solved my problem. I comment in the file Bridge_NET.mqh this lines

string Bridge_NET_CallFunction(string handlerName, string methodName, string parameters = "")
//  return("");
where is my log file?

now i see that it the code running in test very slowly compared with code into mt4.

Anything to improve performance?