MyTradeEvent

MyTradeEvent
public event Action<MyTrade> MyTradeEvent;

The MyTradeEvent event indicates the receipt of a new own trade, which is described in the program by the MyTrade class. Accordingly, the method set as the event handler should accept an instance of this class, and also should not have a return value.

Imagine a scenario where a trading bot needs to accumulate a large volume incrementally upon meeting certain conditions, then shed a portion before accumulating again, and so on. We want to limit the maximum volume for the algorithm and prohibit purchases upon reaching a set threshold.

Instead of calculating the total open volume for all positions after each trade, it would be far more productive to aggregate this information directly.

1. Subscribe to the MyTradeEvent in the constructor.

2. Create a decimal variable that will contain the current volume of purchases.

3. In the event handler for your own trade, increase the value of the variable if it is a purchase.

4. Otherwise, decrease the value of the variable, as this is a sale.

5. Before executing the logic to open positions, check the value of the variable. If the current volume is less than the set threshold, the trading logic is executed; otherwise, the opening of new positions is prohibited.

If you have any difficulties or questions, please write to the support chat. Link