Download MetaTrader 5
To add comments, please log in or register
Having troubles understanding the code? Perhaps, you can find an article on that topic!
Joan
22
Joan 2014.07.17 17:12 

Please,  can anyone help me solve this.
I do not want it to open a new trade, at the exact same price as an exisiting open order.

I tryed this, but it keeps open new orders at the same price.
I have read a lot in the documentation, book and forum.

There must be something that I am missing. 

 

if(TradeAllowed() &&  ........... )
{ Open Trade
bool TradeAllowed()
  {
   
   for(int k=OrdersTotal()-1;k>=0;k--)
   {
      if((OrderSelect(k,SELECT_BY_POS,MODE_TRADES))&&(OrderSymbol()==Symbol())&&(OrderMagicNumber()==Magic))
      {
         if(MathAbs(OrderOpenPrice() - Bid) < Dist_Pips*Point) 
      {
      return(false); 
     }
   else return(true);
   }  
   }
   }
FXEZ
14
FXEZ 2014.07.17 17:54  
bool TradeAllowed() {
   for(int k=OrdersTotal()-1;k>=0;k--) {
      if((OrderSelect(k,SELECT_BY_POS,MODE_TRADES)) && 
       (OrderSymbol()==Symbol())&&(OrderMagicNumber()==Magic)) {
         if(MathAbs(OrderOpenPrice() - Bid) < Dist_Pips*Point) {
                return(false); 
         }
       }  
    }
    return(true);
   }

 Hi, you don't want to execute the line: else return(true) because if there are any open trades (early in the list) that have a different price, it will return true even if there are orders that have the same price as the Bid. In other words, allow it to run through and check all the orders to see if any meet your false condition, then if none of the open trades have caused the function to return false, then (and only then) return true. Try the above:

Joan
22
Joan 2014.07.17 18:59  
FXEZ:

 Hi, you don't want to execute the line: else return(true) because if there are any open trades (early in the list) that have a different price, it will return true even if there are orders that have the same price as the Bid. In other words, allow it to run through and check all the orders to see if any meet your false condition, then if none of the open trades have caused the function to return false, then (and only then) return true. Try the above:

Thank you very much.

So all my problems has been the "else"   I am so greatfull to you.

Joan
22
Joan 2014.07.22 15:25  
FXEZ:

 Hi, you don't want to execute the line: else return(true) because if there are any open trades (early in the list) that have a different price, it will return true even if there are orders that have the same price as the Bid. In other words, allow it to run through and check all the orders to see if any meet your false condition, then if none of the open trades have caused the function to return false, then (and only then) return true. Try the above:


Hi

You where so nice to help me with this issue.

Can you also give me a hint, how to only count the last 2 open positions. ?
I would be very greatfull.
 

/
To add comments, please log in or register