Download MetaTrader 5

help needed - page 2

To add comments, please log in or register
Simon Gniadkowski
Moderator
18025
Simon Gniadkowski  
roeysegal:

I used Print() and it returns nothing.

<CODE REMOVED>

Please use the SRC button to post code . . .
Simon Gniadkowski
Moderator
18025
Simon Gniadkowski  
roeysegal:
it doesn't modify. why? no error.
If it fails Print() the GetLastError()
roeysegal
46
roeysegal  
   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("יאללה מכבי");
       }
      }
     }
    }
   else
Print(GetLastError());
roeysegal
46
roeysegal  
it returns "0"
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI  
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");
}
}
}
}
What the..? o.O
Alain Verleyen
Moderator
32547
Alain Verleyen  
roeysegal:


Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.

Daniel Petrovai
440
Daniel Petrovai  
roeysegal:

"return value of 'OrderModify' should be checked". does someone know what this means?

Hi roeysega,

It means you need to check the return value of OrderModify(). Here is what you need to do :

 if(OrderModify(ticket,openprice,openprice+2*spread,takeprofit,0,Red)==false)
    Print("Failed to modify order, error : "+GetLastError());
 else Print("3");

Same thing with OrderSelect() and other. Just give the program a way out, what to do if such ans such happens.

Now, if you do that, insert the code above, you will most likely get an error since your parameters seem to be wrong.

"what more can I do? " . Well, you can relax a bit, don't stress too much and explain what you want the code to do for you.

You've got a couple of things wrong in the code but nothing that can't be fixed. This for example :

if(Bid>takeprofit2-20*Point && Bid<takeprofit2+20*Point && o==0)

will never work because, lets say we have the EURUSD pair and the bid is now 1.35775. takeprofit2 = 50 pips

If we replace the values in the code you get this :

if(1.35775>50-20*0.00001 && 1.35775 <50+20*0.00001 && o==0) Print("1");

so condition 1 is that 1.35775 to be greater than 50-20*0.00001 ; 20*0.00001 = 0.0002 ; 50 - 0.0002= 49.9998 so condition 1 now is : if 1.35775 > 49.9998, then check condition 2.

It will never check condition 2 because condition 1 will never be satisfied and it will never get to execute the rest of the code posted.

Does that make any sense ? I'm not very good at explaining things.

How about you let me know what you want the code to do, eventually post the entire code and I'll try to help you make it work ?

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI  

Rule of thumb ...

Code runs from left to right, top to bottom ...

If left side not met, right side ignored.

Bottom line of code always the highest priority compared to top line of code.

Daniel Petrovai
440
Daniel Petrovai  
deysmacro:

Rule of thumb ...

Code runs from left to right, top to bottom ...

If left side not met, right side ignored.

Bottom line of code always the highest priority compared to top line of code.


Hi deysmacro,

"Code runs from left to right, top to bottom ..." true, but is not executed always that way, is it ?

Example :

Bid>takeprofit2-20*Point

Multiplication first, then subtraction, then comparison.

12
To add comments, please log in or register