Orderstotal()<1) for specific pair, chart or magicnr

 

Hi,

I am stuck for a week on this problem:

I have the same EA (can easily give it different magic nr's) on like 7 pairs. I do not want the ea open a position when there is already a position open on that particulair pair.  
I searched a lot on orderstotal, bools, magicnr's et  etc. Finally I get stuck here. 

I added the function Orderstotal just before the OrderSend parts: if(OrdersTotal()<1) 

The only problem is that it now counts total open orders in the account and not on the pair/chart/magic nr. Al three would work. 

Could somebody show me which adaption  I should make?

 Thanks a lot! 

I know that there were some threads before and there is where I got my first attempts from but as I am not a coder it did not brought me further than this. And I really really tried. I am not lazy, just got stuck!

Thanks a million! 


----------------------------------------------

extern double lots=0.1;
extern double target=4;
int cbars=0;
extern int magic=9348670;
int dist=24;


int start() {

 double profit=0;
 int j=OrdersTotal()-1;
 for (int i=j;i>=0;i--)
  {
   OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
   if(OrderMagicNumber()==magic && OrderSymbol()==Symbol())
   profit=OrderProfit()+OrderSwap()+profit;
  }
 
 if (profit>=target)
  {
   j=OrdersTotal()-1;
   for (i=j;i>=0;i--)
    {
     OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
     RefreshRates();
     if(OrderType()==OP_BUY && OrderMagicNumber()==magic && OrderSymbol()==Symbol())
      OrderClose(OrderTicket(),OrderLots(),Bid,3,Blue);
    }
  }
 
 double sig = Lowest(NULL,0,MODE_LOW,dist,0);
 if(OrdersTotal()<1)
 if(cbars!=Bars && sig==1)
  {
   RefreshRates();
   OrderSend(Symbol(),OP_BUY,lots,Ask,3,0,0,"buy",magic,0,Blue);
   string AN="ArrBuy "+TimeToStr(CurTime());
   ObjectCreate(AN,OBJ_ARROW,0,Time[1],Low[1]-3*Point,0,0,0,0);
   ObjectSet(AN, OBJPROP_ARROWCODE, 233);
   ObjectSet(AN, OBJPROP_COLOR , Blue);
  }

 profit=0;
 j=OrdersTotal()-1;
 for (i=j;i>=0;i--)
  {
   OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
   if(OrderType()==OP_SELL && OrderMagicNumber()==magic && OrderSymbol()==Symbol())
   profit=OrderProfit()+OrderSwap()+profit;
  }
 
 if (profit>=target)
  {
   j=OrdersTotal()-1;
   for (i=j;i>=0;i--)
    {
     OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
     RefreshRates();
     if(OrderType()==OP_SELL && OrderMagicNumber()==magic && OrderSymbol()==Symbol())
      OrderClose(OrderTicket(),OrderLots(),Ask,3,Magenta);
    }
  }
 
 sig = Highest(NULL,0,MODE_HIGH,dist,0);
 if(cbars!=Bars && sig==1)
 if(OrdersTotal()<1)
  {
   RefreshRates();
   OrderSend(Symbol(),OP_SELL,lots,Bid,3,0,0,"sell",magic,0,Magenta);
   AN="ArrSell "+TimeToStr(CurTime());
   ObjectCreate(AN,OBJ_ARROW,0,Time[1],High[1]+3*Point,0,0,0,0);
   ObjectSet(AN, OBJPROP_ARROWCODE, 234);
   ObjectSet(AN, OBJPROP_COLOR , Magenta);
  }

 cbars=Bars;
 
 return(0);
}

 
RaptorUK:
Please edit your post . . .    please use the   SRC   button to post code: How to use the   SRC   button.


Excuse me. Done
 
Dutchpips:

Excuse me. Done
Thank you.
 
Dutchpips:

Hi,

I am stuck for a week on this problem:

I have the same EA (can easily give it different magic nr's) on like 7 pairs. I do not want the ea open a position when there is already a position open on that particulair pair.  
I searched a lot on orderstotal, bools, magicnr's et  etc. Finally I get stuck here. 

I added the function Orderstotal just before the OrderSend parts: if(OrdersTotal()<1) 

The only problem is that it now counts total open orders in the account and not on the pair/chart/magic nr. Al three would work. 


In your first loop . . .

for (int i=j;i>=0;i--)

  . .   add a variable, EAOrdersTotal,  that you use to keep a running count of the order than meet your criteria of magic number and Symbol and then instead of . . .

if(OrdersTotal()<1)

  . . . use . . 

if(EAOrdersTotal < 1)
 
Dutchpips: I added the function Orderstotal just before the OrderSend parts:

You wan to create your own function. Something which filters your Magic#, Symbol...etc. Then it returns a count. Also, you can try using a for(loop) doing the count within the loop and using the count like OrdersTotal. Something like below.... You need to fix.

j=OrdersTotal()-1;
int Count=0;

for (i=j;i>=0;i--)
{
   OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
   if(OrderType()==OP_SELL 
     && OrderMagicNumber()==magic 
     && OrderSymbol()==Symbol()
   ){
     Count=Count+1;   //Count++
   }
}

if( Count==0 ){ do_something; }
 

Dear RaptorUK,

 

Many thanks for your quick response. Sorry, but I still don't get it.

 

if(OrderMagicNumber()==magic && OrderSymbol()==Symbol())

 

 Checks for magic number already (and all ea's have different magic nr)
Do I have to change the word symbol for a specific Pair here?

Furthermore I do not know how to add the variable. 

Trying just give me invalid codes *#&^$

 I am sorry I am so noob on this ;-) 

 
If you're new to programming, then try searching for newbie programming tutorials on the web. You can also try the mql-Book. If it's comprehensible for your level then continue with that.
 
Dutchpips:

Dear RaptorUK,

 

Many thanks for your quick response. Sorry, but I still don't get it.

 Checks for magic number already (and all ea's have different magic nr)
Do I have to change the word symbol for a specific Pair here?

Furthermore I do not know how to add the variable. 

Trying just give me invalid codes *#&^$

If you want help then that is OK,  I'll help . . .   if you want someone to write code for you then go here:  Jobs

 

if(OrderMagicNumber()==magic && OrderSymbol()==Symbol())  EAOrdersTotal++;  //  increment the running total of orders for this EA
 
Simon Gniadkowski:

If you want help then that is OK,  I'll help . . .   if you want someone to write code for you then go here:  Jobs

 

Hi Simon! i found this thread and found your answer works.

thanks alot

Reason: