Download MetaTrader 5

some operator expected

To add comments, please log in or register
Do you want to deposit to your account? Do this in any convenient way!
dr.Rez
60
dr.Rez 2016.07.03 10:51 

hi

I'm new in programming. 

can you please help me to find out what's the problem with this part of my EA ?

I've  got this Error : 'totallots'- some operator expected 

double TotalLots ()

{



double totalots=0;


for(int i=0; i<OrdersTotal(); i++)


   {

       OrderSelect(i, SELECT_BY_POS, MODE_TRADES)


          totalots+=OrderLots(); 

   }

return(0);

}

Ernst Van Der Merwe
4732
Ernst Van Der Merwe 2016.07.03 13:40  

OrderSelect() should be checked in case of an error and TotalLots() should return a value.

double TotalLots ()
  
  {

   double totalots=0;

   for(int i=0; i<OrdersTotal(); i++)

     {

       if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
       
          continue;

       totalots+=OrderLots(); 

     }

   return(totalots);

  }
dr.Rez
60
dr.Rez 2016.07.03 22:55  

Thank you

and yes  I forgot about return :D 

but   about the other problem , is the error " return value of OrderClose should be cheked" in codes below has same problem ?

void AllOrdersClose ()

   {

   for(int i=OrdersTotal()-1 ; i>=0 ; i-- )

     {

     while(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)

         {

           OrderClose(OrderTicket(),OrderLots(),MarketInfo(Symbol(),MODE_ASK),Slippage,Green);

           OrderClose(OrderTicket(),OrderLots(),MarketInfo(Symbol(),MODE_BID),Slippage,Green);

         }

      }

     } 


Sorry for bad english

Marco vd Heijden
Moderator
4704
Marco vd Heijden 2016.07.03 23:36  
dr.Rez:

Thank you

and yes  I forgot about return :D 

but   about the other problem , is the error " return value of OrderClose should be cheked" in codes below has same problem ?

void AllOrdersClose ()

   {

   for(int i=OrdersTotal()-1 ; i>=0 ; i-- )

     {

     while(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)

         {

           OrderClose(OrderTicket(),OrderLots(),MarketInfo(Symbol(),MODE_ASK),Slippage,Green);

           OrderClose(OrderTicket(),OrderLots(),MarketInfo(Symbol(),MODE_BID),Slippage,Green);

         }

      }

     } 


Sorry for bad english

Don't you like to verify that the order was indeed closed, and take additional action if it did not succeed?

OrderClose()


Returns a value, and the compiler is telling you hey you didn't check the return value.

bool result=OrderClose()
 {
  if(result==true)
    {
    Print("Ok");
    }
  else if(result==false)
    {
     Print(OrderClose Error!");
    }
 }
dr.Rez
60
dr.Rez 2016.07.04 00:08  
Marco vd Heijden:

Returns a value, and the compiler is telling you hey you didn't check the return value.

Thank you 

So OrderClose  not only close position ,but it also  returns a Boolean value that it should be used for checking . right?

I don't know if my English is understandable or not but I hope  it is :)

Marco vd Heijden
Moderator
4704
Marco vd Heijden 2016.07.04 07:41  
dr.Rez:

Thank you 

So OrderClose  not only close position ,but it also  returns a Boolean value that it should be used for checking . right?

I don't know if my English is understandable or not but I hope  it is :)

Put the cursor on the function in meta editor and press F1.

This will open up the reference library and show you exactly what it returns.

OrderClose

Closes opened order.

bool  OrderClose(
   int        ticket,      // ticket
   double     lots,        // volume
   double     price,       // close price
   int        slippage,    // slippage
   color      arrow_color  // color
   );

Parameters

ticket

[in]  Unique number of the order ticket.

lots

[in]  Number of lots.

price

[in]  Closing price.

slippage

[in]  Value of the maximum price slippage in points.

arrow_color

[in]  Color of the closing arrow on the chart. If the parameter is missing or has CLR_NONE value closing arrow will not be drawn on the chart.

Returned value

Returns true if successful, otherwise false. To get additional error information, one has to call the GetLastError() function.

dr.Rez
60
dr.Rez 2016.07.04 14:08  
Marco vd Heijden:

Put the cursor on the function in meta editor and press F1.

This will open up the reference library and show you exactly what it returns.

OrderClose

Closes opened order.


dr.Rez
60
dr.Rez 2016.07.04 14:13  
Thanks a lot 

it was very helpful for me
Slawa
Moderator
6841
Slawa 2016.07.13 10:48  
dr.Rez:

hi

I'm new in programming. 

can you please help me to find out what's the problem with this part of my EA ?

I've  got this Error : 'totallots'- some operator expected 

double TotalLots ()

{



double totalots=0;


for(int i=0; i<OrdersTotal(); i++)


   {

       OrderSelect(i, SELECT_BY_POS, MODE_TRADES)


          totalots+=OrderLots(); 

   }

return(0);

}

Some expected operator is semicolon after OrderSelect

      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

dr.Rez
60
dr.Rez 2016.07.26 20:26  
Slawa:

Some expected operator is semicolon after OrderSelect

      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

really ? :))
thank you so much Slawa
To add comments, please log in or register