Line of code need explanation please

 
void RemoveEAafterSL()
{
int total = OrdersHistoryTotal();
         for(int i = total - 1; i >= 0; i--)
         {
         if(OrderSelect(i, SELECT_BY_POS,MODE_HISTORY))
            if(OrderSymbol() == Symbol())
               if(OrderMagicNumber()==magic)
               {
               if(OrderClosePrice() == OrderStopLoss()) ExpertRemove();                       // function doesnt work if I use < or > ?
               Print("TimeCurrent : ",TimeCurrent(),"OrderCloseTime : ",OrderCloseTime());    //    This is when i have been comparing values to try understand the statement
               }           
          }
}

i am trying create a function to call as an emergency remove EA when price hits a SL in case market moves against me during basket trading.

My EA places new trades when the basket closes and my StopLoss is the point when I want all trading to stop. 

I had a look around and now have a working function im testing.

I have seen similar code which use:   if(TimeCurrent() - OrderCloseTime()==1)   Can someone please explain how this is used, how can it be == 1 ?

The code im using as follows (or could be above ), Im very open to criticism, help and other options to improve this function to make it more robust.

Thanks

Craig 

 
               if(OrderClosePrice() == OrderStopLoss()) ExpertRemove(); 

If there is slippage, it may close at a different price to the SL


You are checking all history, so if there is any trade with the same symbol and magic number that closed at precisely its SL, the EA will be removed

What does

// function doesnt work if I use < or > ?

mean?

 

 What does

// function doesnt work if I use < or > ?

mean?

 

Hi GumRai

Well, at first I too thought of the slippage scenario so thought best to state;

Code for Buy,   if(OrderClosePrice() < OrderStopLoss()) ExpertRemove();   and for Sell,  if(OrderClosePrice() > OrderStopLoss()) ExpertRemove();

compiled but it didnt remove expert,  but thinking about it now since at the moment my EA opens a new basket when SL is reached the OrderClosePrice will never reach those levels as a new SL is placed.

Thats my thought .. what do you think??

but as long as the EA is removed  that is the main condition, slippage I can handle especially if there is a huge move against me. 

I thought that if using == then the EA may not remove the expert if there was a price jump/gap,  think i would still prefer to use the greater > or less than < statement. Any ideas? Ill have a think more about coding it, shouldnt be too hard..

Any idea about my other query, the use of   if(TimeCurrent() - OrderCloseTime()==1 , cant get my head around how this statement can be equal equivalent 1.. ?

 

Cheers

Craig 

 
craigt  if(TimeCurrent() - OrderCloseTime()==1 , cant get my head around how this statement can be equal equivalent 1.. ?
That means the order was closed exactly one second (+/-) ago. Unlikely to be ever true, the order closed, the server sent an update and then a new tick with a time was one second different.
 
WHRoeder:
That means the order was closed exactly one second (+/-) ago. Unlikely to be ever true, the order closed, the server sent an update and then a new tick with a time was one second different.

Thanks WHRoeder, now I get it..

Cheers

Craig 

Reason: