Problem with multicurrency EA - MQL4

 

Hello,

I have problem with part of code - sending order. Perhaps anyone has an any idea or suggestion.

Assumptation: 10 instruments, every instrument open from a specific function.

If I use in the loop OrdersTotal() SELECT_BY_POS and negation !="abc" there isn't open any order. If I use =="abc" break EA will open positions to the end of money on the account. This is logic. I noticed if I use in the loop after SELECT_BY_POS any info it is not conduct with the loop and terminal.

I'd like to open only one position per specific instrument with the specific condition, and after make actions with it.  I know the problem is with limitation in every function to one open order. But I don't have any idea for it. If I use stop open position by limit OrdersTotal() I can't open next instrument from different function.

I know I can SELECT_BY_POS or SELECT_BY_TICKET only. BY position means 0,1,2 etc.... by ticket using magic number.

Thank you.

 int start()
{

                   
  ABC_original_gbpjpy();
  DEF_original_usdjpy();
 

return(0);
}


void ABC_original_gbpjpy()

{

int MagicNumber=OrderMagicNumber();

// conditions here x and y

for (int i=0;i<=OrdersTotal();i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)continue;
  
 //   if (OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) <---- not working
 //   if (OrderSymbol() !="GBPJPY")continue;                          <---- not working, becuse it is switch on GBPJPY window      
      {
       if( x > y )  
         {
          RefreshRates();
          Ticket=OrderSend("GBPJPY",OP_BUY,0.1,NormalizeDouble(Ask,3),20,0,0,"GBPJPY",MagicNumber);

         if (Ticket>0)
           {
            Print("Order placed #",MagicNumber);
           }
           else 
           {
           Print("OrderSend failed,error#",GetLastError());
           }
          }
       }
   
 }
 
jakiego:

Hello,

I have problem ......

Sorry, I didn't understand all your questions, but :
- Your understanding of magic number seems to be wrong.
-SELECT_BY_TICKET simply means select by ticket, you need to have a look at definition of ticket.

  1. int MagicNumber=OrderMagicNumber();
You didn't select any Order to get its Magic number. then this is meaningless.
Plus,it doesn't seem to me that you need to take the magic number from another order in this EA, you simply need to define a global variable and call it Magic (or anything you want) and give it any number you want  like:
 int Magic = 435453;

  Ticket=OrderSend("GBPJPY",OP_BUY,0.1,NormalizeDouble(Ask,3),20,0,0,"GBPJPY",MagicNumber);

You can't use Ask, because Ask is a giving you the Ask price of the chart on which your EA is running.
instead you need to use :

MarketInfo(_Symbol, MODE_ASK);

Also, you don't need to Normalize Ask or Bid.

for (int i=0;i<=OrdersTotal();i++)

it counts 1 extra, and preferably use the decreasing loop.




for (int i=OrdersTotal()-1;i>=0;i--)
 

Thank you for answer.

My problem is open only one position per instrument. It is mean every function should open only one position.

Decreasing loop during open position ? hmmm............. I have to check this idea. I know the decreasing loop I should use during closing positions (I have it).

 

My problem is open only one position per instrument. It is mean every function should open only one position.


Then you need to make a function which takes the name of symbol and give you back the number of orders of the same symbol (+ checking the magic number).


Decreasing loop during open position ? hmmm............. I have to check this idea. I know the decreasing loop I should use during closing positions (I have it).


I cant understand what you were doing exactly,
But, while your loop is not finished its iterations, if any of orders get closed, your loop will skip some orders.

As you mentioned it is very important when closing orders, because you will see some orders left open for sure, but here in this codes, you may not able to see any problem because the problem happens rarely but happens.

 
Dereasing loop during open trades doesn't work.