Oops..
Error in the lots when closing..
Sorry ;)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi,
I'm learning mql4, and doing some eas to practice. For my fifth ea, I got a problem that I don't undertand.
I want the ea send orders only 1 time hour (Minute()==0). It works, but when any order is closed, automatically the ea send an order.
Also, if you see some big errors (i'm a newbie), please tell me.
Thanx for your help.
Here is the code :
int start()
{
//----
int ticket, total, tickTo;
double magic, opened, opened2, last, benef, askLot, bidLot;
if(Bars<100)
{
Print("bars less than 100");
return(0);
}
magic = 010101;
total = OrdersTotal();
opened = total;
last = OrdersHistoryTotal();
askLot = MathCeil(Coef*(Close[1]-Open[1]))/100;
bidLot = MathCeil(Coef*(Open[1]-Close[1]))/100;
tickTo = last+total;
OrderSelect(tickTo,SELECT_BY_TICKET,MODE_TRADES);
if(Close[1]>Open[1] && Minute()==0)
{
if(Open[0]<(OrderOpenPrice()-0.0005) || Open[0]>(OrderOpenPrice()+0.0005))
{
ticket=OrderSend(Symbol(),OP_BUY,askLot,Ask,3,0,0,"Akilitoka",magic,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
}
if(Close[1]<Open[1] && Minute()==0)
{
if(Open[0]<(OrderOpenPrice()-0.0005) || Open[0]>(OrderOpenPrice()+0.0005))
{
ticket=OrderSend(Symbol(),OP_SELL,bidLot,Bid,3,0,0,"Akilitoka",magic,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
}
while(opened>0)
{
tickTo = last+opened;
OrderSelect(tickTo,SELECT_BY_TICKET,MODE_TRADES);
benef = benef+OrderProfit();
opened--;
}
if(benef>TakeProfit || total>245)
{
opened2 = total;
while(opened2>0)
{
tickTo = last+opened2;
OrderSelect(tickTo,SELECT_BY_TICKET,MODE_TRADES);
if(OrderType() == OP_BUY)
{
OrderClose(OrderTicket(),Lots,Bid,3,White);
opened2--;
}
else
{
OrderClose(OrderTicket(),Lots,Ask,3,White);
opened2--;
}
}
return(0);
}
return(0);
}