Querying historical trades in backtester crashes
Querying historical trades in backtester crashes
13 May 2014, 06:37
I have a function that calculates the realized profit (of closed trades) generated by the robot.
The function is called only when a position is closed. It is NOT called by OnTick - so it is not really CPU intensive.
The following code calculates the realized profit.
double RealizedPL = 0.0; string tradeLabel = string.Format("hx:{0}", m_Magic); foreach (HistoricalTrade histTrade in History) { if( histTrade.SymbolCode != Symbol.Code ) continue; if( !histTrade.Label.Contains(tradeLabel) ) continue; RealizedPL += histTrade.NetProfit; }
In the back-tester after few trades, it crashes the cAlgo application and I have to launch the application again. If I comment out the above lines of code, the back-tester works fine without crashing (but I cannot calculated the closed PL).
I works fine in live mode (even if there are hundreds of closed trades) - and the calculations are correct.
Note : The Label.Contains method is used to filter based on "tradeLabel". History.FindAll cannot be used because the Label contains additional data. e.g. "hx:29292:3", "hx:29292:4" etc.
So the question is - what is causing the back-tester to crash ? And what would be the solution ?
Replies
Spotware
13 May 2014, 09:02
Unfortunately we cannot reproduce this issue. We kindly ask you to send us the source code of your cBot. We will use it for debugging purposes only.
Also, is there a way to detect whether the robot is running is live-mode or in back-tester mode ?
You can use IsBacktesting property to check that cBot is running in backtesting.
@Spotware
AlexanderRC
30 Aug 2014, 20:17
RE:
adheer said:
Note : The Label.Contains method is used to filter based on "tradeLabel". History.FindAll cannot be used because the Label contains additional data. e.g. "hx:29292:3", "hx:29292:4" etc.
As a general suggestion, you can also use the comment property of a position to store some data.
@AlexanderRC
adheer
13 May 2014, 06:56
Here is the crash signature :
Also, is there a way to detect whether the robot is running is live-mode or in back-tester mode ?
@adheer