Hi,
Is there any system variable to retrieve the current number of pending orders?
No, it’s not possible,
But you can easily calculate them yourself, just tally any pending order you place, buy or sellshort, that’s all.
As pending orders are all automatically cancelled each candle, you simply restart tallying them each time.
Hi <span class=”bbp-author-name”>robertogozzi</span>,
Can I append new orders to the existing ones that were created in the last candle instead of cancelling all the orders and recreating after each candle?
ALL pending orders are automatically cancelled each new candle.
If you still need them the next candle you need to place them again.
So, if you place 3 pending orders and want to add 1 more later, then next candle you will have to place 4 pending orders, the prior 3 orders + a new one.
So you do not need to keep a tally to be incremented each time. You simply restart counting from zero each candle, as there are no past orders left pending.
Hi <span class=”bbp-author-name”>robertogozzi</span>
I tested it before on 1 second timeframe, as I have both buy limit and buy stop orders set, during price spikes, sometimes a sell order is sent instead causing me to realize losses. Is this a known issue or bug?
Why a bug?
Pending orders are placed to be triggered when a price is reached.
If it is triggered it’s not a bug, it’s what they have to do.
Returning a loss instead of a profit is not due to being a pending or at market order, but why it has been placed at the wrong time.
Hi <span class=”bbp-author-name”>robertogozzi</span>,
The bug probably lies in the part when the target is set. In IG, you can create an order with target directly but in prorealtime it sends orders without targets. The target is only set when the order is processed.
In my code, there are no stop losses but I have encountered instances when during spikes, the order is triggered and in the next instance, it took a stop loss. So it really puzzles me that it took a loss when my code only sets targets.
I have never experienced such issues. It might be due to GUARANTEED stops or to some LIMITED account types that require a stop loss, but I have no clue.
I suggest asking PRT.
@SimLH
Maybe you can past a part of your code with an exemple on photos where is the problem, if will be better for help you 😊