Download MetaTrader 5

Trading different chart windows with one ea

To add comments, please log in or register
skyblazer
45
skyblazer  

Hi, 

I´m assuming this question came a lot but I couldnt find anythin helpful..

Currently My ea works like:

if(OrdersTotal()==0){

placing order ... etc ..

}

 The problem with the code above is, that it stops trading as soon as one order is open regardless of the conditions to open a new order.

So it cant decide whether the order is from the actual chart or another.  

Another problem would be that I´m using Stopp orders, the ea also have to decide whether its an open order or a pending order. Meaning: Don´t trade when there´s an open order unless it´s a different symbol.

 

How can I solve this? 

maybe like a loop where he checks:  if orderymbol = chartsymbol and if ordertype=op_buy || op_sell

-> dont trade 

Have you guys some better suggestions ? 

whroeder1
17050
whroeder1  
skyblazer: maybe like a loop where he checks:  if orderymbol = chartsymbol and if ordertype=op_buy || op_sell
You already stated the answer.
Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
skyblazer
45
skyblazer  
whroeder1:
You already stated the answer.
 Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum

Well I cant just copy this, can I? 

Because I dont understand in the code from the link why  you return false when he checks the attributes from the order. Dont you want to go through them when they are true ? I mean you used != 

Marco vd Heijden
Moderator
6137
Marco vd Heijden  
you need to fiter with either OrderMagicNumber() and or OrderSymbol()
skyblazer
45
skyblazer  
Marco vd Heijden:
you need to fiter with either OrderMagicNumber() and or OrderSymbol()
And how can I implement the thing with the magicNr filter so that the eas are using an unique one on every single chart ?
Marco vd Heijden
Moderator
6137
Marco vd Heijden  
if(Symbol()==OrderSymbol)
{
  // The chart symbol is equal to the order symbol
}

if(OrderMagicNumber()==magicnumber)
{
  // The ordermagic number is equal to the magicnumber (int)
}
This goes inside you orderselect loop.
whroeder1
17050
whroeder1  
skyblazer: Because I dont understand in the code from the link why  you return false when he checks the attributes from the order. Dont you want to go through them when they are true ? I mean you used != 
I go through all of them. Any that are != are not my MN and pair, I don't want to process them.
Remove the function and put the code inside your loop if you want to. Then you'll have to join the lines with ampersands and change everything to ==. Big deal.
for(int iPos = OrdersTotal()-1; iPos >= 0; iPos--)
  if(MySelect(iPos, SELECT_BY_POS) ){
     oo.ticket   = OrderTicket(); ..

skyblazer
45
skyblazer  
whroeder1:
I go through all of them. Any that are != are not my MN and pair, I don't want to process them.
Remove the function and put the code inside your loop if you want to. Then you'll have to join the lines with ampersands and change everything to ==. Big deal.
for(int iPos = OrdersTotal()-1; iPos >= 0; iPos--)
  if(MySelect(iPos, SELECT_BY_POS) ){
     oo.ticket   = OrderTicket(); ..

I´m sorry but this is so weird to understand for me.

What I have now are the following lines: 

int i; 

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

  if(!OrderSelect( i,SELECT_BY_POS) && OrderSymbol() != _Symbol && OrderMagicNumber() != magicNr){

      can_trade = true;

        else{

can_trade=false;

if(can_trade)

{

...//conditions for placing order...etc. 

       }

In Backtesting ea doesnt open a single order... where is the problem ? 

Keith Watford
Moderator
10533
Keith Watford  

Please use the SRC button when posting code. I have done it for you this time. Your formatting is still a mess though.

If you follow your code you will see that can_trade is assigned a value depending on the last order checked

This should work better for you

int i;

can_trade = true;

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

  if(OrderSelect( i,SELECT_BY_POS) && OrderSymbol() == _Symbol && OrderMagicNumber() == magicNr)

    {

    can_trade=false; 

    break;

    }



Keith Watford
Moderator
10533
Keith Watford  
honest_knave:
Typo or maybe it is time I went to bed?

Yes, you are right.

I modified the original code and to be honest never even noticed the !.

I will edit the post.

Thanks

skyblazer
45
skyblazer  
if(OrdersTotal()==0)
{
can_trade;
}
...


 Thanks for your help. He opens orders now,but however still opens a ton of orders when he gets the signal... which was my initial problem and why I started with the lines above

12
To add comments, please log in or register