OrderProfit
//+------------------------------------------------------------------+
//| Вычисляет стоимость сделки в валюте депозита |
//| Параметры: |
//| ClosePrice текущая цена для расчета (current price to calculate) |
//| CurrentDT опорная дата/время для расчета кросс-курса |
//| (reference date / time to calculate the cross-rate) |
//+------------------------------------------------------------------+
double CalcOrderProfit(double ClosePrice, datetime CurrentDT)
{
string sy = v.OrderSymbol();
double lots = v.OrderLots();
int op = v.OrderType();
double LS = MarketInfo(sy, MODE_LOTSIZE);
double OrdProf = lots * LS * (ClosePrice - v.OrderOpenPrice()) * IIF(op==OP_BUY,1,-1);
string FirstPart = StringSubstr(sy, 0, 3);
string SecondPart = StringSubstr(sy, 3, 3);
string DepoCurr = AccountCurrency();
if( SecondPart == DepoCurr )
{ /**/ }
else if( FirstPart == DepoCurr )
{OrdProf /= ClosePrice;}
else
{
if(MarketInfo( DepoCurr + SecondPart, MODE_BID ) > 0)
sy = DepoCurr + SecondPart;
else
sy = SecondPart + DepoCurr;
int sh = iBarShift(sy, 0, CurrentDT, true);
if(sh < 0)
{
Print("Error! No history for "+sy);
return(-1);
} else {
ClosePrice=iClose(sy, 0, sh);
}
FirstPart = StringSubstr(sy, 0, 3);
SecondPart = StringSubstr(sy, 3, 3);
if( SecondPart == DepoCurr )
OrdProf *= ClosePrice;
else if( FirstPart == DepoCurr )
OrdProf /= ClosePrice;
}
OrdProf = NormalizeDouble(OrdProf, 2) ;
return(OrdProf);
}