Hi everyone, I need help using 1 EA on multiple charts!!

 

summary of my question:

I have an EA which places just 1 order at a time using the variable total = OrdersTotal() . A new order will only open when that 1 order is closed.

How do I modify it so that two different currency pairs can each have 1 open order without the same currency pair having 2 open orders?

what I need are lines of code that allows me to do this:
place 1 order (say, with magic # 12345) if there is not already an order with that specific magic# open.
or, place 1 order if there is not already an order of the same ordersymbol open.

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

longer version of my problem:

So I recently modified a simple EA based on placing orders when the 10 and 5 SMA lines cross.

It works fine with my EURUSD chart and it places only one order at a time, either buy or sell, because I have these lines of code:

total = OrdersTotal();

if(total < 1)

--then it places an order

When I created a duplicate EA and applied it to the EURJPY chart however, I had to change the code to

total = OrdersTotal();

if(total < 2)

--so that it would place an order if an order was already opened on the EURUSD chart.

the problem is that when the EURUSD order closes, a second EURJPY order is allowed to open and the EURUSD EA will not place a new order since there is already an EURJPY order open.


I give the different pairs separate magic numbers. I had an order opened on my EURUSD chart with the magic# 22341 and I tried using a new variable for my EURJPY chart:

tott = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderMagicNumber() == 22341) //22341 is the magic# for EURUSD orders

total = OrdersTotal();

if(total < 2 && tott == true)

--then an order is placed for EURJPY

but it gets complicated letting the EAs run on their own... especially if I add a third currency pair of USDJPY which I want my EA to run on.


any help is appreciated!!

 

i decided to go with magic numbers:

total= 0;
for(int i=0;i<OrdersTotal(); i++ )
{
if(OrderSelect(i, SELECT_BY_POS)==true)
{
if (OrderMagicNumber()==12341)
total++;
}
}
{

if(total < 1)

--then a trade will be made

 
  1. Exactly. Also no need for multiple IFs. Also there's no need for multiple magic numbers unless your putting the EA on multiple timeframes per pair.
    total=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.
          total++;
        }
    if(total < 1)...


 

thanks! that was exactly what i was looking for.

although i don't understand the difference between

 for(pos = OrdersTotal()-1; pos >= 0 ; pos--)

and

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

i know int creates a loop?

anyways, i will try it out


and it works! just have to add int pos at the top.

 

You MUST count down when closing/deleting multiple orders or in the presence of multiple orders on multiple charts

  1. If you close position 0, position 1 becomes 0 but the count increments so you skip some orders.
  2. If you have multiple orders and while modify the first one, another closes on another chart, count increments and you skip some orders.
ALWAYS count down.
 
WHRoeder:

You MUST count down when closing/deleting multiple orders or in the presence of multiple orders on multiple charts

  1. If you close position 0, position 1 becomes 0 but the count increments so you skip some orders.
  2. If you have multiple orders and while modify the first one, another closes on another chart, count increments and you skip some orders.
ALWAYS count down.
I think I see what you are saying here . . but isn't there a risk that an order could be counted twice ?
 

For counting the direction doesn't matter, you're just reading an internal list.

It's when doing server calls (such as moving stops) within the loop that's the problem. So why do it one way for counting and the other way for all other loops.

It is possible to catch the same order twice between server calls, but so what, you're going to try move the stops and they're already moved you can either skip the call or ignore the error 1.

Reason: