void OnTick()
{
if(OrdersTotal()==0)
{
double up= iIchimoku (NULL, 5,9,26,52,3,0);
double down= iIchimoku (NULL,5,9,26,52,4,0);
if (MathMin (up,down) < Bid )
OrderSend (NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point);
}
}
{
if(OrdersTotal()==0)
{
double up= iIchimoku (NULL, 5,9,26,52,3,0);
double down= iIchimoku (NULL,5,9,26,52,4,0);
if (MathMin (up,down) < Bid )
OrderSend (NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point);
}
}
非常感谢您,先生,您很严格地指出了问题,没有让我绕圈子。
这是一个解决方案,但它不是最好的解决方案,如果你继续下去,你会知道。
但在这个时候,它可以帮助你。
Marco vd Heijden:
这是一个解决方案,但它不是最好的解决方案,如果你继续下去,你会知道。
但在这个时候,它可以帮助你。
是的,它解决了主题中的问题,但当它关闭时,也会创建一个新的订单,如果它仍然在云之上。你能帮助我解决这个新问题吗?
如何在成功关闭第一个订单后阻止所有新订单?
好吧,你可以创建一个标志。
bool order=0;
然后你可以在下订单时将其值设置为1。
void OnTick()
{
if(order==0)
{
double up= iIchimoku (NULL, 5,9,26,52,3,0);
double down= iIchimoku (NULL,5,9,26,52,4,0);
if (MathMin (up,down) < Bid )
OrderSend (NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point);
order=1;
}
}
{
if(order==0)
{
double up= iIchimoku (NULL, 5,9,26,52,3,0);
double down= iIchimoku (NULL,5,9,26,52,4,0);
if (MathMin (up,down) < Bid )
OrderSend (NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point);
order=1;
}
}
但它会给你一个警告,你需要检查ordersend函数 的返回值,所以
void OnTick()
{
if(order==0)
{
double up= iIchimoku (NULL, 5,9,26,52,3,0);
double down= iIchimoku (NULL,5,9,26,52,4,0);
if (MathMin (up,down) < Bid )
int ticket=OrderSend (NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point);
{
if(ticket!=-1)
{
order=1;
}
}
}
}
{
if(order==0)
{
double up= iIchimoku (NULL, 5,9,26,52,3,0);
double down= iIchimoku (NULL,5,9,26,52,4,0);
if (MathMin (up,down) < Bid )
int ticket=OrderSend (NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point);
{
if(ticket!=-1)
{
order=1;
}
}
}
}
为什么不根据订单是否成功下达来设置这个标志呢?
在这种情况下,如果你的订单失败,它将继续尝试。
我输入了你的代码,并说票据未被宣布,所以我宣布了它,但现在代码打开了多个订单,就像以前一样,现在该如何进行?
void OnTick()
{
bool order= 0;
int ticket;
if(order==0)
{
double up= iIchimoku (NULL, 5,9,26,52,3,0);
double down= iIchimoku (NULL,5,9,26,52,4,0);
if (MathMax (up,down) < Bid )
int ticket= OrderSend (NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point);
{
if( ticket!=1)
{
order=1;
}
}
}
}
{
bool order= 0;
int ticket;
if(order==0)
{
double up= iIchimoku (NULL, 5,9,26,52,3,0);
double down= iIchimoku (NULL,5,9,26,52,4,0);
if (MathMax (up,down) < Bid )
int ticket= OrderSend (NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point);
{
if( ticket!=1)
{
order=1;
}
}
}
}
mrluck1:
我输入了你的代码,并说票据未被宣布,所以我宣布了它,但现在代码打开了多个订单,就像以前一样,现在该如何进行?
void OnTick()
{
bool order= 0;
int ticket;
if(order==0)
{
double up= iIchimoku (NULL, 5,9,26,52,3,0);
double down= iIchimoku (NULL,5,9,26,52,4,0);
if (MathMax (up,down) < Bid )
int ticket= OrderSend (NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point);
{
if( ticket!=1)
{
order=1;
}
}
}
}
{
bool order= 0;
int ticket;
if(order==0)
{
double up= iIchimoku (NULL, 5,9,26,52,3,0);
double down= iIchimoku (NULL,5,9,26,52,4,0);
if (MathMax (up,down) < Bid )
int ticket= OrderSend (NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point);
{
if( ticket!=1)
{
order=1;
}
}
}
}
读一下变量的范围 可能会对你有帮助。
每次打钩时,订单 的值会发生什么变化?
好的,所以你用布尔标志来声明票据。
bool order=0;
int ticket;
int ticket;
然后
void OnTick()
{
if(order==0)
{
double up= iIchimoku (NULL, 5,9,26,52,3,0);
double down= iIchimoku (NULL,5,9,26,52,4,0);
if (MathMax (up,down) < Bid )
ticket= OrderSend (NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point);
{
if( ticket>0)
{
order=1;
}
}
}
}
{
if(order==0)
{
double up= iIchimoku (NULL, 5,9,26,52,3,0);
double down= iIchimoku (NULL,5,9,26,52,4,0);
if (MathMax (up,down) < Bid )
ticket= OrderSend (NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point);
{
if( ticket>0)
{
order=1;
}
}
}
}
你不能在OnTick()中声明它们,因为它们的值当然会在每个tick 中被重置。
还要注意的是,OrderSend要么返回票据号码,要么在失败时返回-1减1的结果。
我把
bool order和
int ticket
在全局变量上,其余的代码在OnTick上,但现在仍然没有任何输入。
I'm new in mql4 and this code opens multiple orders, how can I avoid it? It should just open 1 order until it closed,
我怎样才能做到这一点?
谢谢
{
double up= iIchimoku (NULL, 5,9,26,52,3,0);
double down= iIchimoku (NULL,5,9,26,52,4,0);
if (MathMin (up,down) < Bid )
OrderSend (NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point);
}