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 fx.practic, 10-15-2013, 12:53 AM
          5 responses
          5,403 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by Shai Samuel, 07-02-2022, 02:46 PM
          4 responses
          95 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by DJ888, Yesterday, 10:57 PM
          0 responses
          7 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by MacDad, 02-25-2024, 11:48 PM
          7 responses
          159 views
          0 likes
          Last Post loganjarosz123  
          Started by Belfortbucks, Yesterday, 09:29 PM
          0 responses
          8 views
          0 likes
          Last Post Belfortbucks  
          Working...
          X