Discussing the article: "Market Simulation (Part 05): Creating the C_Orders Class (II)"

 

Check out the new article: Market Simulation (Part 05): Creating the C_Orders Class (II).

In this article, I will explain how Chart Trade, together with the Expert Advisor, will process a request to close all of the users' open positions. This may sound simple, but there are a few complications that you need to know how to manage.

In the previous article, Market Simulation (Part 04): Starting the C_Orders Class (I), I was primarily focused on explaining how the code for sending market trade orders would look. The entire explanation aimed to demonstrate how you could structure the class code in order to decode the information received from the Chart Trade indicator.

However, even without having seeing the source code of the Expert Advisor, I believe that those with some experience could already implement it in practice. And even though it might seem that the code shown in the previous article would not be capable of executing operations on a live trading server, that is not entirely true. It is true, though, that the code would not be sufficient for use with HEDGING accounts.

For NETTING accounts, that code would already be able to open and close positions. But for HEDGING-type accounts, things work a little differently.

If you attempt to close a buy position using the sell button, for example, you would actually be opening a sell position. This applies to HEDGING accounts. In a NETTING account, performing the same action would close the buy position, or at the very least, would produce some kind of effect, such as:

  • A position reversal (flip). This would occur if you sold a larger volume than your existing buy position. In this case, you would move from being long to being short. The size of the new short position would be the difference between the volume of the previous buy position and the volume sold in the reversal.
  • Partial closing. This would occur if the volume sold was smaller than the existing buy position. In that case, part of the buy volume would be closed, leaving the remaining portion still open in the market.


Author: Daniel Jose

 
You explained it completely and I will use it.