Use of Comment() when backtesting

User avatar
slipshod
Trader
Posts: 404
Joined: Tue Dec 27, 2011 9:14 am
Location: Australia

Use of Comment() when backtesting

Post by slipshod »

Hi everyone, firstly my thanks to Steve & everyone who contributes here for such an informative forum :)

I'll try and keep things short - I got into forex after being "let go" from (programming) my day job & threw myself into it all guns blazing. Six months later I had to face the unfortunate truth that as a trader I make a good programmer.

So, convinced that the strategy I'd developed was basically sound & should be profitable if traded by someone without emotions who just follows the rules, I decided it was time to develop my own EA. Over the last 2 months I've been merrily clicking away deep into the night, and finally am at the point where I'm running some basic backtests.

Here I've run into a bit of a problem. How can I tell that the EA is doing what I designed for it to do? When running the EA in normal time I can make it print to the screen via Comment(), and display a bunch of info that tells me exactly what its doing & why. I can compare that to indicators etc & verify that its working properly (or not).

However, when I try this with backtesting in visual mode, the comments flicker on the screen every now & then for a nanosecond, then are gone. I'm basically blind & can't tell precisely why its trading as it is, which is pretty frustrating.

Has anyone else run into this problem, and is there any way around it? Thanks in advance :)
MichaelM
Trader
Posts: 117
Joined: Sun Dec 04, 2011 11:04 pm

Re: Use of Comment() when backtesting

Post by MichaelM »

Use Print (like Comment). It outputs to the Experts tab.
User avatar
slipshod
Trader
Posts: 404
Joined: Tue Dec 27, 2011 9:14 am
Location: Australia

Re: Use of Comment() when backtesting

Post by slipshod »

Thanks but ... unfortunately the Strategy Tester doesn't have an Experts tab, so its not much use for backtesting. Print() does write to a file in tester\logs, however the information only gets saved to the file hundreds of candles after the event (seems to be buffered by the system).
MichaelM
Trader
Posts: 117
Joined: Sun Dec 04, 2011 11:04 pm

Re: Use of Comment() when backtesting

Post by MichaelM »

Sorry, I meant Journal tab.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Use of Comment() when backtesting

Post by SteveHopwood »

All my bots, and the shell, have this snippet in the leading comment block:

Code: Select all

Code for adding debugging Sleep
Alert("G");
int x = 0;
while (x == 0) Sleep(100);
When I am bug-hunting, I replace "G" in the Alert with whatever thingy it is I am looking at - the value of a variable etc. The Sleep stops the code execution at that point, so the Alert is the last thing in the Journal tab.

:D
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
slipshod
Trader
Posts: 404
Joined: Tue Dec 27, 2011 9:14 am
Location: Australia

Re: Use of Comment() when backtesting

Post by slipshod »

Thanks guys - why did I never think to check the Journal? Amazing how easy it is to miss obvious things.

Nice suggestion re the use of Alert too, will definitely put that to good use :)
Raiden
Posts: 8
Joined: Sat Jan 28, 2012 5:50 am

Re: Use of Comment() when backtesting

Post by Raiden »

slipshod wrote: However, when I try this with backtesting in visual mode, the comments flicker on the screen every now & then for a nanosecond, then are gone.
That's bizarre, the only way I think that could happen is that you placed your Comment(), or whatever function with your Comment() in it, in a loop within the Start(). Try placing it in the main body of the Start() itself. You want to make sure it executes every tick.

Edit: for illustration, check out http://raidenworks.com/2012/01/25/drawdown/, and
skip to the header MQL4 Code:

You can see that the Comment() is in the main body of Start(). Don't nest it in anything else. (Unless you are printing error logs which are time specific.)

A little further down the screenshot of the comment field that appears.
User avatar
slipshod
Trader
Posts: 404
Joined: Tue Dec 27, 2011 9:14 am
Location: Australia

Re: Use of Comment() when backtesting

Post by slipshod »

No, I can assure you it was in Start() and not nested at all.

I think its because I had too many indicators running at the time - I've found that when I ran it with no indicators visible the problem went away. Also, when I had a lot of indicators on the screen, objects I added manually (trendlines etc) would disappear the next tick, and again its not something I see when there's nothing but candles.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Use of Comment() when backtesting

Post by SteveHopwood »

slipshod wrote:No, I can assure you it was in Start() and not nested at all.

I think its because I had too many indicators running at the time - I've found that when I ran it with no indicators visible the problem went away. Also, when I had a lot of indicators on the screen, objects I added manually (trendlines etc) would disappear the next tick, and again its not something I see when there's nothing but candles.
Some indi's display a comment. When you call indi's from within an ea, they briefly display their comment, which is then replaced by your ea's comment or one of the other indi's comment. This causes the flicker.

Where you have the source for the indi, find the Comment() and delete it. Where you do not have the source, save the .ex4 under a different name, decompile it, delete the Comment and use the decompiled version instead.

Also, many custom indi's are dreadfully coded. Some will merely delete all objects of the type they are using, regardless of whether the indi created it or not.

You will quickly come to loathe these blasted things as much as I do.

:D
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
Raiden
Posts: 8
Joined: Sat Jan 28, 2012 5:50 am

Re: Use of Comment() when backtesting

Post by Raiden »

SteveHopwood wrote:
slipshod wrote:No, I can assure you it was in Start() and not nested at all.

I think its because I had too many indicators running at the time - I've found that when I ran it with no indicators visible the problem went away. Also, when I had a lot of indicators on the screen, objects I added manually (trendlines etc) would disappear the next tick, and again its not something I see when there's nothing but candles.
Some indi's display a comment. When you call indi's from within an ea, they briefly display their comment, which is then replaced by your ea's comment or one of the other indi's comment. This causes the flicker.
That makes much sense. As for having lots of indicators onscreen, I can attest that having about 8, both main and sub-window, does not affect my comment field. Might be possible that one of the indicators has a memory leak too, might explain why the comment field disappears completely after a while.
SteveHopwood wrote:Where you have the source for the indi, find the Comment() and delete it. Where you do not have the source, save the .ex4 under a different name, decompile it, delete the Comment and use the decompiled version instead.
Another work around would be to create labels(ObjectCreate(), ObjectSetText(), ObjectSet()) instead of using Comment(). Worth doing as you can manipulate the information display better, e.g. colour, font, fontsize, etc..
Post Reply

Return to “Coders Hangout”