Backtesting on 1hr chart but exiting intrabar


Category:
0
0

Hello. Great resources here. However, I couldn’t find a solution for my issue: I built a strategy for backtesting based on a 1hour chart. I need to exit trades within the 1hr candle (intrabar/ on 5min candles for instance). Otherwise, the stop might get triggered intrabar but the strategy exits the trade on the open of the following hour. Is this even possible?

Thanks guys.

Marked as spam
Posted by (Questions: 3, Answers: 7)
Asked on December 13, 2020 1:34 pm
135 views
0
To clarify: What I\’m looking for: The signals should be created based on 1 hour candles. Entries on the open of the following candle. But exiting if stop gets hit intrabar. The way I have it now is that the strategy recognizes the low and high of an 1hr candle and closes the position on the following 1hr candle based on the low / high of the previous candle. But this is not realistic since the previous bar might rally / dump but no exit is triggered. Then, when the exit gets triggered (based on a simple stop-loss) it calculates Entry-price minus stop. If the previous bar then rejects and the following bar isn\’t below the stop, the trade is still active. That creates on backtesting many winning trades when they actually should have been stopped out. I hope that makes sense. That’s my current exit code: def stop = EntryPrice() – StopLoss; AddOrder(OrderType.SELL_TO_CLOSE, close[-1] <= stop, price = stop, tickcolor = Color.GRAY, arrowcolor = Color.GRAY, name = "Stop", tradeSize = contracts);
( at December 13, 2020 1:46 pm)
0
Private answer

Chart strategies and studies are only able to look to higher time frames. They cannot look to lower time frames. So whatever is the lowest time frame from which you need the strategy to act, that is the time frame you need to apply to the chart. In this case it would be the 5 min time frame for your chart. Then you need to write your code to reference the higher time frame to get the data from the 1 hour candles.

Writing chart strategies that reference higher time frames (or multiple higher time frames) is beyond the ability of most novice programmers. So unless you have been writing code as your full time profession for 5 or more years you should not be trying to mix time frames in a chart strategy.

The following video will demonstrate the main issue that must be accounted for when building MTF chart strategies for back-testing:

https://www.hahn-tech.com/thinkorswim-strategy-guide-mtf/

 

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on December 13, 2020 1:57 pm