如何在MQL4 Metatrader 4中打开多个OrderSend()?

时间:2016-09-07 17:54:13

标签: mql4 metatrader4

我正在尝试使用ExpertAdvisor或Script同时在MQL4中打开多个交易。然而,当我将EA拖动到图表时,它只打开一个订单,而不是第二个订单(或第三个,第四个等)

extern double lots = 0.01;
extern int takeprofit = 40;
extern int stoploss = 40;

void OnStart(){

double profitlvl_buy;
double losslvl_buy;

profitlvl_buy = Ask+takeprofit*Point;
losslvl_buy = Ask-stoploss*Point;

int ticket1;
int ticket2;

ticket1 = OrderSend("EURUSD", OP_BUY, lots, MarketInfo("EURUSD", MODE_ASK), 10, losslvl_buy, profitlvl_buy, NULL);
ticket2 = OrderSend("GBPUSD", OP_BUY, lots, MarketInfo("GBPUSD", MODE_ASK), 10, losslvl_buy, profitlvl_buy, NULL);

}

如何让它执行多个OrderSend()来电?

1 个答案:

答案 0 :(得分:2)

确定。在图表上部署EA /脚本时,它会使用有关图表的信息(符号,时间范围等 - 在编辑器中它们是粉红色的)

因此,当您部署EA时,假设EURUSD,图表,它就行了:

profitlvl_buy = Ask+takeprofit*Point;

并认为“ Ask ”绝对是Ask的{​​{1}}(或换句话说,EURUSD图表的Ask价格{{ 1}}) 然后 您要求 _Symbol 发送交易, GBPUSD takeprofit 计算为{{1}所以我认为stoploss是不正确的。即EURUSD为1.12,takeprofit为1000个刻度,因此tp = 1.13,GBP的价格为1.33,Ask不能(对于市场订单)低于交易条目。

为了解决问题:

takeprofit

通常一般来说,确保故障单返回 takeprofit (如果成功)或double ask = MarketInfo( "EURUSD", MODE_ASK ); int ticket1 = OrderSend( "EURUSD", OP_BUY, lots, ask, 10, ask-stoploss*Point, ask+takeprofit*Point, NULL ); ask = MarketInfo( "GBPUSD", MODE_ASK ); int ticket2 = OrderSend( "GBPUSD", OP_BUY, lots, ask, 10, ask-stoploss*Point, ask+takeprofit*Point, NULL ); 并且在这种情况下打印错误代码,这种情况 - 错误#130