Querying historical trades in backtester crashes

Created at 13 May 2014, 06:37
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
AD

adheer

Joined 13.05.2014

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 ?

 

 

 


@adheer
Replies

adheer
13 May 2014, 06:56

Here is the crash signature :

Problem signature:
  Problem Event Name:	APPCRASH
  Application Name:	cAlgo.exe
  Application Version:	1.21.34315.47301
  Application Timestamp:	5370b392
  Fault Module Name:	clr.dll
  Fault Module Version:	4.0.30319.17929
  Fault Module Timestamp:	4ffa5753
  Exception Code:	c00000fd
  Exception Offset:	00002cd0
  OS Version:	6.1.7601.2.1.0.256.1
  Locale ID:	1033
  Additional Information 1:	f591
  Additional Information 2:	f591647bb6b16aa45c599c556a2b4760
  Additional Information 3:	6973
  Additional Information 4:	6973df2c28c5c1895f0e64d5565cb52b

 

Also, is there a way to detect whether the robot is running is live-mode or in back-tester mode ?


@adheer

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