Runtime bug: signal hangs, but not due to an infinite loop.

Questions about MultiCharts and user contributed studies.
User avatar
pcrespo
Posts: 49
Joined: 07 Feb 2015
Has thanked: 7 times
Been thanked: 4 times

Runtime bug: signal hangs, but not due to an infinite loop.

Postby pcrespo » 24 Aug 2016

MC version 9.1

I'm backtesting a signal in Portfolio Trader. It makes some progress then freezes and crashes PT (it stops responding after I cancel the backtest) so I have to end the PT process.

No error message and nothing in the MCPortfolio >> StudyRunner_Trace log.

So I tried debugging by printing messages to a text file.

The strategy makes long and short trades. The long trades behave fine. The code for short trades is the same except they're generated by the opposite conditions. However, from my output tests I see that the algorithm crashes the moment it tries to go short (doesn't matter if it's a market or limit order). There is one loop in my code, but it the algo crashes without even entering the loop. The short order is never filled because the market position never goes below 0.

When it attempts to go short, the code after that point successfully gets executed (I'm able to print a message at the end of the code). However, the code preceding it never gets executed again (ie the next Data1 bar is never reached). That is, I can print a message at the end of the code but not at the beginning (after the declarations) in the next cycle.

Here's what I mean:

Code: Select all

Inputs: ...
Vars: ...
Print(File(filename), "Beginning of main routine.");
...
Print(File(filename), "Going short.");
SellShort n contracts next bar market;
...
Print(File(filename), "Last line of code.");
Here's the output up to the point of the crash:

Code: Select all

Beginning of main routine.
Beginning of main routine.
...
Going short.
Last line of code.
Unfortunately, I'm not at liberty to share the code. I don't expect anyone to know exactly what's wrong just from this vague problem description. Rather, my hope is merely that people can list the possible causes for this behavior.

Thanks

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Runtime bug: signal hangs, but not due to an infinite lo

Postby TJ » 25 Aug 2016

MC version 9.1

I'm backtesting a signal in Portfolio Trader. It makes some progress then freezes and crashes PT (it stops responding after I cancel the backtest) so I have to end the PT process.

No error message and nothing in the MCPortfolio >> StudyRunner_Trace log.

So I tried debugging by printing messages to a text file.

The strategy makes long and short trades. The long trades behave fine. The code for short trades is the same except they're generated by the opposite conditions. However, from my output tests I see that the algorithm crashes the moment it tries to go short (doesn't matter if it's a market or limit order). There is one loop in my code, but it the algo crashes without even entering the loop. The short order is never filled because the market position never goes below 0.

When it attempts to go short, the code after that point successfully gets executed (I'm able to print a message at the end of the code). However, the code preceding it never gets executed again (ie the next Data1 bar is never reached). That is, I can print a message at the end of the code but not at the beginning (after the declarations) in the next cycle.

Here's what I mean:

Code: Select all

Inputs: ...
Vars: ...
Print(File(filename), "Beginning of main routine.");
...
Print(File(filename), "Going short.");
SellShort n contracts next bar market;
...
Print(File(filename), "Last line of code.");
Here's the output up to the point of the crash:

Code: Select all

Beginning of main routine.
Beginning of main routine.
...
Going short.
Last line of code.
Unfortunately, I'm not at liberty to share the code. I don't expect anyone to know exactly what's wrong just from this vague problem description. Rather, my hope is merely that people can list the possible causes for this behavior.

Thanks

It looks like MultiCharts can read and execute your signal until the Last line of code with no problem.

User avatar
pcrespo
Posts: 49
Joined: 07 Feb 2015
Has thanked: 7 times
Been thanked: 4 times

Re: Runtime bug: signal hangs, but not due to an infinite lo

Postby pcrespo » 25 Aug 2016

If it were fine, the backtest would finish and generate a performance report. Instead, it crashes at 2% completion.

My output demonstrates that it gets to the last line of code, but doesn't return to the 1st line. It's supposed to cycle, because I didn't wrap the entire code in a "once" keyword.

It cycles up until the point when it attempts to go short. That first message ("Beginning of main routine") repeats a bunch of times, but then once the "Going short" message appears, the first message does not show again.

I quoted wrong though. The 1st and last message alternate. Then the "going short" message appears, and then the last message appears once, and then the output cuts off (prematurely). Data1 is minute bars and I'm testing a 2-year period, so if not for the crash, the output would have over 2 million lines of those alternating messages.

I should have mentioned: if I change the period, the crash still only happens at the first short trade.


The most similar thing I've encountered was when I had the error,
name of the order has already been used for the other order."
When I made that mistake, the same output behavior occurred -- PT would run into the error, then finish executing to the last line, but then quit execution before returning to the 1st line.

The difference is, when I had that bug, a backtest would simply end upon bumping into the error. In my current situation, the backtest freezes forever. Also, that error showed up in the log whereas this one doesn't.

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: Runtime bug: signal hangs, but not due to an infinite lo

Postby bensat » 25 Aug 2016

Out of curiosity, do you have a file write/access authorization problem for the file generated with

Code: Select all

Print(File(filename), "Last line of code.");
?

Just asking ....

Thank you.

Regards

Ben

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Runtime bug: signal hangs, but not due to an infinite lo

Postby TJ » 25 Aug 2016

If it were fine, the backtest would finish and generate a performance report. Instead, it crashes at 2% completion.

My output demonstrates that it gets to the last line of code, but doesn't return to the 1st line. It's supposed to cycle, because I didn't wrap the entire code in a "once" keyword.

It cycles up until the point when it attempts to go short. That first message ("Beginning of main routine") repeats a bunch of times, but then once the "Going short" message appears, the first message does not show again.

I quoted wrong though. The 1st and last message alternate. Then the "going short" message appears, and then the last message appears once, and then the output cuts off (prematurely). Data1 is minute bars and I'm testing a 2-year period, so if not for the crash, the output would have over 2 million lines of those alternating messages.

I should have mentioned: if I change the period, the crash still only happens at the first short trade.


The most similar thing I've encountered was when I had the error,
name of the order has already been used for the other order."
When I made that mistake, the same output behavior occurred -- PT would run into the error, then finish executing to the last line, but then quit execution before returning to the 1st line.

The difference is, when I had that bug, a backtest would simply end upon bumping into the error. In my current situation, the backtest freezes forever. Also, that error showed up in the log whereas this one doesn't.

If MultiCharts can read and execute your code,
then the problem is not in MultiCharts.

The problem is in the logic.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Runtime bug: signal hangs, but not due to an infinite lo

Postby TJ » 25 Aug 2016

What is your computer spec?

User avatar
pcrespo
Posts: 49
Joined: 07 Feb 2015
Has thanked: 7 times
Been thanked: 4 times

Re: Runtime bug: signal hangs, but not due to an infinite lo

Postby pcrespo » 25 Aug 2016

Out of curiosity, do you have a file write/access authorization problem
Good thinking, but no. The problem happened before I had any Print statements. It's printing to the desktop folder of the logged in user, where it has all permissions.
What is your computer spec?
Windows 7 64-bit, 2-core i5, 8gb ram. Other, non-buggy signals run fine. But just now I tried the code on a fast server and got the same problem. PT freezes at the same progress point, stops responding and has to be killed by Windows.


Return to “MultiCharts”