Download MetaTrader 5

help needed

To add comments, please log in or register
Publish your article. We will translate it into other languages!
roeysegal
46
roeysegal 2014.04.02 18:22 
hi. I wrote the code and it was good. but somehow now there is a warning about the "OrderModify" and I can't find the problem. it writes "return value of 'OrderModify' should be checked". does someone know what this means?
roeysegal
46
roeysegal 2014.04.02 20:10  
if (Bid>takeprofit2-20*Point&&Bid<takeprofit2+20*Point&&o==0)
{
for(int i=OrdersTotal()-1;i>=0;i--)
{
for(int j=i;j>=0;j--)
{
if(OrderSelect(i, SELECT_BY_POS))
{
o=2;
ticket=OrderTicket();
openprice=OrderOpenPrice();
takeprofit=OrderTakeProfit();
OrderModify(ticket,openprice,openprice+2*spread,takeprofit,0,Red);
Toast
226
Toast 2014.04.02 20:21  

https://www.mql5.com/en/forum/139592

and

https://docs.mql4.com/en/trading/ordermodify

Returned value (OrderModify)

If the function succeeds, it returns true, otherwise false.

roeysegal
46
roeysegal 2014.04.03 18:54  
thanks. I know that. but it was o.k before and I haven't changed nothing. and now all my programs have this problem. maybe it's because the mt4 had been updated?
Toast
226
Toast 2014.04.03 19:17  

You aren't checking the return value of OrderModify in your last line of code. That is why you are get the warning.

To put it another way, MT4 wants you to check if the OrderModify function returns true or false rather than just blindly running it.

MT4 is now more strict and alerts you to this bad style as a warning (not an error).

if(OrderModify(ticket,openprice,openprice+2*spread,takeprofit,0,Red)) {/*do something*/} else {/*do something else*/}
roeysegal
46
roeysegal 2014.04.03 20:11  

is it new?

qjol
3243
qjol 2014.04.03 20:16  
roeysegal:

is it new?


yes
roeysegal
46
roeysegal 2014.04.03 20:18  
thank you very much. it works :)
roeysegal
46
roeysegal 2014.04.03 20:55  
it doesn't modify. why? no error.
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.04.03 23:23  
roeysegal:
it doesn't modify. why? no error.

Use Print() so that it produce output in case it doesn't modify.
roeysegal
46
roeysegal 2014.04.04 09:18  

I used Print() and it returns nothing.

if(Bid>takeprofit2-20*Point && Bid<takeprofit2+20*Point && o==0)
  {
   Print("1");
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      for(int j=i;j>=0;j--)
        {
         if(OrderSelect(i,SELECT_BY_POS))
           {
            Print("2");
            o=2;
            ticket=OrderTicket();
            openprice=OrderOpenPrice();
            takeprofit=OrderTakeProfit();
            if(OrderModify(ticket,openprice,openprice+2*spread,takeprofit,0,Red))
               Print("3");
           }
        }
     }
  }
"o" is changed to 0 when all positions are closed.

takeprofit2 is at least 40-50 pips from OpenPrice(). and it gets there, but doesn't enter. it doesn't return "1".

what more can I do?

12
To add comments, please log in or register