Hi guys,
I need your coding help. I have different open positions from different EAs with unique magic numbers.
Now I want to let check every EA if the EA wants to open a new position to check if there is already an open position with a given magic number.
How can help?
Bset regards,
for(int nCnt = OrdersTotal() - 1; nCnt >= 0; nCnt--) { OrderSelect(nCnt, SELECT_BY_POS, MODE_TRADES); if(OrderMagicNumber() == myMagicNumber && OrderCloseTime()==0) { //Do your stuff here } }
int count=0; for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() ){ // and my pair. count++; } if (!count){ // I have no open orders on this chart
If you're selecting open orders (non-history,) OrderCloseTime() will ALWAYS be zero. Always check return codes (orderSelect).
On which position I have to fill in the code?
Best regards
On which position I have to fill in the code?
Best regards
Here is my code:
//+------------------------------------------------------------------+
//| OpenHedge EA.mq4 |
//| Copyright © 2010, MetaQuotes Software Corp. |
//| MetaTrader 4 Trading Platform / MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
extern int Slippage=5;
extern int MagicNumber_1=1000;
extern int MagicNumber_2=2000;
double dXPoint=1;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
if(Digits==3 || Digits==5)
{
dXPoint=10;
}
if(Digits==3 || Digits==5)
{
dXPoint=10;
int SLIPPAGE=SLIPPAGE*dXPoint;
}
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
if(iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,0)<iMA(N ULL,0,20,8,MODE_SMMA,PRICE_MEDIAN,0))
{
OrderSend("EURUSD",OP_BUY,1,MarketInfo("EURUSD",MO DE_ASK),2,NULL,NULL,"Magic Number 1000",MagicNumber_1,0,CLR_NONE);
Sleep(1000);
OrderSend("USDCHF",OP_BUY,1,MarketInfo("USDCHF",MO DE_ASK),2,NULL,NULL,"Magic Number 1000",MagicNumber_1,0,CLR_NONE);
Sleep(1000);
OrderSend("EURUSD",OP_SELL,1,MarketInfo("EURUSD",M ODE_BID),2,NULL,NULL,"Magic Number 2000",MagicNumber_2,0,CLR_NONE);
Sleep(1000);
OrderSend("USDCHF",OP_SELL,1,MarketInfo("USDCHF",M ODE_BID),2,NULL,NULL,"Magic Number 2000",MagicNumber_2,0,CLR_NONE);
Sleep(1000);
//RefreshRates();
}
//------------- 2
if(iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,0)>iMA(N ULL,0,20,8,MODE_SMMA,PRICE_MEDIAN,0))
{
OrderSend("EURUSD",OP_SELL,1,MarketInfo("EURUSD",M ODE_BID),2,NULL,NULL,"Magic Number 1000",MagicNumber_1,0,CLR_NONE);
Sleep(1000);
OrderSend("USDCHF",OP_SELL,1,MarketInfo("USDCHF",M ODE_BID),2,NULL,NULL,"Magic Number 1000",MagicNumber_1,0,CLR_NONE);
Sleep(1000);
OrderSend("EURUSD",OP_BUY,1,MarketInfo("EURUSD",MO DE_ASK),2,NULL,NULL,"Magic Number 2000",MagicNumber_2,0,CLR_NONE);
Sleep(1000);
OrderSend("USDCHF",OP_BUY,1,MarketInfo("USDCHF",MO DE_ASK),2,NULL,NULL,"Magic Number 2000",MagicNumber_2,0,CLR_NONE);
Sleep(1000);
}
return(0);
}
//+------------------------------------------------------------------+
Kind regards
- 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 need your coding help. I have different open positions from different EAs with unique magic numbers.
Now I want to let check every EA if the EA wants to open a new position to check if there is already an open position with a given magic number.
How can help?
Bset regards,