How to make EA only open one position per Currency pair.

 

Hi all, I am having difficulties with my code.

I would like it to open one order per currency pair but currently it only opens one order for the whole platform, can anyone guide me as to how i could adjust my code to open one trade per currency pair.

this is what i have currently got going,

   if (signal=="BUY" && OrdersTotal()==0)

   OrderSend (NULL,OP_BUY,.10,Ask,0,(Ask-ATRLoss),(Ask+ATRProfit),NULL,0,0,Green);

   if (signal=="SELL" && OrdersTotal()==0)

   OrderSend (NULL,OP_SELL,.10,Bid,0,(Bid+ATRLoss),(Bid-ATRProfit),NULL,0,0,Red);

 

You must expand the OrdersTotal () definition. For example, with the name Symbol ().

Use OrderSelect()...

 
liamsean000:

I know that it is not obvious, but topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I will move your topic to the MQL4 and Metatrader 4 section.

 
Don't use NULL.
  1. On MT4, you can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not. OrderSend does not.
  2. Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
  3. Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
  4. MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
Reason: