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

How to get the balance of my last trade closed in NT8 strategy builder?

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

    How to get the balance of my last trade closed in NT8 strategy builder?

    Hello.
    I need to know if my last trade closed was profitable or not.
    How can i get that info in strategy builder NT8?

    #2
    Hi fscabrera03,
    Please see this thread here. Was posted in the NT7 section, but the principle is still applicable.

    NT-Roland

    Comment


      #3
      Thank you bro

      Comment


        #4
        Hello fscabrera03,

        Welcome to the NinjaTrader forums!

        NT-Roland, thanks for providing the link to information.

        The SystemPerformance.AllTrades is a Trades collection will contain information about closed trades.

        The <Trade>.Currency is a property with the pnl of that trade.

        For example:
        Code:
        Print(SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count -  1].Currency);
        Below are direct links to the help guide.


        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          What about for multiple instrument strategies? Is there a way to get the last trade of the current series BarsInProgress?

          Comment


            #6
            Hello mase2005,

            Thanks for your note.

            You could consider creating a condition that checks if BarsInProgress == 1 and access the SystemPerformance.AllTrades collection to get the last trade made on that added instrument.

            For example, the sample code might look something like this.

            Code:
            if (BarsInProgress == 1)
            {
                    if (CrossAbove(smaFast, smaSlow, 1))
                         EnterLong("myEntrySignal");
                    else if (CrossBelow(smaFast, smaSlow, 1))
                         EnterShort("myEntrySignal");
            
                     if (SystemPerformance.AllTrades.Count > 1)
                     {
                          Trade lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];
            
                          Print("The last trade profit is " + lastTrade.ProfitCurrency + " " + BarsInProgress + " " + lastTrade.TradeNumber);
                     }    
            }​
            See the help guide documentation linked by my colleague Chelsea in post # 4 for more information and sample code.

            And, see this help guide page about working with multi-timeframe / multi-instrument NinjaScripts: https://ninjatrader.com/support/help...nstruments.htm

            Let me know if I may assist further.
            Last edited by NinjaTrader_BrandonH; 10-24-2022, 09:34 AM.
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Thanks for your reply. I am submitting orders to multiple instruments, and need to retrieve the last trade for the current BarsInProgress. For example, say I have 4 instruments, and have submitted orders on each. In OnBarUpdate, I need to get the last trade for the current BarsInProgress (need to do this for each instrument).

              Comment


                #8
                Hello mase2005,

                Thanks for your note.

                After further investigation, we see that the SystemPerformance TradeCollection will get the last trade that was made by the strategy in general. To get a trade that was placed on a specific instrument, you could consider using the GetTrades() method.

                See this help guide page for more information about GetTrades(): https://ninjatrader.com/support/help.../gettrades.htm

                See this help guide page for more information about using TradeCollection: https://ninjatrader.com/support/help...collection.htm

                Let me know if I may assist further.
                Brandon H.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you. This is closer to what I'm looking for. Is the 'entrySignalName' and 'instance' required or optional? (I'm using multiple entry signal names, and need to get the last trade on that instrument regardless of entry signal name)

                  Comment


                    #10
                    Hello mase2005,

                    Thanks for your note.

                    You could consider passing an empty string in for the entrySignalName property when calling GetTrades(). This would get any trades placed on that instrument regardless of entrySignalName.

                    The code might look something like below.

                    Code:
                    TradeCollection myTrades = SystemPerformance.AllTrades.GetTrades("ES 12-22", "", 1);
                    Let me know if I may assist further.
                    Brandon H.NinjaTrader Customer Service

                    Comment


                      #11
                      Perfect. Thank you!!!!

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by elirion, Today, 01:36 AM
                      0 responses
                      3 views
                      0 likes
                      Last Post elirion
                      by elirion
                       
                      Started by gentlebenthebear, Today, 01:30 AM
                      0 responses
                      4 views
                      0 likes
                      Last Post gentlebenthebear  
                      Started by samish18, Yesterday, 08:31 AM
                      2 responses
                      9 views
                      0 likes
                      Last Post elirion
                      by elirion
                       
                      Started by Mestor, 03-10-2023, 01:50 AM
                      16 responses
                      391 views
                      0 likes
                      Last Post z.franck  
                      Started by rtwave, 04-12-2024, 09:30 AM
                      4 responses
                      34 views
                      0 likes
                      Last Post rtwave
                      by rtwave
                       
                      Working...
                      X