Lot size - page 3

To add comments, please log in or register
nicholi shen
2155
nicholi shen  
Luciole:

Thanks I did and it is almost working !!! thanks a lot !

I still have some problems when I try to close some part of the lots.


What I initially wrote was :

But then, a warning message saying "return value of 'orderClose' should be checked

So I wrote that, as suggested here

Now there is this error message  "'return' - 'void' function returns a value".

I am confused as I do not understand why should I wrote return 0.. or do anything else..

Any suggestions? :)



What is that you are actually trying to accomplish? Tell us your end goal in plain English. 

Luciole
120
Luciole  

Hi (again),

in plain English,

 at this point, my EA is supposed to have taken a trade, and I want it to manage it:

When it reaches TP1 (profit), 80% of the position should be closed (lots3)


 while (trade == 1) // trade has been taken

             {

               if (MarketInfo(Symbol(), MODE_BID) <= profit) //if the market reaches TP1

               {

                   if(OrderSelect (magic,SELECT_BY_TICKET) == true) //then it selects my trade

                     lot3 = CDouble::RoundToLots(OrderLots() * 0.8); //it calculates 80% of the position

                     OrderClose (OrderTicket(), lot3, OrderClosePrice(), 10, Red); //and close 80% of it

                }

then this error message appears:


Petr Nosek
1508
Petr Nosek  
Luciole:
 

then this error message appears:

OrderClose isn't a void function but a bool function and you should check the return value if the OrderClose was successful or not. See documentation: https://docs.mql4.com/trading/orderclose
OrderClose - Trade Functions - MQL4 Reference
OrderClose - Trade Functions - MQL4 Reference
  • docs.mql4.com
OrderClose - Trade Functions - MQL4 Reference
Luciole
120
Luciole  
Petr Nosek:
OrderClose isn't a void function but a bool function and you should check the return value if the OrderClose was successful or not. See documentation: https://docs.mql4.com/trading/orderclose

it took me some time to figure out how to make it work.

here is the final code (if it helps someone):

 while (numberTrade == 1) 
             {
               if (MarketInfo(Symbol(), MODE_BID) <= profit)
               {
                   if(OrderSelect (ticket,SELECT_BY_TICKET) == true)
                     {
                     if(OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == magic) 
                        {
                        lot3 = CDouble::RoundToLots(OrderLots() * 0.8);
                        rueck = OrderClose (OrderTicket(), lot3, OrderClosePrice(), 10, Red);
                        return;  
                        }
                   }
                }
123
To add comments, please log in or register