Download MetaTrader 5
To add comments, please log in or register
Do you wonder how to use widgets? Read the article!
mihailmql
18
mihailmql 2015.04.23 10:16 

Well,I've made an Expert Advisor that is supposed to open an order once the current price reaches the upper Bollinger Band(it will check it every 30 minutes and in 9 symbols).
The problem is that if the current price reaches the upper Bollinger Band and after 30 minutes it reaches there again,it will open another order which is not what I wanted.
I have been trying for 4 days to avoid it but couldn't...  

My main try was to check if an order with the same symbol already existed and then to open the new order in each symbol(only where the condition was true of course) except for the opened order symbol. 
For example:
If the current price reached the the upper bollinger band in EURUSD,USDCAD and EURJPY but an order with EURUSD symbol already existed,it will open the order only in USDCAD and EURJPY.

Can someone help me please?

Thanks in advance! 

Keith Watford
Moderator
7875
Keith Watford 2015.04.23 11:16  
   int total=OrdersTotal();
   string open_order_symbols[];
   ArrayResize(open_order_symbols,total);
   for(int x=total-1;x>=0;x--)
      {
      if(OrderSelect(x,SELECT_BY_POS) && OrderMagicNumber()==MagicNumber) //Assuming that your EA uses a magic number
         open_order_symbols[x]=OrderSymbol();
      }
   
   //Code for checking conditions for symbol - using EURUSD as an example
   bool check_conditions=true;
   for(int x=total-1;x>=0;x--)
      {
      if(open_order_symbols[x]=="EURUSD")
         {
         check_conditions=false;
         break;
         }
      }
   if(check_conditions)
      {
      //CHECK FOR CONDITION TO OPEN AN ORDER FOR THIS SYMBOL AND OPEN IF TRUE
      }
Not Tested or compiled but may help you
mihailmql
18
mihailmql 2015.04.23 15:30  

Hey there!
Thanks for helping me but the problem is that I don't really know how to open a buy trade in all of the symbols (which reached the upper Bollinger Band) except for "EURUSD".. I have tried so many silly things like OrderSend (Symbol() - "EURUSD"....) but nothing really helped me.. 

Can you solve this one please? 

Keith Watford
Moderator
7875
Keith Watford 2015.04.23 20:25  

You check conditions for each symbol individually

I believe that it is simplest to store the symbols in an array and then check each symbol in a loop

   string symbol_array[]={"EURUSD","USDCAD","EURJPY"};
   int array_size=ArraySize(symbol_array);

   int total=OrdersTotal();
   string open_order_symbols[];
   ArrayResize(open_order_symbols,total);
   for(int x=total-1;x>=0;x--)
     {
      if(OrderSelect(x,SELECT_BY_POS) && OrderMagicNumber()==MagicNumber) //Assuming that your EA uses a magic number
         open_order_symbols[x]=OrderSymbol();
     }

//Code for checking conditions for symbols
   for(int symbols=array_size-1;symbols>=0;symbols--)
     {
      bool check_conditions=true;
      for(int x=total-1;x>=0;x--)
        {
         if(open_order_symbols[x]==symbol_array[symbols])
           {
            check_conditions=false;
            break;
           }
        }
      if(check_conditions)
        {
         //CHECK FOR CONDITION TO OPEN AN ORDER FOR THIS SYMBOL STORED IN symbol_array[symbols]
         //IF CONDITIONS ARE SATISFIED - OPEN A TRADE
        }
     }

 Not tested

whroeder1
13597
whroeder1 2015.04.24 13:16  
Hoyeah: Well,I've made an Expert Advisor that is supposed to open an order once the current price reaches the upper Bollinger Band(it will check it every 30 minutes and in 9 symbols).

You are overly complicating everything. Trading other pairs mean you can not use any predefined variables and must pole all symbols for new ticks (onTick is called only for the current chart.)

Make your EA trade the current chart pair only. Then put it on multiple charts. Done.

Keith Watford
Moderator
7875
Keith Watford 2015.04.24 13:37  
WHRoeder:

You are overly complicating everything. Trading other pairs mean you can not use any predefined variables and must pole all symbols for new ticks (onTick is called only for the current chart.)

Make your EA trade the current chart pair only. Then put it on multiple charts. Done.

Good advice
mihailmql
18
mihailmql 2015.04.27 15:31  

Well,this is very nice and I could have never thought about this idea alone but as you can surely see in your code,when an order equals to one of the symbols which are attached to the chart(the ones that we have chosen before),it stops the for loop(break;) and then continues and checks what if they are not equal,but I don't want it just to stop the for loop using break;,I want it to open an order in the symbols that touched the Upper Bollinger Band EXCEPT for the one which equals the order symbol.. even if it has touched the upper BB as well!

In other words,I don't want my program to place another if an order with the same symbol already exists..
Or,if you have already done that in your previous code,please tell me what to do to get exactly what I want..

 

Thanks in advance mate!! 

whroeder1
13597
whroeder1 2015.04.27 21:12  
Hoyeah: I don't want my program to place another if an order with the same symbol already exists..
So change GumRai 's OrderSelect loop to only process your symbol. What's the problem?
learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
mihailmql
18
mihailmql 2015.04.28 16:14  
Well,I can post my attempt if you wish... 
I can't continue my program without this small part and I will never pay someone to code for me something which is not even a quarter of my program while the rest I already know myself.
whroeder1
13597
whroeder1 2015.04.29 13:02  
Hoyeah: Well,I can post my attempt if you wish...
What part of "post your attempt and the nature of your problem" was unclear?
/
To add comments, please log in or register