How to check last closed position type buy or sell was ...

Created at 27 May 2022, 10:40
MongolTrader's avatar

MongolTrader

Joined 12.02.2015

How to check last closed position type buy or sell was ...
27 May 2022, 10:40


How to check last closed position type whether was buy or sell ...


cTrader Automate
@MongolTrader
Replies

firemyst
29 May 2022, 13:57

If you know the symbol and gave the position a unique label, you could also look for it in the "HistoricalTrade" collection.

Example:

HistoricalTrade ht = History.FindLast(p1.Label, p1.SymbolName);


@firemyst

amusleh
30 May 2022, 09:52

Hi,

Try this:

            var lastTrade = History.OrderBy(trade => trade.ClosingTime).LastOrDefault();

            if (lastTrade != null)
            {
                // Do something
            }

 


@amusleh