Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Rounding Last PnL and Last Profit

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

    Rounding Last PnL and Last Profit

    I hope someone can help with this one. I've searched the forum and found several posts, but none that answered my problem.

    I'm using Last PnL and Last Profit in an auto strategy. The code lines are
    lastProfit = (lastTrade.ProfitCurrency * contracts) ; and

    lastpnl = (Performance.AllTrades.TradesPerformance.Currency. CumProfit - priorTradesCumProfit);

    The output window returns:
    The Last PnL is -84.6999999999983
    The Last Profit is -84.6999999999983

    I changed the code lines to read:
    lastProfit = Math.Round(lastTrade.ProfitCurrency * contracts) ; and

    lastpnl = Math.Round(Performance.AllTrades.TradesPerformance .Currency.CumProfit - priorTradesCumProfit);

    This successfully rounded to the nearest whole number, but I need it rounded to 2 decimals.

    I tried to use the "pop up" menu example of
    decimal Math.Round(decimal d, int decimals, midpointrounding mode)
    but I get a best overload error and cannot convert from double to system midpointrounding error. It wants a current bar [0] of some sort and seems to be applicable to indicators.

    Can someone tell me how to make the Math.Round round the Last PnL and Last Profit to 2 decimal places?
    Thanks!
    Joe

    #2
    trade1953, I believe Math.Truncate would do the job for you - http://msdn.microsoft.com/en-us/libr....truncate.aspx
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Try
      lastProfit = Math.Round(lastTrade.ProfitCurrency * contracts * 100) /100;

      Comment


        #4
        Baruch,
        Thank You, Thank You , Thank You!!!! You're a genius. Truncate didn't work for me (still rounded to whole number) and I didn't know what to do next. If I can EVER return the favor somehow, just ask. Yahoo!!
        Joe

        Comment


          #5
          Joe,
          Your welcome. Glad I could help, but really it's nothing.
          Baruch

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Stanfillirenfro, Today, 07:23 AM
          1 response
          2 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by cmtjoancolmenero, Yesterday, 03:58 PM
          2 responses
          19 views
          0 likes
          Last Post cmtjoancolmenero  
          Started by olisav57, Yesterday, 07:39 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by cocoescala, 10-12-2018, 11:02 PM
          7 responses
          943 views
          0 likes
          Last Post Jquiroz1975  
          Started by oviejo, Today, 12:28 AM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X