Announcement

Collapse
No announcement yet.

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.
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            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.
                <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                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.
                    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                    Comment


                      #11
                      Perfect. Thank you!!!!

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by NullPointStrategies, Today, 05:17 AM
                      0 responses
                      53 views
                      0 likes
                      Last Post NullPointStrategies  
                      Started by argusthome, 03-08-2026, 10:06 AM
                      0 responses
                      130 views
                      0 likes
                      Last Post argusthome  
                      Started by NabilKhattabi, 03-06-2026, 11:18 AM
                      0 responses
                      70 views
                      0 likes
                      Last Post NabilKhattabi  
                      Started by Deep42, 03-06-2026, 12:28 AM
                      0 responses
                      44 views
                      0 likes
                      Last Post Deep42
                      by Deep42
                       
                      Started by TheRealMorford, 03-05-2026, 06:15 PM
                      0 responses
                      49 views
                      0 likes
                      Last Post TheRealMorford  
                      Working...
                      X