OrderClose >> some operator expected

To add comments, please log in or register
Luciole
154
Luciole  

Good evening to the mql4 community,

I was trying to modify an open position, to close 80% of the position to be precise.

And with those instructions an error message appear : 

"some operator expected"

if (MarketInfo(Symbol(), MODE_BID) <= profit)
               {
                   if(OrderSelect (magic,SELECT_BY_TICKET) == true)
                     lot3 = Cdouble::RoundTo Lots(OrderLots() * 0.8);
                     OrderClose (magic, lot3, Bid, 10, Red);
               }


Any idea on how to fix the problem? 

Thanks a lot !

Luciole

Mehmet Bastem
1672
Mehmet Bastem  
Luciole:

Good evening to the mql4 community,

I was trying to modify an open position, to close 80% of the position to be precise.

And with those instructions an error message appear : 

"some operator expected"


Any idea on how to fix the problem? 

Thanks a lot !

Luciole

if (MarketInfo(Symbol(), MODE_BID) <= profit && OrderMagicNumber()==magic)
               {
                   if(OrderSelect (OrderTicket(),SELECT_BY_TICKET) == true)
                      {
                     lot3 = NormalizeDouble((OrderLots() * 0.8),Digits);
                     OrderClose (OrderTicket(), lot3, Ask, 10, Red);
                       }
               }
Keith Watford
Moderator
20380
Keith Watford  
lot3 = NormalizeDouble((OrderLots() * 0.8),Digits);

Using Digits to normalise may give invalid results.

Ahmet Metin Yilmaz
4173
Ahmet Metin Yilmaz  

https://docs.mql4.com/predefined/digitsvar


there are no connection between digits and lotsize

you may use directly  selected orderlots and multiply your choice 

Digits - Predefined Variables - MQL4 Reference
Digits - Predefined Variables - MQL4 Reference
  • docs.mql4.com
Digits - Predefined Variables - MQL4 Reference
Petr Nosek
3023
Petr Nosek  
Luciole:

Any idea on how to fix the problem? 

Try the code below. But I'm not sure if you understand what you are doing. E.G. your comparison Bid with "profit" sounds really strange and there are more similar strange things in your code.

            if (MarketInfo(Symbol(), MODE_BID) <= profit) // This is strange (profit is a price???)
              {
               if(OrderSelect (magic,SELECT_BY_TICKET)) // This is strange (magic as a ticket???)
                 {
                  lot3 = CDouble::RoundToLots(OrderLots() * 0.8); // Now it is correct
                  OrderClose (OrderTicket(), lot3, Bid, 10, Red); // This is correct only if it is a LONG trade (Bid)
                 }
              }
Keith Watford
Moderator
20380
Keith Watford  
OrderClose (OrderTicket(), lot3, Bid, 10, Red); // This is correct only if it is a LONG trade (Bid)

A good habit to get into is to Use OrderClosePrice() as then it doesn't matter if it is a Long or a Short trade, it will always be correct.

OrderClose (OrderTicket(), lot3, OrderClosePrice(), 10, Red); // This is correct for either a long or short
Mehmet Bastem
1672
Mehmet Bastem  
Keith Watford:

A good habit to get into is to Use OrderClosePrice() as then it doesn't matter if it is a Long or a Short trade, it will always be correct.

    if(OrderType()==OP_BUY) OrderClose (OrderTicket(), lot3, MarketInfo(OrderSymbol(), MODE_BID), 10, Red);
     if(OrderType()==OP_SELL) OrderClose (OrderTicket(), lot3, MarketInfo(OrderSymbol(), MODE_ASK), 10, Red);
Keith Watford
Moderator
20380
Keith Watford  
 if(OrderType()==OP_BUY) OrderClose (OrderTicket(), lot3, MarketInfo(OrderSymbol(), MODE_BID), 10, Red);
 if(OrderType()==OP_SELL) OrderClose (OrderTicket(), lot3, MarketInfo(OrderSymbol(), MODE_ASK), 10, Red);

What advantage is there over using the much simpler

OrderClose (OrderTicket(), lot3, OrderClosePrice(), 10, Red); // This is correct for either a long or short

??

Luciole
154
Luciole  
Petr Nosek:

Try the code below. But I'm not sure if you understand what you are doing. E.G. your comparison Bid with "profit" sounds really strange and there are more similar strange things in your code.

Thanks a lot for your help.


So if it is a short i should write ask instead of bid?

I do no understand why...


Thanks..

Luciole
154
Luciole  
Keith Watford:

What advantage is there over using the much simpler

??

This a good question, I hope we get an answer :)

Luciole
154
Luciole  
Petr Nosek:

Try the code below. But I'm not sure if you understand what you are doing. E.G. your comparison Bid with "profit" sounds really strange and there are more similar strange things in your code.

My code is weird.. outch 

yeah i am a beginner

What I wanted to write 

is I am selling and when bid reach my first take profit (variable = profit),

then i want to close 80% of the position..


Should I write it differently?

12
To add comments, please log in or register