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

Trade Object from Executions

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

    Trade Object from Executions

    I have an Indicator which subscribes to ExecutionUpdate, so I can track all of my Executions.
    What I want to do now is to create Trades from these Executions, which I can then export for example.

    The trade object can be created like this:
    Code:
    Trade trade = new Trade(entryExecution, exitExecution, qty);
    so every trade consists of an entry and exit execution.

    When I just use simple orders with one buy and one sell then this code could work:
    Code:
    private Execution entryExecution = null;
    private void OnExecutionUpdate(object sender, ExecutionEventArgs e)
    {
        Execution execution = e.Execution;
    
        // doesn't work with position scaling
        if (entryExecution == null)
        {
            entryExecution = execution;
        }
        else
        {
            trade = new Trade(entryExecution, execution, 1);
            entryExecution = null;
            Print("Trade: " + trade);
        }
    }​
    but when it comes to multiple orders with different quantities and position scaling, this doesn't work.

    Is there an easier way to extract trades from executions similar to the way they are displayed in the Trade Performance tab? Or do I need to manually calculate these with all the order handling metrics?

    #2
    Hello SantoshXX,

    Thanks for your post.

    The SystemPerformance collection could be used to get TradesPerformance information from the TradeCollection. Note that a trade is considered a buy and a sell.

    See the help guide documentation below for more information about accessing trades in the TradeCollection.

    SystemPerformance: https://ninjatrader.com/support/help...collection.htm
    TradeCollection: https://ninjatrader.com/support/help...collection.htm
    TradesPerformance: https://ninjatrader.com/support/help...erformance.htm
    Trade: https://ninjatrader.com/support/help.../nt8/trade.htm
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the reply!

      It seems like SystemPerformance only works for trades placed within a strategy. What I'm looking for are the trades that are manually placed, I want to access them in an Indicator.








      Comment


        #4
        Hello SantoshXX,

        Thanks for your notes.

        Correct, SystemPerformance would return trades placed by a strategy. There would not be a simpler way to track manual trades made in an indicator script.

        To accomplish this in an indicator you would need to come up with your own custom logic calculate these with all the order handling metrics as you noted in post # 1.

        To do this in an indicator you will need to set up an account object similar to the example code on the Account help guide page. After that is set up, you can get an Execution collection from the Account object. With the Execution collection you could create "Trades", comprising of an entry execution and an exit execution.

        Note that at this time there is not a supported method to retrieve historical executions from the local database. We are tracking interest for this in an internal feature request to get the Trade Collection information in an indicator or addon. Please let me know if you would like me to add your vote to this feature request.​

        Account: https://ninjatrader.com/support/help...ghtsub=account
        ExecutionUpdate: https://ninjatrader.com/support/help...tionupdate.htm
        Executions: https://ninjatrader.com/support/help...executions.htm
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Thanks for the answer, Brandon!

          Yes this feature would be really helpful, please add my vote to this feature request. Thank you!

          Comment


            #6
            +1

            Please add my vote.

            Comment


              #7
              Hello SantoshXX and bltdavid,

              Thanks for your notes.

              I have added both of your votes to the feature request.

              This request is being tracked under the number SFT-586.

              As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted on the Release Notes page of the Help Guide.

              Release Notes — https://ninjatrader.com/support/help...ease_notes.htm
              Brandon H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by nissan200sx55, Yesterday, 06:25 AM
              2 responses
              13 views
              0 likes
              Last Post nissan200sx55  
              Started by fredericlebre, Today, 01:19 AM
              1 response
              14 views
              0 likes
              Last Post NinjaTrader_Erick  
              Started by NM_eFe, Yesterday, 05:15 PM
              1 response
              11 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by cmtjoancolmenero, 04-29-2024, 03:40 PM
              25 responses
              81 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by TraderIqbal, 10-20-2023, 10:12 AM
              3 responses
              123 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Working...
              X