Download MetaTrader 5

Discussion of article "MQL5 Cookbook: ОСО Orders"

To add comments, please log in or register
Do you have questions on how to turn your idea into reality? Ask them on the Forum!
MetaQuotes Software Corp.
Moderator
181107
MetaQuotes Software Corp. 2015.02.12 16:21 

New article MQL5 Cookbook: ОСО Orders has been published:

Any trader's trading activity involves various mechanisms and interrelationships including relations among orders. This article suggests a solution of OCO orders processing. Standard library classes are extensively involved, as well as new data types are created herein.

This article focuses on dealing with such type of order pair as OCO. This mechanism is implemented in some trading terminals competing with MetaTrader 5. I pursue two aims through the example of creation of an EA with a panel for OCO orders processing. On the one hand, I wish to describe features of the Standard Library, on the other hand I would like to extend a trader's tool set.


1. Essence of OCO Orders

OCO orders (one-cancels-the-other order) represent a pair of two pending orders.

They are connected by mutual cancellation function: if the first one triggers, the second one stays untouched, and vice versa.

Fig. 1 Pair of OCO orders

Fig. 1 Pair of OCO orders

Fig.1 shows a simple order interdependence scheme. It reflects an essential definition: a pair exists for so long as both orders exist. In terms of logic any [one] order of the pair is an essential but not sufficient condition for the pair existence.

Some sources say that the pair must have one limit order and one stop order, moreover orders must have one direction (either buy or sell). To my mind such restriction cannot aid in creation of flexible trading strategies. I suggest that various OCO orders shall be analyzed in the pair, and most importantly we shall try to program this pair.

Author: Dennis Kirichenko

Alain Verleyen
Moderator
30728
Alain Verleyen 2015.02.18 14:34  

Thank you for this interesting article.

  • There is a translation issue in point 1.

They are connected by mutual cancellation function: if the first one triggers, the second one stays untouched, and vice versa.

The second should be removed if the first is triggered, not "untouched".

  • The way to process the deletion of the second order with OnTrade/OnTradeTransaction is not reliable enough. It can happens that the need event is not received at all, or received and not processed :

Besides, transactions can be lost during delivery from the server to the terminal.

and

Transactions queue length comprises 1024 elements. If OnTradeTransaction handles a new transaction for too long, the old ones in the queue may be superseded by the newer ones.

So it's better to add a protection proceedings to avoid big surprise if your second pending order is not removed.

Dennis Kirichenko
11320
Dennis Kirichenko 2015.02.18 15:25  

angevoyageur, thank you for your comments!  You're talking business as always :-)

As for the translation - yes, there's a blunder.

As for the deletion of the untriggered order in the body of the Trade event-handler - yes, the additional checking should be exploited, e.g. in the body of the NewTick event-handler.


theone964
12
theone964 2016.12.21 15:40  

I know this is an old thread but I really want to use this. I downloaded the zip file but I have no idea how to make this work., Some assistance on compiling this would be great.


Thank You

To add comments, please log in or register