How can I see the date of the last trade taken?

Created at 06 Apr 2017, 14:17
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!
C.

c.ostmo

Joined 05.04.2017

How can I see the date of the last trade taken?
06 Apr 2017, 14:17


I'm trying to limit my robot to one buy trade and one sell trade per day. If I've done this right, I have applied a label to my trades:

 

                    var result = ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "Sell", StopLoss, TakeProfit);
                    if (!result.IsSuccessful)
                    {
                        Print("Stoping cBot due to failure to execute market order");
                        Stop();
                    }

 

But when I try to retrieve the date and compare it to the current date:


                HistoricalTrade lastSellTradeDate = History.FindLast("Sell");
                DateTime openTime = MarketSeries.OpenTime.LastValue;
                DateTime currentDate = MarketSeries.OpenTime.LastValue.Date;

                Print("Current Date is " + currentDate + " and last trade was taken " + lastSellTradeDate);

 

Everything is printed except "lastSellTradeDate". Am I doing something wrong? Or, is there a better way to do this?


@c.ostmo
Replies

c.ostmo
06 Apr 2017, 14:23

RE:

Just to be clear, trades are definitely being take, and that line is printed after each one. None of them in the log have any date for the last trade.


@c.ostmo

c.ostmo
06 Apr 2017, 14:46

I know I have no idea what I'm doing. I needed something like this:

                HistoricalTrade lastSell = History.FindLast("Sell");
                Print(lastSell.ClosingTime);

However, is there anyway to get the closing date? Will "ClosingTime" return the date, or just the time of day?

Also, this produces an error: "Crashed in OnTick with NullReferenceException: Object reference not set to an instance of an object." What am I missing? (If you could talk to me like I have no idea what I'm doing, I would appreciate it)


@c.ostmo