谢谢!
没用这样的函数,需要自己写,遍历所有持仓,把品种名称当作形参即可。
double TotalProfit(string symbol) { double sum = 0.0; int total = PositionsTotal(); for(int i=0; i<total; i++) { ulong ticket = PositionGetTicket(i); if(ticket>0 && PositionGetString(POSITION_SYMBOL)==symbol) { sum += PositionGetDouble(POSITION_PROFIT) + PositionGetDouble(POSITION_SWAP); } } return sum; }
你要的应该以点数为单位的吧
// 获取实时浮动盈利的点数和获取最大浮动盈利的点数
double FloatingProfit(bool returnMaxProfit = true)
{
double profit = 0.0;
double maxProfit = 0.0;
double pointValue = SymbolInfoDouble(Symbol(), SYMBOL_POINT);
for(int i = 0; i < PositionsTotal(); i++)
{
if (PositionGetSymbol(i) == Symbol() && PositionGetString(POSITION_SYMBOL) == Symbol())
{
double currentProfit = PositionGetDouble(POSITION_PROFIT) / pointValue;
profit += currentProfit;
maxProfit = MathMax(maxProfit, currentProfit);
}
}
return returnMaxProfit ? maxProfit : profit;
}
double ProfitPoint = FloatingProfit(false); // 获取实时浮动盈利的点数
double MaxFloatingPoint = FloatingProfit(true); // 获取最大浮动盈利的点数
你要的应该是这样的
double FloatingProfit(bool returnMaxProfit = true) { if(PositionsTotal() == 0) return 0; static double maxProfitPoints = 0.0; double ProfitPoints = 0.0; double openPrice = PositionGetDouble(POSITION_PRICE_OPEN); long positionType = PositionGetInteger(POSITION_TYPE); ENUM_POSITION_TYPE TypeBuy = POSITION_TYPE_BUY ; ENUM_POSITION_TYPE TypeSell = POSITION_TYPE_SELL ; double price = positionType == TypeBuy ? SymbolInfoDouble(_Symbol, SYMBOL_ASK) : SymbolInfoDouble(_Symbol, SYMBOL_BID) ; if(PositionGetDouble(POSITION_PROFIT) > 0 && PositionGetString(POSITION_SYMBOL) == _Symbol) ProfitPoints = positionType == TypeBuy ? price - openPrice : openPrice - price; if(ProfitPoints > maxProfitPoints) maxProfitPoints = ProfitPoints; return returnMaxProfit ? maxProfitPoints : ProfitPoints; } double ProfitPoint = FloatingProfit(false); // 获取实时浮动盈利的点数 double MaxFloatingPoint = FloatingProfit(true); // 获取最大浮动盈利的点数