Discussing the article: "Market Simulation: Position View (XIII)"

 

Check out the new article: Market Simulation: Position View (XIII).

In this article, we will look at how to easily implement an indicator that shows whether a position is generating a profit or a loss. The procedure is simple and effective. Even without in-depth expertise, this indicator will allow you to easily recognize when to close a position. This way, you will avoid unexpected results, since the calculation reflects the actual outcome you would get if you closed the position.

Before removing the C_IndicatorPosition class from the final code, we should explain the reason. We want to remove the intermediate layer between the indicator and the C_ElementsTrade class. You might be wondering why we are changing the architecture right now. It is quite simple. Up to this point, the behavior of the position indicator had not yet been fully defined. We temporarily kept the C_IndicatorPosition class as a separation layer to isolate the implementation from potential failures or drastic changes, as shown in the following image.

In the previous diagram, the black line represents the connection between the indicator and the C_IndicatorPosition class. This class branches into three lines: red, blue, and green, which correspond to the components to be displayed on the chart: stop-loss, opening price, and take-profit, respectively. Although this structure has been useful so far, it will become a limitation in the next phase. Therefore, we will remove the C_IndicatorPosition class from the project and incorporate the methods and member variables currently defined by that class into the indicator, as shown below.


Author: Daniel Jose