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.

Trang chủ Bộ lọc cổ phiếu Bộ lọc Forex Bộ lọc Tiền điện tử Lịch kinh tế Giới thiệu Tính năng Biểu đồ Trả phí Giới thiệu bạn Quy tắc Áp dụng Trung tâm Trợ giúp Giải pháp cho Website & Nhà môi giới Widget Giải pháp biểu đồ Thư viện Biểu đồ Lightweight Blog & Tin tức Twitter
Hồ sơ Tùy chỉnh Hồ sơ Tài khoản và Thanh toán Giới thiệu bạn Xu Ticket Hỗ trợ của tôi Trung tâm Trợ giúp Tin nhắn riêng Trò chuyện Đăng xuất