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

GetAtmStrategyRealizedProfitLoss after AtmStrategyClose

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

    GetAtmStrategyRealizedProfitLoss after AtmStrategyClose

    Hi,

    Calculating the PnL on an ATM Strategy on Ninja 8 is not working the same as on Ninja 7 ;

    It looks like GetAtmStrategyRealizedProfitLoss(atmid) is not giving results if the position was previously closed by AtmStrategyClose(atmid).

    I attach a simple example code ; it enters long if close>open
    and closes the position if it lasts more than 2 bars
    ( on this case, the reported pnl is zero )
    Attached Files
    pmaglio
    NinjaTrader Ecosystem Vendor - The Indicator Store

    #2
    Hello,

    Thank you for the post.

    I tried applying this script to a chart and allowed it to run, I do see that some values are being reported for the PnL you are printing:

    Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


    Can you tell me, was the PnL reported exactly zero on your end or could you provide a past of the output you had seen?

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

    Comment


      #3
      Hi...

      Try increasing the target and stop so the trade can survive one or 2 bars and this part of the code trigger ;
      if( CurrentBar-entry_bar > 1)
      {
      Print("Cancel Order");
      AtmStrategyClose(atmStrategyId);
      }

      you will get printed cancel Order and a PnL = 0

      Example picture :
      Attached Files
      Last edited by pmaglio; 12-07-2016, 04:00 PM.
      pmaglio
      NinjaTrader Ecosystem Vendor - The Indicator Store

      Comment


        #4
        Hello,

        Thank you for the reply.

        I do see a zero being printed, do you have the specific test you had completed in NT7 where this was working as you had expected?

        I used the logic you provided and reverted it to an NT7 script, I see identical outcome when comparing the two scripts which leads me to believe there is still some difference.

        Can you provide the test you had used for NT7 for me to further review differences?

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

        Comment


          #5
          I dont see the point of trying to replicate this on Ninja 7 as this is the usual way we get the PnL from a closed trade...
          ...anyway, here is your example

          The only cancelled trade with a pnl=0 was the 1st one, with entry=exit=51.58
          All other trades are reporting correct PnL, even if they reached target/stop or were cancelled by AtmStrategyClose(atmStrategyId);

          Please let me know how to proceed with the Ninja 7 to Ninja 8 conversion
          Attached Files
          pmaglio
          NinjaTrader Ecosystem Vendor - The Indicator Store

          Comment


            #6
            Thank you for providing the two samples, pmaglio. Reviewing these samples, I noticed they were both nearly functionally identical to built-in samples, with the exception of three functional changes.

            First, these lines of code executing toward the bottom of OnBarUpdate, followed by the rest of the existing code being commented out :

            Code:
            [FONT=Courier New]
                            if( CurrentBar-entry_bar > 1)
                            {
                                Print("Cancel Order");
                                AtmStrategyClose(atmStrategyId);
                            }[/FONT]
            While most of the code this prevents from executing is simply print statements, in both NT7 and NT8, this active code is prevented from being executed :

            Code:
            [FONT=Courier New]
                            // You can change the stop price
                            if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
                                AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);[/FONT]
            Last, the second argument to AtmStrategyCreate for you is OrderType.Market rather than OrderType.Limit .

            None of these modifications appear to affect PnL values directly, but could cause trades to be placed in different ways prior to PnL calculations even taking place should NT8 simulate the trade desk in a different way from NT7 (or other such factors). Therefore, for our test on our end, we will start by instead using the built-in SampleAtmStrategy in both NT7 and NT8, using the visual studio debugger. I would like to invite you to make another copy of your strategy with the above changes reverted and test on your end, so we may rule out factors such as not placing orders to begin with. Ideally, in order to introduce the fewest uninteresting factors, there should be no functional differences between your code and the built-in code. Non-functional differences like print statements, or unit tests outside the code, should be all that remain.

            If any of the above changes are important to our test, please let us know and please let us know why, so that we can give all the information our developers will require in order to repair any potential bugs. We need to completely understand the test code on our end to use it.

            Thank you once more for your report and for helping to improve Ninja. I am happy to have a chance to help you get your NT7 code working in NT8 by discovering and reporting on any code breaking changes.
            Jessica P.NinjaTrader Customer Service

            Comment


              #7
              Dear Jessica,
              I have lot of customer's job pending to be converted to Ninja 8, so cant spend more time with this
              Just let me know when you fix this issue.
              And if it is not an issue just explain how to get the PnL of last trade if it was cancelled via AtmStrategyClose

              Thanks !
              pmaglio
              NinjaTrader Ecosystem Vendor - The Indicator Store

              Comment


                #8
                Hello pmaglio,

                Thank you for your patience.

                I am looking further into why your code is doing this. It seems if we set the string to empty for the atmStrategyId right after calling the realized PnL we get zero. I will investigate further on why this is occurring in NinjaTrader 8.

                Comment


                  #9
                  Hello pmaglio,

                  This has been reported to development. To be clear it is not what I thought in my last post.
                  The real item is that when the ATM strategy is closed by AtmStrategyClose() the Realized PnL is reporting 0.
                  I will follow up here if I have any additional information.

                  Comment


                    #10
                    Hello pmaglio,

                    Thank you for your patience.

                    Development is implementing a resolution for this, planned for the next release.

                    Thank you again for your report.

                    Comment


                      #11
                      Hi NinjaTrader_PatrickH. I am experiencing the same issue of getting the realized PnL as zero for NT7 and you stated that development is implementing a resolution for this. Could you please let me know the current status of this?

                      Comment


                        #12
                        Originally posted by mbesha View Post
                        Hi NinjaTrader_PatrickH. I am experiencing the same issue of getting the realized PnL as zero for NT7 and you stated that development is implementing a resolution for this. Could you please let me know the current status of this?
                        I suspect that fix was for NT8 only.
                        [I presume the intent was to make NT8 replicate NT7 as much as possible, except in
                        those areas explicitly documented otherwise.]

                        You should probably open NT7 topics in the NT7 Strategy forum.

                        Comment


                          #13
                          Hello mbesha,

                          bltdavid is correct. This change was for NinjaTrader 8.
                          Chelsea B.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by GLFX005, Today, 03:23 AM
                          1 response
                          6 views
                          0 likes
                          Last Post NinjaTrader_Erick  
                          Started by nandhumca, Yesterday, 03:41 PM
                          1 response
                          12 views
                          0 likes
                          Last Post NinjaTrader_Gaby  
                          Started by The_Sec, Yesterday, 03:37 PM
                          1 response
                          11 views
                          0 likes
                          Last Post NinjaTrader_Gaby  
                          Started by vecnopus, Today, 06:15 AM
                          0 responses
                          1 view
                          0 likes
                          Last Post vecnopus  
                          Started by Aviram Y, Today, 05:29 AM
                          0 responses
                          5 views
                          0 likes
                          Last Post Aviram Y  
                          Working...
                          X