关闭订单的利润计算 "HELP" - 页 8

Natashe4ka:

Vitalie Postolache:

I.e.

if ((op<0||OrderType()==op) && (t==OrderCloseTime() ||  t==OrderCloseTime()+60)) {LastProfit+=OrderProfit()+OrderCommission()+OrderSwap();}

(t==OrderCloseTime()||t==OrderCloseTime()+60)?

Natashe4ka:

I.e.

if ((op<0||OrderType()==op) && t==OrderCloseTime()+60) {LastProfit+=OrderProfit()+OrderCommission()+OrderSwap();}

+60 ?

PeriodSeconds() 会更正确。还是你只打算在M1上工作？

double lastloss()
{
double lastlos=0.0,op=0.0;
int cnt=0;
datetime time=0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==_Symbol && OrderMagicNumber()==Magic && OrderType()<2)
{
if(cnt==0) time=OrderCloseTime();
op=OrderProfit()+OrderSwap()+OrderCommission();
if(OrderCloseTime()+PeriodSeconds()<time && op>0.0) break;
lastlos+=op;
if(cnt!=0) cnt++;
}
}
}
return(lastlos);
}

Vitalie Postolache:

Natashe4ka:

Vitalie Postolache:

color ProfitColor;

if(lastloss()<0) ProfitColor=Red;
if(lastloss()>0) ProfitColor=LimeGreen;
if(lastloss()==0)ProfitColor=DarkGray;
ObjectCreate("Last Profit", OBJ_LABEL, 0, 0, 0);
ObjectSet("Last Profit", OBJPROP_CORNER, 1);
ObjectSet("Last Profit", OBJPROP_XDISTANCE, 5);
ObjectSet("Last Profit", OBJPROP_YDISTANCE, 15);
ObjectSetText("Last Profit",StringConcatenate("Last Profit: ",DoubleToStr(lastloss(),2)),10,"Arial",ProfitColor);

Natashe4ka:

Vitalie Postolache: