Find historical trade using Contains() on Label

Created at 30 Oct 2023, 07:59
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!
AB

abdul.latiff.hashim

Joined 01.07.2020

Find historical trade using Contains() on Label
30 Oct 2023, 07:59


Hi,

I want to find some historical trades that meet criteria such as a certain string contained in the label. Is this correct?

protected override void OnTick()
{
            var Str = "ABCDEF";

            ExecuteMarketOrder(TradeType.Sell, SymbolName, Symbol.VolumeInUnitsMin, Str);
            ClosePosition(Positions.Find(Str));

            var X = History.Where(T => T.Label.Contains("ABC")).Count();
            Print(X);
}

This code return error during Count() function…

30/10/2023 15:49:17.632 | Crashed in OnTick with NullReferenceException: Object reference not set to an instance of an object.

Please help me do it correctly.

Thanks.


@abdul.latiff.hashim
Replies

PanagiotisChar
31 Oct 2023, 07:32

Hi Abdul,

Try

History.Where(T => T.Label != null && T.Label.Contains("ABC")).Count()

 


@PanagiotisChar