Debugging an EA

 

Hi guys,

 I need your help. I am new to developing EAs and I have troubles debugging my code. 

 If I use the debugging tool, after defining my breakpoints and start the tool, the application doesn't do anything: it runs (I can pause it or stop it), but it doesn't go to the any breakpoint or finish by itself (the step into, over and out are disabled).

 And if I try to debug it using Print and Alert messages running the code through the Strategy Tester, the messages displayed in the journal are inconsistent: not all messages are displayed (even if I put one after another, the second can print but not the first one), and there are runs where the messages displayed differ from the previous run, even without changing the code, symbol or period (the only change is an extra compilation).

Additionally, during the run, the system opened a position without displaying the message I put before the code requests it (same issue specified above), and what is even worse is that the opened position didn't have the stop loss value I specified (it is 0 and therefore it stays open for longer), so it would seem it is opening by itself without running my code.

 What can I do? I am getting frustrated.

 Thanks in advance,

 Cesar 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
 
veninoz:

Hi guys,

 I need your help. I am new to developing EAs and I have troubles debugging my code. 

 If I use the debugging tool, after defining my breakpoints and start the tool, the application doesn't do anything: it runs (I can pause it or stop it), but it doesn't go to the any breakpoint or finish by itself (the step into, over and out are disabled).

 And if I try to debug it using Print and Alert messages running the code through the Strategy Tester, the messages displayed in the journal are inconsistent: not all messages are displayed (even if I put one after another, the second can print but not the first one), and there are runs where the messages displayed differ from the previous run, even without changing the code, symbol or period (the only change is an extra compilation).

Additionally, during the run, the system opened a position without displaying the message I put before the code requests it (same issue specified above), and what is even worse is that the opened position didn't have the stop loss value I specified (it is 0 and therefore it stays open for longer), so it would seem it is opening by itself without running my code.

 What can I do? I am getting frustrated.

 Thanks in advance,

 Cesar 

I have the same issue regarding debugging and print in testing, so can't help there :(.

Regarding SL and TP, MT5 does not accept (and therefore will not execute) SL and TP. So, instead SL and TP, use opposite pending orders as TP and SL, for example, if we open buy 1 lot, then also open 1 lot sell limit as TP and 1 lot sell stop as SL. 

 
phi.nuts:

I have the same issue regarding debugging and print in testing, so can't help there :(.

Regarding SL and TP, MT5 does not accept (and therefore will not execute) SL and TP. So, instead SL and TP, use opposite pending orders as TP and SL, for example, if we open buy 1 lot, then also open 1 lot sell limit as TP and 1 lot sell stop as SL. 

I have been reading this in a few posts,  being new to MT5 I just tried and was able to place a trade manually with SL and TP.  Do you mean it's not possible to do this via mql5 ?
 
RaptorUK:
I have been reading this in a few posts,  being new to MT5 I just tried and was able to place a trade manually with SL and TP.  Do you mean it's not possible to do this via mql5 ?
Is SL/TP later executed ?, some users reported that, it is not executed at all :( 
 
phi.nuts:
Is SL/TP later executed ?, some users reported that, it is not executed at all :( 
Yes it was,  trade exited at SL
 
RaptorUK:
Yes it was,  trade exited at SL

Yes I just tried that with MetaQuotes server. MQ must be enable SL and TP in this new build (my MT is actually downloading new MT5 build 773). My Alpari UK does not have SL/TP fields in order window when pressing F9. 

 
phi.nuts:

My Alpari UK does not have SL/TP fields in order window when pressing F9. 

Is that an ECN type scenario ?
 
veninoz:

Hi guys,

 I need your help. I am new to developing EAs and I have troubles debugging my code. 

 If I use the debugging tool, after defining my breakpoints and start the tool, the application doesn't do anything: it runs (I can pause it or stop it), but it doesn't go to the any breakpoint or finish by itself (the step into, over and out are disabled).

 And if I try to debug it using Print and Alert messages running the code through the Strategy Tester, the messages displayed in the journal are inconsistent: not all messages are displayed (even if I put one after another, the second can print but not the first one), and there are runs where the messages displayed differ from the previous run, even without changing the code, symbol or period (the only change is an extra compilation).

Additionally, during the run, the system opened a position without displaying the message I put before the code requests it (same issue specified above), and what is even worse is that the opened position didn't have the stop loss value I specified (it is 0 and therefore it stays open for longer), so it would seem it is opening by itself without running my code.

 What can I do? I am getting frustrated.

 Thanks in advance,

 Cesar 

1) Breakpoints work, however they are triggered on live price action, so you have to wait for events

2) you have to check the printouts in logs, journals keeps only shorter list of logs

3) different brokers work in different ways. some don't allow setting SL/TP on opening deal, so you have to set them later. You can check MqlTradeRequest  and ENUM_SYMBOL_TRADE_EXECUTION to recognize the use case from program. MigBank e.g. was most problematical to me as it had a different setup needed for opening orders, as it was returning a strange fault. Try using the CTrade class, maybe it will suite you.

4) i didn't have any issues with SL/TP not working and i don't believe this to be true.  the moment SL/TP is set, it gets executed.

 
tp/sl not effect may because of your broker , i just have the same problem when send a open command. and i do a modify operation right after open a new position. it work.:)
 
xhxiang:
tp/sl not effect may because of your broker , i just have the same problem when send a open command. and i do a modify operation right after open a new position. it work.:)
That is the typical ECN type Broker solution.
Let me google that for you
Let me google that for you
  • lmgtfy.com
Let Me Google That For You
 

Previous poster was correct, some brokers allow SL & TP to be set at time of trade others do not.

Best thing is to always set them after the trade has been opened this way there is less likelihood of any problems and it will work with all brokers.

Remember that brokers each have different minimum distances for these things so make sure you check the symbol info for the correct levels.

 

Reason: