{
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);
}
}
It's a solution but it's is not the best solution as you will learn if you proceed.
But it can help you at this point in time.
It's a solution but it's is not the best solution as you will learn if you proceed.
But it can help you at this point in time.
yes it solved the problem in the topic, but when it closes it also creates a new order, if it's still above the cloud. Could you help me to solve this new problem?
How block all new orders after sucessfully closing the first?
Well you can create a flag.
Then you can set the value to one when the order is placed.
{
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;
}
}
But it will give you the warning that you need to check the return value of the ordersend function so
{
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;
}
}
}
}
Why not set the flag depending on if the order was successfully placed or not ?
In that case if your order fails it will continue to try.
yes it solved the problem in the topic, but when it closes it also creates a new order, if it's still above the cloud. Could you help me to solve this new problem?
How block all new orders after sucessfully closing the first?
As Marco has already alluded to, you will probably run into other problems.
What if there is an open order on another symbol?
What if there are orders being controlled by another EA?
What if there are pending orders?
What if the trigger is still active when you close the first one?
In response to the latter, you could use a flag as Marco has suggested. Just remember you need to decide when to reset the flag or the EA never takes another trade again.
Alternatively, you could check for a cross / change of state from below/in the cloud to above the cloud.
i put your code and says ticket is undleclared, so i declared it, but now the code opens multiple orders, just like before, how to proceed now?
{
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;
}
}
}
}
i put your code and says ticket is undleclared, so i declared it, but now the code opens multiple orders, just like before, how to proceed now?
{
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;
}
}
}
}
It would probably help you to read about the scope of variables.
What happens to the value of order each tick?
Okay so you declare the ticket with the boolean flag.
int ticket;
And then
{
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;
}
}
}
}
You can not declare them in OnTick() because their value will be reset on every tick of course.
Also note that the OrderSend either returns the ticket number , or -1 minus one if it fails.
I put
bool order and
int ticket
on global variables, and the rest of the code on OnTick, but still doesn't make any entry now
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm new in mql4 and this code opens multiple orders, how can i avoid it? it should just open 1 order until it closes,
how can i do this?
Thanks
{
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);
}