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.");
Code: Select all
Beginning of main routine.
Beginning of main routine.
...
Going short.
Last line of code.
Thanks