My strategy processes orders one candle after the condition has been met

 

By default, a strategy is calculated once per bar, on the bar close. During that calculation, the strategy is able to generate new orders or update existing ones. But when the bar has already closed, it cannot be traded anymore, so the earliest moment that a strategy order can be filled is at the open of the next bar. Because of this, by default, the strategy will open a position one bar after the entry condition has been met.

That behavior can be changed with the process_orders_on_close argument. This allows the strategy to fill orders on the close of the bar. To do this, a process_orders_on_close argument should be added to the strategy() function declaration and set to true, like this:

//@version=4 
strategy(..., process_orders_on_close=true, ...)

This is how strategy works without the process_orders_on_close argument:

//@version=4
strategy("process_orders_on_close example")
strategy.entry("EN", strategy.long, when = bar_index == 20650)
strategy.close("EN", when = bar_index == 20655)

This is how strategy works with the process_orders_on_close argument:

//@version=4
strategy("process_orders_on_close example", process_orders_on_close = true)
strategy.entry("EN", strategy.long, when = bar_index == 20650)
strategy.close("EN", when = bar_index == 20655)


The entry EN is tied to a condition that will be true at the bar 20650, but the actual entry occurs one bar after that, at bar 20651. The same happens with its close: the condition is true at bar 20655, but the entry is only closed on the next bar. By adding the process_orders_on_close argument and setting it to true, the strategy can now fill orders on the close of the bars, so the market order EN now fills one bar sooner.

Home Stock Screener Forex Screener Crypto Screener Economic Calendar About Chart Features Pricing Refer a friend House Rules Help Center Website & Broker Solutions Widgets Charting Solutions Lightweight Charting Library Blog & News Twitter
Profile Profile Settings Account and Billing Referred friends Coins My Support Tickets Help Center Private Messages Chat Sign Out