Download MetaTrader 5
To add comments, please log in or register
Having difficulties in understanding the Trading Signals service? Read the article!
reza rahmad
2746
reza rahmad 2014.03.25 11:48 
help me please i want to calculate all profit in order and if all position
totalprofit all posotion >= 10 close;
bool   result;
   double price,OrderProfitCash,OrderProfitPoint,RealProfit;
   int    cmd,error;
   int    TradeTick;
   double TimeOut;

   for(TradeTick=OrdersTotal()-1; TradeTick > 0; TradeTick--)
      { TimeOut=0;
        while(!IsTradeAllowed()) {if(TimeOut > 50) break;TimeOut++;}
        if(OrderSelect(TradeTick,SELECT_BY_POS,MODE_TRADES))
           {
           cmd=OrderType();
           //---- first order is buy or sell
           if(cmd==OP_BUY || cmd==OP_SELL)
              {
              while(true)
                 {// Cal the Profit Point
                 RefreshRates();
                 if(cmd==OP_BUY) { price =Bid; OrderProfitPoint =(price-OrderOpenPrice())/Point; }
                 else            { price =Ask; OrderProfitPoint =(OrderOpenPrice()-price)/Point; }
                 
                 OrderProfitCash = OrderProfit()+OrderCommission()+OrderSwap();
                 if(OrderProfitCash <= 0) continue;
                 //if((TakeProfitPoint > OrderProfitPoint) || !OrderProfitCash) break;
                 result=OrderClose(OrderTicket(),OrderLots(),price,GetSlippage(),CLR_NONE);
                 if(result!=TRUE) { error=GetLastError(); Print("LastError = ",error); }
                 else { error=0; Print("OrderProfit = ", OrderProfit());RealProfit+=OrderProfit();}
                 
                 if(error==129 || error==135) RefreshRates();
                 else break;
                 }
              }
           }
           else Print( "Error when order select ", GetLastError());
      }
   Print("Close Profit Order Call, Profit Take =",RealProfit);
   return(0);
   
  }

so hows the coding iam stuck??
qjol
3243
qjol 2014.03.25 12:04  
if you are talking about the whole positions in the account

you can simply use AccountProfit
reza rahmad
2746
reza rahmad 2014.03.25 23:24  
qjol:
if you are talking about the whole positions in the account

you can simply use AccountProfit

from every order sireee

/
To add comments, please log in or register