Why do i get expiration of buy/sell limit Orders while EA backtesting ?

 

Hi Folks,

 

During backtesting of my EA, frequently the opened Sell-limit and Buy-limit orders get closed due to expiration. I dont know why, since i do have the expiration time defined in the code:

 

if ( Bid>(tdn-big_limit*Point) && Bid<(tdn-small_limit*Point) && tdo!=empty && tuo==empty && LastOrder != 0    ) {  // LastOrder!= 0 prevent script from making a lot of same sellstop orders
         Ticket = OrderSend (Symbol(), OP_SELLLIMIT, Lotlimit, Bid+(Pips*Point), 3, Bid+(Pips*Point) + (StopLosslimit*Point),Bid+(Pips*Point)-(TakeProfitlimit*Point),NULL, Magic, TimeCurrent() + 3600, Red);
         LastOrder = 0;

if ( Ask<(tun+big_limit*Point) && Ask>(tun+small_limit*Point) &&  tuo!=empty && tdo==empty&& LastOrder != 1  ) {  // LastOrder!= 1 prevent script from making a lot of same buystop orders
         Ticket = OrderSend ( Symbol(), OP_BUYLIMIT, Lotlimit, Ask- (Pips*Point), Slippage, Ask- (Pips*Point)-(StopLosslimit*Point),Ask-(Pips*Point)+(TakeProfitlimit*Point), NULL, Magic, TimeCurrent() + 3600), Green);
         LastOrder = 1; // It prevent script from making a lot of same buy orders
      }


 I use the EA only on M15 PERIOD. I've tried several other expiration time, but i always get sometimes expiration closes. 

 

Any tips ?

 

Cheers

akuh 

 
akuh:

Hi Folks,

 

During backtesting of my EA, frequently the opened Sell-limit and Buy-limit orders get closed due to expiration. I dont know why, since i do have the expiration time defined in the code:


 I use the EA only on M15 PERIOD. I've tried several other expiration time, but i always get sometimes expiration closes.

What are you asking?

If you set an expiration time, why are you surprised when it is activated?

always get sometimes


It is either always or sometimes, it cannot be both.
 
Keith Watford:

What are you asking?

If you set an expiration time, why are you surprised when it is activated?

It is either always or sometimes, it cannot be both.

No thats not what i mean. Lets see the following pictures: Although the order is opened correctly and the price is below the tp-line, the order is not closed. If o choose short expiration times, the order gets closed quickly, otherwise the order is then closed by expiration, until the price reaches the next limit level (price). You can see the problem in the attached pictures:

 

 

 
akuh: No thats not what i mean. Lets see the following pictures: Although the order is opened correctly and the price is below the tp-line, the order is not closed. If o choose short expiration times, the order gets closed quickly, otherwise the order is then closed by expiration, until the price reaches the next limit level (price). You can see the problem in the attached pictures:

Expiration does not close orders. It only deletes pending orders. If the order has been triggered before expiration, it will no longer close due to expiration.

Plus, you have to consider weekends. If the expiration ends after the close of the week, it will only be deleted when the week opens again.

EDIT: Also, you should always check for error 147 (ERR_TRADE_EXPIRATION_DENIED), in case the broker or account does not support expiration.

 
Fernando Carreiro:

Expiration does not close orders. It only deletes pending orders. If the order has been triggered before expiration, it will no longer close due to expiration.

Plus, you have to consider weekends. If the expiration ends after the close of the week, it will only be deleted when the week opens again.

EDIT: Also, you should always check for error 147 (ERR_TRADE_EXPIRATION_DENIED), in case the broker or account does not support expiration.

I do not get error147. It has somehow to do if the price get below the tp-line in the same candle. But i cannot figure out why.
 
akuh:
I do not get error147. It has somehow to do if the price get below the tp-line in the same candle. But i cannot figure out why.
Did you check your broker's Freeze Level conditions?
 
akuh:

No thats not what i mean. Lets see the following pictures: Although the order is opened correctly and the price is below the tp-line, the order is not closed. If o choose short expiration times, the order gets closed quickly, otherwise the order is then closed by expiration, until the price reaches the next limit level (price). You can see the problem in the attached pictures:

 

 

Why do you want a sell limit to be close if the price is below the TP ? You should read and understand how limit orders are working.

To trigger a SL/TP the sell limit should be triggered in first place and become a SELL. 

Trading system and Orders Set in MetaTrader 4
Trading system and Orders Set in MetaTrader 4
  • www.metatrader4.com
The MetaTrader 4 trading system allows traders to implement trading strategies of any complexity. By combining different types of market, pending and stop orders, as well as using a trailing stop, users can perform trades regardless of the current market situation.
 
Alain Verleyen:

Why do you want a sell limit to be close if the price is below the TP ? You should read and understand how limit orders are working.

To trigger a SL/TP the sell limit should be triggered in first place and become a SELL. 

Thats correct. I know what the sell buy limit order is. in my EA the buy/sell limit normally are transformed into SELL or BUY orders but sometimes they just dont. I dont see why.
 
akuh:
Thats correct. I know what the sell buy limit order is. in my EA the buy/sell limit normally are transformed into SELL or BUY orders but sometimes they just dont. I dont see why.

Your topic was about expiration, now you say the problem is "sometimes" limit orders are not triggered. Make your mind please.

I don't see any problem in what you posted. 

Reason: