Download MetaTrader 5
To add comments, please log in or register
Add our channel to friends and follow the news!
Jan
175
Jan 2016.11.23 20:38 

Hey Guys,

I want to make a backtest but for that I need to programm my EA so that it is possible to execute more than only one trade?
At the moment I have programmed it so that the EA can only trade once. But I have no idea how to programm the EA so that he can trade more than one time but only one trade at the same time!

How is that possible? - Any idea?

Greetings and Thank you! 

whroeder1
13929
whroeder1 2016.11.23 21:06  
Jan: But I have no idea how to programm the EA so that he can trade more than one time but only one trade at the same time!
On a new tick, do a OrderSelect loop and see if you already have an open order. Don't open another if you do.
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
Keith Watford
Moderator
8780
Keith Watford 2016.11.23 22:36  
how to programm the EA so that he can trade more than one time but only one trade at the same time!

You are not being very clear.


   bool can_trade=true;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
         if(OrderOpenTime()>=Time[0])
           {
            can_trade=false;
            break;
           }
     }
    
     if(can_trade)
        {
        //Check conditions to place trade
        }
The above code will only allow 1 trade per bar
/
To add comments, please log in or register