Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 stafe, 04-15-2024, 08:34 PM
        6 responses
        30 views
        0 likes
        Last Post stafe
        by stafe
         
        Started by adeelshahzad, Today, 03:54 AM
        4 responses
        25 views
        0 likes
        Last Post adeelshahzad  
        Started by merzo, 06-25-2023, 02:19 AM
        10 responses
        823 views
        1 like
        Last Post NinjaTrader_ChristopherJ  
        Started by frankthearm, Today, 09:08 AM
        5 responses
        17 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        43 views
        0 likes
        Last Post jeronymite  
        Working...
        X