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

    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 NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          63 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          139 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          75 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          50 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X