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

Time of entry

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

    Time of entry

    How could I get the time of the current position entry?

    #2
    Hi frslvr, thanks for posting.

    For historical data, you can save the value of Time[0] before or after the entry line e.g.

    DateTime entryTime = Time[0];
    EnterLong();

    For real time, you can save the DateTime.Now variable within OnOrderUpdate to capture the system time when the order is filled.

    Another way to get this would be to use BarsSinceEntryExecution and then use that bar number in Time[] to get the proper index.

    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris,

      Thank you for your reply.
      I actually want to create an add-on displaying timer of how long the current trade is active. I thought there might be a property somewhere at account.Positions.
      Ideally, I would like to use something like account.Positions[0].Time
      Maybe you could suggest some other workaround?

      Thanks

      Comment


        #4
        Maybe I can get it this way?
        Code:
        Execution exec = account.Executions.FirstOrDefault(e => e.Instrument == chartTrader.Instrument && e.IsInitialEntry);
        exec.Time
        But seems like not enough conditions to match the execution I'm looking for.

        Comment


          #5
          LastOrDefault seems to deliver it

          Comment


            #6
            Hi frslvr, thanks for your reply.

            Note that the Account.Executions collection is erased every after every market session. There is no supported NinjaScript code to get historical execution data from the database. The best way to ID an execution is from the Execution.OrderId property. Assuming your script was running at the time the trade was placed it can capture execution data from the Account.ExecutionUpdate event, write it to a .json file, and load the data when NinjaTrader starts up. The purpose of all this would be to cover the case where you enter a trade, close out of NinjaTrader, then need the addon to pick up from where it left off on the next startup. If you are only interested trades made in the current session the addon can subscribe to ExecutionUpdate and all the data including a timestamp will be available.

            Best regards,
            -ChrisL

            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Shansen, 08-30-2019, 10:18 PM
            24 responses
            940 views
            0 likes
            Last Post spwizard  
            Started by Max238, Today, 01:28 AM
            0 responses
            9 views
            0 likes
            Last Post Max238
            by Max238
             
            Started by rocketman7, Today, 01:00 AM
            0 responses
            4 views
            0 likes
            Last Post rocketman7  
            Started by wzgy0920, 04-20-2024, 06:09 PM
            2 responses
            28 views
            0 likes
            Last Post wzgy0920  
            Started by wzgy0920, 02-22-2024, 01:11 AM
            5 responses
            33 views
            0 likes
            Last Post wzgy0920  
            Working...
            X