net profit and direction of the last trade

Created at 07 Jul 2018, 12:12
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!
SK

skalkas

Joined 27.04.2016

net profit and direction of the last trade
07 Jul 2018, 12:12


Hello, please

can smbd help and provide us with the code, which will retriev he  net profit and the direction of the last closed trade? Thank you  


@skalkas
Replies

ap11
09 Jul 2018, 15:23

Hi Skalkas,

Please see the code below:

var lastTrade = History.LastOrDefault();
if (lastTrade != null)
{
    Print("Last trade {0} {1}, profit: {2}", lastTrade.TradeType, lastTrade.SymbolCode, lastTrade.NetProfit);
}

Regards,
Andrey


@ap11

skalkas
09 Jul 2018, 15:44

Hello Andrey,

thank you...this one works as a pront log, but what Iam trying is to fill with those two values some variables....something like this, but it creates an error...and I dont now whats wrong:

var lastTrade = History.LastOrDefault();
if (lastTrade != null)
{
    Print("Last trade {0} {1}, profit: {2}", lastTrade.TradeType, lastTrade.SymbolCode, lastTrade.NetProfit);
}
 
var netpprofit = lastTrade.NetProfit;
var tradetype = lastTrade.TradeType;

@skalkas

ap11
09 Jul 2018, 15:59

You should check if lastTrade is not null. If History is empty, it will be null. And you will get NullReference exception


@ap11

skalkas
09 Jul 2018, 16:30

I see, that was the problem. Thank you very much.


@skalkas