Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting the Time of Last Trade

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Getting the Time of Last Trade

    Hi,

    I was wondering if there was any way to get the time of last trade as I'd like to find out the time at which I got stopped out of a trade.

    Also, is there a way I could retrieve the last stored entry for SetStopLoss() or find out the last price a trade occured at?

    Thanks

    #2
    Hi wuileng, you can get the bar of the last entry with BarsSinceExit() and then just reference the bar time from there. So if BarSinceExit() returns 5, you can get the bar time of the exit with Time[5].

    Unfortunately there isn't a way to retrieve the last stored entry for SetStopLoss() unless you store the values passed to it in another variable.

    To find the last price a trade occured at, you can use Trade class objects. Please see this reference for similar concepts. It can be adapted for your use.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Thanks! I tried to use the following to store the last trade's exit price in prevstop (double) but it says that it cannot implicitly convert the IExecution object to a double. What can I do about this?

      Trade lasttrade = Performance.AllTrades[0];
      prevstop = lasttrade.Exit;

      Comment


        #4
        Wuileng, the entries and exits provided are IExecutions and you can get the price data from those IExecutions. The code you posted just needs another step:
        Code:
        Trade lasttrade = Performance.AllTrades[0];
        IExecution lasttradeExit = lasttrade.Exit;
        // IExecution lasttradeEntry = lasttrade.Entry;
        double prevstop = lasttradeExit.Price;
        AustinNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        571 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        331 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        549 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        550 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X