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

Created at 27 May 2022, 10:40
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!
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