Download MetaTrader 5
To add comments, please log in or register
Trade like successful traders - subscribe to their signals!
amando
425
amando 2014.01.08 23:32 

Hello,

 

im translating my ea from mt4 to mt5 and i have some problems to set the orders.

  for (int i=0;i<PositionsTotal();i++){
      PositionSelect(i);
      if(PositionGetInteger(POSITION_MAGIC) == magic){
         if( PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL ) Sold++;
         if( PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY ) Bought++;
         
            }
         }
          
         if ( Sold   == 0 && Close > OpenPrev && Close > prevClose  ) OpenPendingShort(SL_Sell, Entry_Sell);     
         if ( Bought == 0 && Close < OpenPrev && Close < prevClose  ) OpenPendingLong( SL_Long, Entry_Long );
         

            
       }  

 as long the line with  Bought == 00 i never get any sold order. i can try to delete the Bought line to get sold order.

 

the main idea behind is, look if there is some working orders ( in mt4 was working and pending) and if there is no one set some new one with the void function.

 

please be so kind, and do not refere to the help files. im not an english native and the german documentation is crap.

Alain Verleyen
Moderator
30635
Alain Verleyen 2014.01.09 01:06  

The code you provided has unbalanced brackets, a typo ? Your issue is unclear (at least to me), maybe you can show the mql4 code you want to convert ?

You can also print your variable's values to see why your condition isn't triggered.

amando
425
amando 2014.01.09 10:38  

here is the original MQL4 code

 

   for (i=0;i<OrdersTotal();i++){
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderComment()==Text && OrderMagicNumber()==MN){
         if(OrderType()==OP_BUYSTOP || OrderType()==OP_BUY) Bought++;
         if(OrderType()==OP_SELLSTOP || OrderType()==OP_SELL) Sold++;
      }
   }
   
     
   if( Bought==0 && SMA10 > SMA40){ //no buy order
   
      Ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots, Kauf,3, SLLong, 0,Text,MN,TimeCurrent() + 24 * 60 *60 ,Blue);

        }

       
   if( Sold==0 && SMA10 < SMA40){ //no sell order
   
      Ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots,Verkauf, 3,SLShort, 0,Text,MN,TimeCurrent() + 24*60*60,Red);
        
    }
    
Alain Verleyen
Moderator
30635
Alain Verleyen 2014.01.09 16:39  
amando:

here is the original MQL4 code

 

Ok.

PositionSelect takes a string as parameter (symbol), and return a bool, you have to check this value to see if all is ok.

For pending orders, you have to use OrderXXXX functions.

   // NOT TESTED, NOT COMPILED

   for(int i=0;i<PositionsTotal();i++)
     {
      string symbol=PositionGetSymbol(i);
      if(PositionSelect(symbol))
        {
         if(PositionGetInteger(POSITION_MAGIC)==magic)
           {
            if( PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL ) Sold++;
            if( PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY ) Bought++;
           }
        }
     }
   for(int i=0;i<OrdersTotal();i++)
     {
      ulong ticket=OrderGetTicket(i);
      if(OrderSelect(ticket))
        {
         if(OrderGetInteger(ORDER_MAGIC))
           {
            if(OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_SELL_STOP) Sold++;
            if(OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_BUY_STOP) Bought++;
           }
        }
     }
   if(...)
 
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
/
To add comments, please log in or register