What's wrong with using this to modify orders? - page 3

 
yuan83:

Hi WHRoeder,

 I will try that out. Thanks. But for the case of a trade hitting stop loss, what can I use to identify that? Thanks

You can check the OrderClosePrice() vs OrderStopLoss() of the closed order,  it isn't exact though,  if price moves past your SL it can close at a price that isn't your SL.
 
RaptorUK:
You can check the OrderClosePrice() vs OrderStopLoss() of the closed order,  it isn't exact though,  if price moves past your SL it can close at a price that isn't your SL.


Looks like my post didn't get through. Wanted to ask. Do the commands you suggested shows the price at stop loss? If so, what I actually meant is, is there a command to indicate that the trade hit stop loss and is closed? Instead of still open and running?thanks! 

 
yuan83:


Looks like my post didn't get through. Wanted to ask. Do the commands you suggested shows the price at stop loss? If so, what I actually meant is, is there a command to indicate that the trade hit stop loss and is closed? Instead of still open and running?thanks! 

If the order is open it isn't closed,  if it's in the order pool instead of the history pool it isn't closed,  if it's OrderCloseTime() is  0  then it's not closed, have a read of the available Trading Functions
 

Could anyone advise what's wrong with the below?

 

for(j=0; j < i; j++)
                        {if(OrderSelect(x[j], SELECT_BY_POS)==true)
                           {if (OrderCloseTime() ==0 && OrderType() == OP_BUYSTOP) 
                              {SL1 = NormalizeDouble((iLow(Symbol(),PERIOD_M5,1) - 2*iATR(Symbol(),PERIOD_M5,14,1)),Digits);
                               Openprice = NormalizeDouble((Ask - 2*iATR(Symbol(),PERIOD_M5,14,NULL)),Digits);
                              OrderModify(x[j], Openprice, SL1,0, 0, CLR_NONE);  
                              }
                            if (OrderCloseTime()==0 && OrderType()==OP_BUY)
                            {    SL1 = NormalizeDouble((iLow(Symbol(),PERIOD_M5,1) - 2*iATR(Symbol(),PERIOD_M5,14,1)),Digits);
                                 OrderModify(x[j], OrderOpenPrice(), SL1,0, 0, CLR_NONE); 



 

should i not use the loop? it does not modify, with ordermodify  error 4051. or is one of my ordertype wrong? hmm 

 
yuan83:

Could anyone advise what's wrong with the below?

 

 

should i not use the loop? it does not modify, with ordermodify  error 4051. or is one of my ordertype wrong? hmm 

How do you know that your SL is less than the OrderOpenPrice () ?

 

If you don't take the advice you are given why should people still help you ? 

RaptorUK:
Amongst other things yes,  did you replace NULL with 0 ?  did you code checks on the return values and report all errors ?  how are you recovering if your EA has to stop and restart ?

RaptorUK:
What if the OrderSend() fails ? you will have a ticket number of -1 in your array . . .  read this:   What are Function return values ? How do I use them ?


Why aren't you checking the return value from the OrderModify() ?  if it fails you could print the error number,  the Bid and Ask prices,  the current OrderOpenPrice() the new SL you are trying to set and then you might be able to find out why you are getting an error  4051.

 

Hi Raptor,

 sorry, i did not address all of your questions. So the normal standard is actually to write the ticket numbers to a file and retrieve from there if need to? I am still not good with all the commands. 

 

But one thing i really don't understand is...

 

y =OrderSend(Symbol(),OP_SELLSTOP, lots, Openprice, 0, SL, 0,0,CLR_NONE);
                  if (y>0)
                        {  x[i] = y;
                           i++;
                        }
               }
         for(j=0; j < i; j++)
         {    if(OrderSelect(x[j], SELECT_BY_POS)==true)

I tried to put a Print("x[j]", x[j]) after the orderselect.... .what i keep getting is the value 0.

 if i put the print at x[i], before i++, i get the same value i.e. 0. but y has a value.. . 

why is the array not storing my ticket number? 

 
yuan83:


why is the array not storing my ticket number? 

I don't know . . .  you have all of your code,  add some debugging Print() statements and spend a few hours and find out . . .
Reason: