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 CarlTrading, 03-31-2026, 09:41 PM
          1 response
          68 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          38 views
          0 likes
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          63 views
          1 like
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          62 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          53 views
          0 likes
          Last Post CarlTrading  
          Working...
          X