Professional Documents
Culture Documents
Time and Profit mql5
Time and Profit mql5
mqh>
CTrade trade;
int OnInit() {
return INIT_SUCCEEDED;
}
void OnTick() {
MqlDateTime structTime;
TimeCurrent(structTime);
structTime.hour = CloseTimeHour;
structTime.min = CloseTimeMin;
structTime.sec = CloseTimeSec;
datetime timeClose = StructToTime(structTime);
if (isCloseTime || isProfit) {
for (int i = PositionsTotal() - 1; i >= 0; i--) {
ulong posTicket = PositionGetTicket(i);
if (PositionSelectByTicket(posTicket)) {
if (trade.PositionClose(posTicket)) {
if (isCloseTime)
Print(__FUNCTION__, " > Pos #", posTicket, " was closed
because of close time...");
else if (isProfit)
Print(__FUNCTION__, " > Pos #", posTicket, " was closed
because of profit...");
Comment("Server Time: ", TimeCurrent(),
"\nClose Time: ", TimeToString(timeClose, TIME_DATE |
TIME_MINUTES),
"\nProfit: ", DoubleToString(profit, 2), " (Target: ",
DoubleToString(TargetProfit, 2), ")");
}
}
}
}
}