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.

홈으로 스탁 스크리너 포렉스 스크리너 크립토 스크리너 이코노믹 캘린더 정보 차트 특징 프라이싱 프렌드 리퍼하기 하우스룰(내부규정) 헬프 센터 웹사이트 & 브로커 솔루션 위젯 차팅 솔루션 라이트웨이트 차팅 라이브러리 블로그 & 뉴스 트위터
프로화일 프로화일설정 계정 및 빌링 리퍼드 프렌즈 코인 나의 서포트 티켓 헬프 센터 비밀메시지 채팅 로그아웃