• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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:

    http://screencast.com/t/wDP3wmF89Ni

    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, 03: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:
            
                            if( CurrentBar-entry_bar > 1)
                            {
                                Print("Cancel Order");
                                AtmStrategyClose(atmStrategyId);
                            }
            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:
            
                            // You can change the stop price
                            if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
                                AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);
            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.
                Patrick H.NinjaTrader Customer Service

                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.
                  Patrick H.NinjaTrader Customer Service

                  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.
                    Patrick H.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NT-Roland, Today, 06:34 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post NT-Roland  
                    Started by gemini42, Yesterday, 09:44 PM
                    0 responses
                    11 views
                    0 likes
                    Last Post gemini42  
                    Started by martyn73, Yesterday, 03:09 PM
                    0 responses
                    10 views
                    0 likes
                    Last Post martyn73  
                    Started by martyn73, Yesterday, 03:05 PM
                    0 responses
                    11 views
                    0 likes
                    Last Post martyn73  
                    Started by mic414, Yesterday, 02:17 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post mic414
                    by mic414
                     
                    Working...
                    X