Download MetaTrader 5

Trying to calculate total profit for trades - page 2

To add comments, please log in or register
Find out how to install MetaTrader on Mac OS
Subgenius
582
Subgenius 2014.11.30 23:06  

okay you want to see all buy/sell profit of open orders?

set terminal to 'All History'

call function

OrdersTotalInfo()

reference global variables

SellsOpenProfit, BuysOpenProfit
Subgenius
582
Subgenius 2014.11.30 23:11  
the main reason i say it should help with profit & loss would because you can check each order open and close price, lot value as well as commission and swap and add up the totals for all buys and sells
Subgenius
582
Subgenius 2014.11.30 23:16  
jtubbs13791:
Thanks for the the help. it works, but it only pulls the info from the last open trade. Is there away to get all the open trades? Plus I am confused on how to get the closed profit amount. I know you change MODE_TRADES to MODE_HISTORY, but I am not getting any info. As you can tell I am fairly new to the coding scene.

heres what i do to find my pips for the day

string _symbol=Symbol();
int newMagic=1234;
int _buyspips=0, _sellspips=0;
for(int GFTDPips=OrdersTotal()-1; GFTDPips>=0; GFTDPips--)
   {
   OrderSelect(GFTDPips,SELECT_BY_POS,MODE_TRADES);
      {
      if(TimeDayOfYear(OrderOpenTime())==TimeDayOfYear(TimeCurrent()) &&
         OrderSymbol()==_symbol && OrderMagicNumber()==newMagic && OrderComment()==_comment)
         {
         if(OrderType()==OP_BUY){_buyspips+=OrderClosePrice()-OrderOpenPrice();}
         if(OrderType()==OP_SELL){_sellspips+=OrderOpenPrice()-OrderClosePrice();}
         }
      }
   }
for(GFTDPips=OrdersHistoryTotal()-1; GFTDPips>=0; GFTDPips--)
   {
   OrderSelect(GFTDPips,SELECT_BY_POS,MODE_HISTORY);
      {
      if(TimeDayOfYear(OrderOpenTime())==TimeDayOfYear(TimeCurrent()) &&
         OrderSymbol()==_symbol && OrderMagicNumber()==newMagic && OrderComment()==_comment)
         {
         if(OrderType()==OP_BUY){_buyspips+=OrderClosePrice()-OrderOpenPrice();}
         if(OrderType()==OP_SELL){_sellspips+=OrderOpenPrice()-OrderClosePrice();}
         }
      }
   }
whroeder1
14470
whroeder1 2014.11.30 23:17  
GumRai: Use iPos--
  1. For POD types, ++x and x++ are equivalent.
  2. For classes ++x is operator++(){ whatEver; return GetPointer(this) ; }
  3. For classes x++ is operator++(int){ CLASS tmp(this); ++this ; return tmp;} which is more than twice as expensive.
  4. Prefer ++x over x++
12
To add comments, please log in or register