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.

首页 股票筛选器 外汇筛选器 加密货币筛选器 财经日历 关于 图表功能 价格 推荐朋友 网站规则 帮助中心 网站 & 经纪商解决方案 插件 图表解决方案 轻量图表库 博客 & 新闻 Twitter
概览 个人资料设置 账户和账单 推荐朋友 代币 我的客服工单 帮助中心 私人消息 在线聊天 退出