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.

Laman Utama Penyaring Saham Penyaring Forex Penyaring Kripto Kalendar Ekonomi Mengenai Ciri-ciri Carta Harga Rujuk rakan Peraturan Dalaman Pusat Bantuan Laman web dan Penyelesaian Broker Widget Penyelesaian Pencartaan Perpustakaan Pencartaan yang Ringan Blog & Berita Twitter
Profil Tetapan Profil Akaun dan Pengebilan Kawan-kawan yang dirujuk Coin Tiket Sokongan Saya Pusat Bantuan Mesej Peribadi Sembang Daftar Keluar