MQL4 - automated forex trading   /  

Forum

EA to place two orders simultaneously

Back to topics list To post a new topic, please log in or register

avatar
9
jasius 2008.04.16 06:07 

I want my EA to place both EURUSD and USDCHF buy orders simultaneously, then close when it's in profit (in any way) by 10 pips and then immediately place two new buy orders and so on. However, it wouldn't do anything when I place EA on a EURUSD chart. Could anybody provide some insight?



extern double TakeProfit = 10;
extern double Lots = 0.1;
double Points;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init ()
{
Points = MarketInfo (Symbol(), MODE_POINT);
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int cnt=0, total;
if(Bars<100)
{
Print("bars less than 100");
return(0);
}
if(OrdersTotal()<1)
{
if(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money");
return(0);

OrderSend("EURUSD",OP_BUY,Lots,Ask,3,0,"Hedge",16384,0,Red);
if(GetLastError()==0)Print("Order opened : ",OrderOpenPrice());
return(0);

OrderSend("USDCHF",OP_BUY,Lots,Ask,3,0,"Hedge",16384,0,Red);
if(GetLastError()==0)Print("Order opened : ",OrderOpenPrice());
return(0);
}
return(0);
}
total=OrdersTotal();
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_BUY &&
OrderSymbol()=="EURUSD" && OrderSymbol()=="USDCHF")
{

if(((iClose("EURUSD",PERIOD_M1,0))-(iClose("USDCHF",PERIOD_M1,0))>TakeProfit*Point) ||
((iClose("USDCHF",PERIOD_M1,0))-(iClose("EURUSD",PERIOD_M1,0))>TakeProfit*Point) ||
((iClose("USDCHF",PERIOD_M1,0))+(iClose("EURUSD",PERIOD_M1,0))>TakeProfit*Point))
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);
return(0);
}
}
}
return(0);
}

article

Secrets of MetaTrader 4 Client Terminal

21 way to ease the life: Latent features in MetaTrader 4 Client Terminal. Full screen; hot keys; Fast Navigation bar; minimizing windows; favorites; traffic reduction; disabling of news; symbol sets; Market Watch; templates for testing and independent charts; profiles; crosshair; electronic ruler; barwise chart paging; account history in the chart; types of pending orders; modifying of StopLoss and TakeProfit; undo deletion; chart print.


avatar
582
irusoh1 2008.04.16 07:38 

It is a better idea to indent your brackets then you can see what's wrong.


if(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money");
return(0);

OrderSend("EURUSD",OP_BUY,Lots,Ask,3,0,"Hedge",16384,0,Red);
if(GetLastError()==0)Print("Order opened : ",OrderOpenPrice());
return(0);

OrderSend("USDCHF",OP_BUY,Lots,Ask,3,0,"Hedge",16384,0,Red);
if(GetLastError()==0)Print("Order opened : ",OrderOpenPrice());
return(0);
}

trying to send order when there is no money.


avatar
9
jasius 2008.04.17 03:51 
irusoh1 wrote:

It is a better idea to indent your brackets then you can see what's wrong.


if(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money");
return(0);

OrderSend("EURUSD",OP_BUY,Lots,Ask,3,0,"Hedge",16384,0,Red);
if(GetLastError()==0)Print("Order opened : ",OrderOpenPrice());
return(0);

OrderSend("USDCHF",OP_BUY,Lots,Ask,3,0,"Hedge",16384,0,Red);
if(GetLastError()==0)Print("Order opened : ",OrderOpenPrice());
return(0);
}

trying to send order when there is no money.

Unfortunately, nothing is happening, after activation EA just sits there and laughs at me with the smiley face but does not open any trades

Back to topics list  

To add comments, please log in or register