我正在尝试使用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()
来电?
答案 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