OrderTotal Help ? - page 2

 
themasterx7:

I think your code is better, I have this one I don't know if it will work:

I will try it all and see what works.

be carefull with your variable OrderType, it's a mql function...

 
remcous:

be carefull with your variable OrderType, it's a mql function...

Will do, and thanks again remcous.

 
if (OrdersTotal()==0){
         OrderType=OrderType();

You can not use any Trade Functions until you first select an order.

 
William Roeder:

You can not use any Trade Functions until you first select an order.

I'll keep it in mind Thanks.

 

I'll try this and see:

int OrderType; 


    



if (OrdersTotal()==0)
{
   if(OrderSelect(...) 
     {                          
         OrderType=OrderType();//or if(OrderType=OrderType())
        //Open Buy Trade
      {

}
 if (OrdersTotal()==1)
{
       if(OrderSelect(...)
     {
         OrderType=OrderType();
        //Close the Trade
     }   
}
else 
{
//print error
}
 

I tried it all nothing seem to work I tried this one also I don't know what's wrong with it:

 if(Code&&OrdersTotal()==0&&(OP_BUY==1||OP_BUY==0)) ////SELL     
   {
   ticket= OrderSend(Symbol(),OP_SELL,lotSize,Bid,3,0,0,NULL,0,0,Red);
   
   }
   
   
   for(i=0;i<OrdersTotal();i++)
      { 
         select= OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      
          if(OrderType()==OP_SELL &&OrderSymbol()==Symbol())
          if(CODE)
        {
         closeticket=OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
        }
   
     }
     
  // if(OrdersTotal()<x)                                     ////////////////BUY
   if(CODE&&OrdersTotal()==0&&(OP_SELL==1||OP_SELL==0))
   {
   ticket= OrderSend(Symbol(),OP_BUY,lotSize,Ask,3,0,0,NULL,0,0,Red);
   }
   
   
   for(i=0;i<OrdersTotal();i++)
      { 
      select= OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      
   if(OrderType()==OP_BUY &&OrderSymbol()==Symbol())
   if(CODE)
   {
   closeticket=OrderClose(OrderTicket(),OrderLots(),Bid,3,Green);
   }
     }
 
themasterx7:

I tried it all nothing seem to work I tried this one also I don't know what's wrong with it:

So I need to take out OrdersTotal() or Add a Function that counts trades?

if(Code&&OrdersTotal()==0&&(OP_BUY==1||OP_BUY==0)) ////// OrderTotal==0 need to deleted and add some kind of variable ?
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 | //| Expert tick function                                             | //| test1                                                            |...
 
if (OrdersTotal()==0)
{
   if(OrderSelect(...) 
     {   

This willnever be true.

You can not select an order if the orderstotal == 0

 

I asked you in post #2

What is the variable CODE and where does it get its value from? 

You ignored the question

Now you have added a new variable  Code.

 
Keith Watford:

I asked you in post #2

You ignored the question

Now you have added a new variable  Code.

sorry for the late replay, I thought I answered you I don't know what you mean maybe you mean this :

int Buy_trade=0;
int Sell_trade=0;
int x=1; 






if(Sell_trade>0)             ///////////////////////////////////////////////////SELL
    {
    //value of Sell_Trade
  
  for(i=0;i<OrdersTotal();i++)
      { 
         select= OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      
          if(OrderType()==OP_SELL &&OrderSymbol()==Symbol())
          if(CODE)
        {         
         closeticket=OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
        }
   
     }
    }
    else
    {
   if(OrdersTotal()<x) 
   if(CODE)
   {
   ticket= OrderSend(Symbol(),OP_SELL,lotSize,Bid,3,0,0,NULL,0,0,Red);
   
   }


   }
   if(Buy_trade>0)                   /////////////////////BUY
    {
    for(i=0;i<OrdersTotal();i++)
      { 
      select= OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      
   if(OrderType()==OP_BUY &&OrderSymbol()==Symbol())
   if(CODE)
   {
   closeticket=OrderClose(OrderTicket(),OrderLots(),Bid,3,Green);
   }
    }
       
  }
  else
  {
  if(CODE)
   {
   ticket= OrderSend(Symbol(),OP_BUY,lotSize,Ask,3,0,0,NULL,0,0,Red);
   }
  }
  
 } 
    } 

like  remcous told me, I have two variables in this case I have three Global values :

int Buy_trade=0;
int Sell_trade=0;
int x=1; 

so I think that what you mean is my variable code is If(Buy_trade or Sell_Trade >0 ||<0) and they get its value from the global but do I need to assign a value of my global variable inside my code because it doesn't work . If I didn't answer you give me an Example of a variable code and its value.

remcous
remcous
  • www.mql5.com
Trader's profile
Reason: