检查 Metatrader 4 交易历史中的 OrdersHistoryTotal 数量是否改变
Check if number of OrdersHistoryTotal in Metatrader 4 trade history changed
我想在交易结束后立即触发一个函数(= OrdersHistoryTotal
至少增加了 1)。
MQL4 中是否有针对此类情况的任何处理程序?
在我的特定设置中,我有以下函数 pushSocket
,它应该只在 OrdersHistoryTotal
改变的情况下推送数据。
int i,hstTotal=OrdersHistoryTotal();
string historical_trades = "";
for(i=0;i<hstTotal;i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) continue;
historical_trades = historical_trades +
"historical_trades|" +
version + "|" +
DID + "|" +
AccountNumber() + "|" +
IntegerToString(OrderTicket()) + "," +
TimeToString(OrderOpenTime(), TIME_DATE|TIME_SECONDS) + "," +
TimeToString(OrderCloseTime(), TIME_DATE|TIME_SECONDS) + "," +
IntegerToString(OrderType()) + "," +
DoubleToString(OrderLots(),2) + "," +
OrderSymbol() + "," +
DoubleToString(OrderOpenPrice(),5) + "," +
DoubleToString(OrderClosePrice(),5) + "," +
DoubleToString(OrderStopLoss(),5) + "," +
DoubleToString(OrderTakeProfit(),5) + "," +
DoubleToString(OrderCommission(),2) + "," +
DoubleToString(OrderSwap(),2) + "," +
DoubleToString(OrderProfit(),2) + "," +
"<" + OrderComment() + ">|";
}
pushSocket.send(StringFormat("%s", historical_trades, true));
我试图插入一个计数器来比较它,但每次内存清理时计数器都会被删除。以上函数嵌套在每秒执行一次的 onTick 函数中。
MQL5 中有一个函数 OnTradeAction()
,每次完成某些交易操作时都会调用该函数。但不幸的是,此功能在 MQL4 中不可用。另一方面,您可以在 OnTick()
内实现一个函数,该函数将检查 HistoryTraderTotal()
与之前保存的值相比是否有所增加,并在这种情况下执行您喜欢的所有步骤。多一点工作,但几乎相同。
OnTimer(){
Mt4OnTradeAction();
otherLogic();
}
Mt4OnTradeAction(){
static int historyTradesTotal=0;
if(HistoryTradesTotal()==historyTradesTotal) return;
historyTradesTotal = HistoryTradesTotal();
processingTrade();
}
我想在交易结束后立即触发一个函数(= OrdersHistoryTotal
至少增加了 1)。
MQL4 中是否有针对此类情况的任何处理程序?
在我的特定设置中,我有以下函数 pushSocket
,它应该只在 OrdersHistoryTotal
改变的情况下推送数据。
int i,hstTotal=OrdersHistoryTotal();
string historical_trades = "";
for(i=0;i<hstTotal;i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) continue;
historical_trades = historical_trades +
"historical_trades|" +
version + "|" +
DID + "|" +
AccountNumber() + "|" +
IntegerToString(OrderTicket()) + "," +
TimeToString(OrderOpenTime(), TIME_DATE|TIME_SECONDS) + "," +
TimeToString(OrderCloseTime(), TIME_DATE|TIME_SECONDS) + "," +
IntegerToString(OrderType()) + "," +
DoubleToString(OrderLots(),2) + "," +
OrderSymbol() + "," +
DoubleToString(OrderOpenPrice(),5) + "," +
DoubleToString(OrderClosePrice(),5) + "," +
DoubleToString(OrderStopLoss(),5) + "," +
DoubleToString(OrderTakeProfit(),5) + "," +
DoubleToString(OrderCommission(),2) + "," +
DoubleToString(OrderSwap(),2) + "," +
DoubleToString(OrderProfit(),2) + "," +
"<" + OrderComment() + ">|";
}
pushSocket.send(StringFormat("%s", historical_trades, true));
我试图插入一个计数器来比较它,但每次内存清理时计数器都会被删除。以上函数嵌套在每秒执行一次的 onTick 函数中。
MQL5 中有一个函数 OnTradeAction()
,每次完成某些交易操作时都会调用该函数。但不幸的是,此功能在 MQL4 中不可用。另一方面,您可以在 OnTick()
内实现一个函数,该函数将检查 HistoryTraderTotal()
与之前保存的值相比是否有所增加,并在这种情况下执行您喜欢的所有步骤。多一点工作,但几乎相同。
OnTimer(){
Mt4OnTradeAction();
otherLogic();
}
Mt4OnTradeAction(){
static int historyTradesTotal=0;
if(HistoryTradesTotal()==historyTradesTotal) return;
historyTradesTotal = HistoryTradesTotal();
processingTrade();
}