What is the code to enter a trade when a condition is met instead of next candle open?
What I am trying to do is once it has passed my condition say yesterdays close to open a position immediately and not wait until the open of the next candle?
Trades are ALWAYS opened immediately, unless you delay them with pending orders.
Strategies are executed when a candle closes and, if conditions are met, a trade is immediately entered in the new just opening candle.
Conditions cannot be evaluated while a candle is forming.
Multiple Time Frame, MTF, support just added for demo trading, did not change this behaviour, but it allows to combine higher and lower TFs so that you can evaluate conditions and eventually enter earlier, but still when the candle in the lower TF closes.
Thank you Robert for your reply.
That seems silly. If say I want to buy once the price has past yesterdays high, I dont want to wait for the candle to close and start a new one. So the only way I can do this is manually? For an example – lets say I have a 4hr bar and I want to go long once the high of the previous bar has been passed are you saying I cannot do this and it will only enter a trade once the next 4 hour bar has opened? meanwhile the breakout has already happened and left my entry on the next candle which just might be a retrace and get stopped out.
You can certainly do that using pending orders.
You can write:
BUY 1 CONTRACT AT HIGH STOP //buy when current HIGH is reached
BUY 1 CONTRACT AT HIGH[1] STOP //buy when previous HIGH is reached
Bear in mind that pending orders expire when each bar closes and you need to enter them again if conditions are still met.
But, to go back to your question, even the decision to enter a pending order must be made when a bar closes, not while a bar is being formed.
That’s not a big problem, we normally make decisions after some event, say MA crossovers or the like, are confirmed at the closure of a bar.
Does that mean I can write a code to use in auto trader and also back test it?
Yes, you can!
You should backtest them always in tick-by-tick mode.
ProOrder will be aware of them only when the bar closes and by then more than one pending order could be triggered, regardless of how you set DEFPARAM CUMULATEORDERS, say you set two orders, one triggered when thr price reaches the previous high and another one when it reaches the previous low. They might be both triggered before the candle closes, you need to know that!
You can find examples here:
https://www.prorealcode.com/topic/setting-a-pending-order-while-on-market/#post-25881
https://www.prorealcode.com/topic/hedging-strategy/#post-33807
https://www.prorealcode.com/prorealtime-trading-strategies/breakout-range-ts/
https://www.prorealcode.com/topic/number-of-open-positions/#post-29473
You can also read documentation about Stop/Limit orders.
Looks like I have more reading to do.
My strategy is based on a 4hr bar and can only enter on the next bar. If an entry is triggered it must be closed by close of bar unless profit or loss reached. If no entry I wait until the next days time frame when the 4 hr bar is completed and the system starts again. Entry is based on prior high or low or open. May consider trend filter yo stop trades entering for no good reason