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 TheWhiteDragon, 01-21-2019, 12:44 PM
          4 responses
          541 views
          0 likes
          Last Post PaulMohn  
          Started by GLFX005, Today, 03:23 AM
          0 responses
          3 views
          0 likes
          Last Post GLFX005
          by GLFX005
           
          Started by XXtrader, Yesterday, 11:30 PM
          2 responses
          11 views
          0 likes
          Last Post XXtrader  
          Started by Waxavi, Today, 02:10 AM
          0 responses
          7 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by TradeForge, Today, 02:09 AM
          0 responses
          14 views
          0 likes
          Last Post TradeForge  
          Working...
          X