Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Performace.AllTrades question

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

    Performace.AllTrades question

    Hi,

    I am trying to understand how to track my profits / losses within the Strategy code. I thought if I did the code below I would get it. I even tried resetting my simulation account and then I am printing output. The output prints me the following. This is wrong because I have reset my simulation account and I am doing this in simulation mode on the on Bar Update. Please tell me what I am supposed to be doing. I was expecting to be seeing a profit of 0 not -359 ? Thanks

    11/2/2011 3:13:00 AM Cumalivtive Profit is -359.999999999999

    cumprofit = Performance.AllTrades.TradesPerformance.Currency.C umProfit; // Calculate the cumprofit all strategy days
    PrintWithTimeStamp("Cumalivtive Profit is " + cumprofit);

    #2
    sqadri, this figure would not be aligned to your sim account performance, but the strategy's historical and realtime trades taken (AllTrades collection), so the individual strategy performance basically.

    For account performance in realtime check into the GetAccountValue() method -

    Comment


      #3
      Hi,

      Thank you. I went to the link and I am interested in Profit and Loss so should I be using AccountItem.RealizedProfitLoss ? What Profit and Loss does this show me ? Is is suppose to show me my entire profit and loss across all trades both manual and strategies ? I couldn't find the detail to this.

      Thanks a lot..

      Comment


        #4
        The PNL would only be tied to this specific strategy, the manual trades could unfortunately not be accessed from NinjaScript.

        The Performance class also differentiates between

        All Trades - historical and realtime
        Realtime - realtime only

        for the strategy trading performance reporting.

        Comment


          #5
          Thank you so much. I was able to get what I wanted using the Get AccountValue as you had suggested. However, I am still having some issues. Basically what I wanted to do was shut off or disable my strategy after I reach a certain Realized Profit. I copied the StopStrategy function from your sample SampleHaltBasicStrategy code but it's not working. Here is my code :

          RealizedProfitLoss = GetAccountValue(AccountItem.RealizedProfitLoss);

          if (RealizedProfitLoss >= 400)
          {
          Print("Calling STOP");
          StopStrategy(); }
          My Strategy works fine until I hit the Profit target of 400 then I get this error in the output window :

          Calling STOP
          **NT** Error on calling 'OnBarUpdate' method for strategy 'BollingerStrategyGeneric/b2362dd7d0174d58960ebe8021db6f2e': Object reference not set to an instance of an object.

          Can you tell me what I should be doing if I need to disable my strategy after a certain profit / loss is reached ?

          Thanks

          Comment


            #6
            sqadri,

            I am happy to assist you.

            From the reference sample, it is using :

            Code:
            Performance.AllTrades.TradesPerformance.Currency.CumProfit > 1000
            Generally this error occurs mainly when one tries to access an object that doesn't exist, or when you try to access an object's properties while that object is null (which means the properties don't exist).

            I would suggest using the method from the reference sample.

            Please let me know if I may assist further.
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Thanks Adam.

              I thought I shouldn't be using Performance.AllTrades.TradesPerformance.Currency.C umProfit because it doesn't give me an accurate picture about my Profits / Losses. I am now confused :-(

              Initially I was using the Performance.AllTrades.TradesPerformance.Currency.C umProfit but I was noticing it was giving me some other number then I found out it's not meant only for Real Trades it also includes historical trades.

              My objective is I think very simple. I am running a Strategy A for eg. Once the Strategy has made X amount of Profit or Y amount of Loss I just want to turn off / disable the strategy until the next day when my Profit and or loss should be reset through my broker and I can manually re-enable the strategy. I hope the objective is clear. In that case should I be using Performance.AllTrades.TradesPerformance.Currency.C umProfit or AccountItem.RealizedProfitLoss or something else completely ?

              Thank you.

              Comment


                #8
                Hello sqadri,

                Please take a look at this reference sample:


                This can help you accomplish this using TradePerformance:
                Locking in realized profits after a certain amount of gains have been achieved during the trading session
                Cutting realized losses short after a certain amount of losses have been accrued over the trading session
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks a lot. That worked.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  672 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  379 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  111 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  577 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  582 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X