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

Realized PnL not getting reset

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

    Realized PnL not getting reset

    Hi
    I am working on a strategy to limit trading only when the profit goal hasnt been reached or the loss limit haa not been reached.

    I was able to set the condition inside the Strategy Builder. No Issues there.

    But when I run it, I found out that the value of Realized PnL iwas already beyond the profit/loss limits , so no order was going through.

    I put a text drawing the chart and found out that the Realized PnL value was 200.

    So, I quit the Playback Session and started a new PLayback Session. That didnt work.

    I tried resetting the database (I saw a post along those lines in the forum somewhere..) and that didnot work either.

    Can you guide me as to how I can reset the Realized PnL value (without having to write code to do that..)?

    Or suggest a code clip that I can incorporate in the ninja script?

    Thanks for your help.


    Regards.


    #2
    Hello shanshan1001,

    Thank you for your post.

    From the provided details I would not be certain what happened in this test however this could potentially be related to which performance collection is being used. Were any historical trades placed which equated to 200 PnL? Could you provide a screenshot of the conditions you made to support your question further?

    If you had historical trades that equated to this amount that may explain the reason it stopped taking trades, or that it took some historical trades up to what your condition required.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi
      Thanks for your response.. I dont have much else to share..

      Here is the sample code I get using the strategy builder..

      if ((SystemPerformance.AllTrades.TradesPerformance.Cu rrency.CumProfit >= DailyProfitTarget)
      || (SystemPerformance.AllTrades.TradesPerformance.Cur rency.CumProfit <= DailyMaxLoss))
      {
      PlaySound(@""); // this is sample action
      }

      1. Is that the right performance collection when using Historical Data or Playback Data?

      2. Is that the right performance collection when using live data with SIM account?

      3. Is that the right performance collection when using live data and real money account?

      4. What is the Ninja Script command to terminate the strategy from running?

      Can you please guide me?

      Thanks.

      Comment


        #4
        Hello shanshan1001,

        Thank you for providing that.

        To explain the condition better we can start with the trade collection we see is being used. The builder is specifically using the All Trades collection which includes historical trades.

        If your strategy was placing any historical trades before playback began this limit would be reached before you start playing the data forward. If this is what is happening, that would explain the result if this condition also controls the trading. You can view the strategies historical performance report from the chart where it is applied to verify if it placed historical trades and see where the condition stopped working.

        To answer your questions, this collection does work when using all modes and is the right collection to use for certain use cases. This would not likely be one of those use cases if the expectation is to run in realtime while also allowing the strategy to place historical trades and accumulate historical profits. The trade collection is unable to be reset and will include all of the strategies trades.

        To fix the problem you would need to prevent the strategy from placing historical trades so its profit starts at 0, from that point your strategy could work as expected.

        To stop a strategy from running this would be something you need to unlock it to do if you want to physically disable its. We have some samples in the following post: https://ninjatrader.com/support/help...nce_user_d.htm

        I look forward to being of further assistance.


        JesseNinjaTrader Customer Service

        Comment


          #5
          Thank you for your response.

          I am paraphrasing -
          when testing strategies with historical data, the realizd PnL value will be inherited from the test run with historical data even after you switch to live data and live account??. Is my understanding correct?

          In order to avoid this, I should not be placing trades with historical data but only see how the strategy would have played out by looking at the trader markers?

          Please confirm.

          How do I ever reset the Realized PnL value?? Can I write a custom code to reset that value??

          BTW - that link was very helpful!! Thanks!!!!


          Comment


            #6
            Hello shanshan1001,

            Thank you for your reply.

            when testing strategies with historical data, the realizd PnL value will be inherited from the test run with historical data even after you switch to live data and live account??. Is my understanding correct?
            I am not certain I understand how you worded this question, the AllTrades collection will contain trades since the strategy was enabled. If you are talking about switching from sim to live, that would not be included as those are separate accounts.

            In order to avoid this, I should not be placing trades with historical data but only see how the strategy would have played out by looking at the trader markers?
            What I had noted was that if you have historical trades being placed a solution would be to avoid placing historical trades in that use case. If you are specifically trying to work forward in realtime from a starting point of 0, and the strategy is placing historical trades and reaching the limit before you start playback the solution would be to prevent historical trades. You can confirm if this is happening by looking at the strategies historical performance report before you start playback but after enabling it.

            How do I ever reset the Realized PnL value?? Can I write a custom code to reset that value??
            There is no way to reset the trade collection aside from restarting the strategy. In manual coding you can add logic to account for new sessions, in the builder you would be limited to using the current value of the properties being used.


            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              What collection should I use if I only want to refer to trades made with Real Money account? (Live Account)

              Comment


                #8
                Hello shanshan1001,

                You would use the same collections, the account is selected when you enable the strategy. If you use the live account when you enable the script, the collection would represent the trades placed to the live account. This will still contain historical trades the strategy placed while calculating if you use the AllTrades collection because those are still part of your strategies performance. If you specifically wanted only live trades you could also use the RealTimeTrades collection as that would only contain realtime placed orders.
                ​​​​​​​https://ninjatrader.com/support/helpGuides/nt8/en-us/realtimetrades.htm

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Late to this post, but just wanted to add to what Jesse recommended using another great example available on the NT8 API help/guide. (I was just searching for this myself and came across this thread so wanted to add value by sharing what I found works for me.)

                  You won't be able to reset the collection, but you can take the delta of the current session from the prior session and you'll get the relevant stats for current session only.


                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by helpwanted, Today, 03:06 AM
                  1 response
                  8 views
                  0 likes
                  Last Post sarafuenonly123  
                  Started by Brevo, Today, 01:45 AM
                  0 responses
                  7 views
                  0 likes
                  Last Post Brevo
                  by Brevo
                   
                  Started by aussugardefender, Today, 01:07 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post aussugardefender  
                  Started by pvincent, 06-23-2022, 12:53 PM
                  14 responses
                  242 views
                  0 likes
                  Last Post Nyman
                  by Nyman
                   
                  Started by TraderG23, 12-08-2023, 07:56 AM
                  9 responses
                  385 views
                  1 like
                  Last Post Gavini
                  by Gavini
                   
                  Working...
                  X