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

GetUnrealizedProfitLoss results format

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

    GetUnrealizedProfitLoss results format

    I'm attempting to render average position price and Pnl to a custom textbox. And having trouble figuring out how to properly format the output based on a given instrument for pips and points. How can I properly format those results so they match the format used in the chart trader panel? Below my current switch statement:

    switch (lastPanelPnlUnit)
    {
    case PerformanceUnit.Currency:
    tbPositionPnL.Text = position.GetUnrealizedProfitLoss(LastPanelPnlUnit, marketData.LastTradePrice).ToString("C2",Core.Glob als.GeneralOptions.CurrentCulture);
    break;
    case PerformanceUnit.Percent:
    tbPositionPnL.Text = position.GetUnrealizedProfitLoss(LastPanelPnlUnit, marketData.LastTradePrice).ToString("P2", Core.Globals.GeneralOptions.CurrentCulture);
    break;
    case PerformanceUnit.Pips:
    tbPositionPnL.Text = Math.Round(position.GetUnrealizedProfitLoss(Perfor manceUnit.Pips, marketData.LastTradePrice)).ToString(Core.Globals. GeneralOptions.CurrentCulture);
    break;
    case PerformanceUnit.Points:
    tbPositionPnL.Text = Math.Round(position.GetUnrealizedProfitLoss(LastPa nelPnlUnit, marketData.LastTradePrice)).ToString(Core.Globals. GeneralOptions.CurrentCulture);
    break;
    case PerformanceUnit.Ticks:
    tbPositionPnL.Text = Math.Round(position.GetUnrealizedProfitLoss(LastPa nelPnlUnit, marketData.LastTradePrice)).ToString(Core.Globals. GeneralOptions.CurrentCulture);
    break;
    }

    #2
    Hello martyn73,

    You are referring to the PnL display box on the chart?

    I wanted to give this code a test to see what was different.



    I'm seeing the pips and points might not be returning correct values, is this what you are seeing?

    Using the test script are you finding the other performance units are returning correctly?
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Using the test script I see the same as what you show in the video. Pips and points do not return correctly. The other units do.

      Comment


        #4
        And am talking about the Pnl display box on the chart as well as as on the Char Trader panel. I'm re-creating a similar Pnl interface like what's on the Chart Trader panel.

        Comment


          #5
          So is there a workaround for this? Or is this a bug within the GetUnrealizedProfitLoss method that will need to be fixed?

          Comment


            #6
            Hello martyn73,

            The case PerformanceUnit.Pips and PerformanceUnit.Points are rounding to 0.
            Without rounding I am finding the decimal value is matching the pip value once converted. Without rounding the Points are returning correct as well.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              But I need some sort of rounding because the output string for point could be very long. I would need to know to how many digits behind the decimal I round based on a given instrument. Would I do that using TickSize? For pip, it does not return with the pip's format. Is there a call that I can make so it returns in the proper format: x'x ?

              Comment


                #8
                Hello martyn73,

                NinjaTrader is giving you the values correctly.

                It is your choice to round these to 0..

                Yes, the TickSize could tell you how many digits an instrument has with some custom logic.
                Below is a link to a google search for finding the number of digits after a decimal in C#.


                The performance is only going to be returned as a number not as a string. For pip notation you would need to convert the value to a string.
                Below is a link to the cme group that has helpful tips on this.


                I'm also copying some text from an internal conversation I found between other techs.

                To convert fractional rpresentation to the decimal representation Ninja uses, given the price 149'16, or 149 and 16/32
                • The whole number part (149) remains the same in decimal representation
                • A calculator will convert 16 / 32 to 0.5
                This gives us 149.50

                To convert decimal notation to fractional notation, given the price 149.50 :
                • The whole number part (149) remains the same
                • Simply multiply the fractional part (0.50 is equal to 50 / 100) by 32, to get 16
                This gives us 149'16
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Ok, understood. Thanks for the references and feedback.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by PaulMohn, Today, 05:00 AM
                  0 responses
                  8 views
                  0 likes
                  Last Post PaulMohn  
                  Started by ZenCortexAuCost, Today, 04:24 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post ZenCortexAuCost  
                  Started by ZenCortexAuCost, Today, 04:22 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post ZenCortexAuCost  
                  Started by SantoshXX, Today, 03:09 AM
                  0 responses
                  16 views
                  0 likes
                  Last Post SantoshXX  
                  Started by DanielTynera, Today, 01:14 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post DanielTynera  
                  Working...
                  X