help needed - page 2

 
roeysegal:

I used Print() and it returns nothing.

<CODE REMOVED>

Please use the SRC button to post code . . .
 
roeysegal:
it doesn't modify. why? no error.
If it fails Print() the GetLastError()
 
   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());
 
it returns "0"
 
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
 
roeysegal:


Hello,

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


This time, I edited it for you.

 
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 ?

 

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.

 
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.

Reason: