Hi there edktrading – I will try to rephrase Roberto’s response;
What you want is simply not possible.
Your code is called at the end of each bar. This is thus at the points in time of your blue and green balls respectively. Thus, your code is called when the bar with those balls is formed. These will also be the bars in which you detect the double bottom or double top. And what happens next is : your code detected the double bottom/top, decided to buy on that signal and … had to wait for 15 minutes (TimeFrame of the chart is e.g. 15 minutes) in order to hand the order to the broker.
you will see an arrow on the next candle as it’s impossible to enter at a prior time (as you will not be able to do manually).
This is not entirely explaining what is possible and what is not possible;
Manually : If I see a double top emerging, then I know before the last bar closes (that is the bar prior to the balls) that this is so. I can place a Market order right before the bar ends or else I can place the order quickly when the new bar started. In both case this will do what edktrading wants to accomplish. If I want, I can of course place a pending (Limit or Stop) order just the same – it’s about the idea of “immediately” placing an order.
Automatically : This can never work because the situation (double bottom/top) can only be detected in that bar of the ball and next has to wait for handing the order to the broker only when that bar ends. This part is exactly how Roberto poses it.
pending orders are EXECUTED when a bar closes
This could be confusing, because pending orders are given to the broker or are least are handed to the higher level system when the bar closes. If anything is “executed” it is the forming of position at the Exchange. But this could be vague to all of us, so why the “executed” in capitals I don’t understand (read : I probably miss the point).
The moral of course is that a pending order too, is given to the (virtual) broker system, again at the end of the bar (and yes, it cancels itself at the end of the next bar, unless the order has been filled underway (we might call this Excuted ? – so vague and confusing).
You could resort to MTF (Multiple Time Frames) support, to use a lower TF, but this won’t help you much in this case, unless you want to consider a DOUBLE BOTTOM when that price level is hit without waiting for it to be confirmed at the closing.
Apologies for all the “rephrasing”, but I don’t see why this would not work; The confirmation of the closing occurs at the higher level TimeFrame (like 15 minutes) and the buy could occur at the lower level (like 1 minute). You are still 1 minute later than you’d achieve manually, but it is better than 15 minutes late.
N.b.: Resort to 1 second for the lower level is also possible, but not advisable due to relatively long Backtesting times plus way shorter Backtest periods.