Trade Profit Info

Custom MT4 expert advisors published here.

Moderator: admin

Trade Profit Info

Postby Apprentice » Mon Jun 29, 2020 8:25 am

Based on request.
viewtopic.php?f=27&t=70086
Trade Profit Info.mq4
(8.48 KiB) Downloaded 367 times
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Trade Profit Info

Postby BTS0301 » Mon Jun 29, 2020 9:45 pm

Thanks! But am I missing something? There's errors throughout and I think I need a file called Ordersiterator, but where can I find that? I've googled it and everything.
Also I'm only after a few lines of code to incorporate into my own that will show the result I'm after. What is the most needed lines of code for this result? From line 82 to end?
BTS0301
 
Posts: 16
Joined: Fri Jun 26, 2020 9:17 pm

Re: Trade Profit Info

Postby Apprentice » Tue Jun 30, 2020 3:20 am

Your request is added to the development list.
Development reference 1591.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia


Re: Trade Profit Info

Postby BTS0301 » Wed Jul 01, 2020 10:50 pm

Thankyou!
But how can I get it to be 0 until an order is sent? And can it show buy/sell as positive numbers unless the trade has gone in the opposite direction?
Thanks heaps
BTS0301
 
Posts: 16
Joined: Fri Jun 26, 2020 9:17 pm


Re: Trade Profit Info

Postby BTS0301 » Fri Jul 03, 2020 4:56 am

I had rewritten some of the code and it works for the Buy. But I can't get it to work in reverse properly for the Sell. I incorporated some of your new code but still couldn't get the desired result.
For the Sell, I want profit to show as a positive number and include brokerage (7 * lots) eg. .70c for .1 lots
Code: Select all
{
   datetime last = 0;
   double price = 0;
   double lots = 0;
   bool isBuy = true;
   bool isSell = true;
   OrdersIterator it();
   it.WhenSymbol(_Symbol).WhenTrade();
   while (it.Next())
   {
      datetime dt = it.GetOpenTime();
      if (last < dt)
      {
         price = it.GetOpenPrice();
         lots = OrderLots();
         isBuy = it.IsBuy();
         isSell = it.IsSell();
      }
   }
   if (last == 0 && OrderType() == OP_BUY)
   {
      double point = MarketInfo(_Symbol, MODE_POINT);
      int digits = (int)MarketInfo(_Symbol, MODE_DIGITS);
      int mult = digits == 3 || digits == 5 ? 10 : 1;
      double pipSize = point * mult;
      double unitCost = MarketInfo(_Symbol, MODE_TICKVALUE);
      double pips = isBuy ? ((close[0] - price) / pipSize)*10 : ((price - close[0]) / pipSize)*10;
      double profit = ((lots * pips * unitCost))- (7 * lots);
      Comment("Pips: " + DoubleToString(pips,0) + "  $: " + DoubleToString(profit, 2));
   }
   else
   if (last == 0 && OrderType() == OP_SELL)
   {
      double point = MarketInfo(_Symbol, MODE_POINT);
      int digits = (int)MarketInfo(_Symbol, MODE_DIGITS);
      int mult = digits == 3 || digits == 5 ? 10 : 1;
      double pipSize = point * mult;
      double unitCost = MarketInfo(_Symbol, MODE_TICKVALUE);
      double pips = isSell ? ((price - close[0]) / pipSize)*10 : ((close[0] - price) / pipSize)*10;
      double profit = ((lots * pips * unitCost))- (7 * lots);
      Comment("Pips: " + DoubleToString(pips,0) + "  $: " + DoubleToString(profit, 2));
   }
   
   return 0;
}
BTS0301
 
Posts: 16
Joined: Fri Jun 26, 2020 9:17 pm

Re: Trade Profit Info

Postby Apprentice » Fri Jul 03, 2020 5:07 am

Your request is added to the development list.
Development reference 1625.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Trade Profit Info

Postby Apprentice » Mon Jul 06, 2020 1:45 pm

I don't understand what needs to be done. It works fine.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Trade Profit Info

Postby BTS0301 » Tue Jul 07, 2020 1:42 am

Sell order profits are showing as negative numbers. How can this be changed so that it shows positive profit?
BTS0301
 
Posts: 16
Joined: Fri Jun 26, 2020 9:17 pm

Next

Return to MT4 Expert Advisors

Who is online

Users browsing this forum: No registered users and 12 guests