I'm looking to trade a strategy which has logic similar to the following: For a basket of stocks, lets say 100 stocks, if Price for an individual stock breaks the High of the last 52 weeks, and the last 3 days have all been green candles (e.g. Close[1] > Open[1], Close[2] > Open[2], then go long immediately - without waiting for the full days bar to complete.
To get the high of the last 52weeks I need to use Daily data and I generally choose a date range of the last 18 months. I've got this setup and all working fine - backtests run in ~60 seconds.
The problem I'm facing is running this in real-time. If I choose OnBarClose then I will obviously be delayed in entering a trade until the next day (as the current bar being built that breaks the 52wk High isn't closed until the next day).
If I choose OnPriceChange, then when I'm running the strategy in real-time then suddenly my last 3 days rules that work in backtesting fail in realtime, because Close[1] > Open[1], Close[2] > Open[2] no longer represent days but seconds/minutes as the bars are formed by price changes.
I can't add an additional timeframe of minutes because backtesting and live running both requires 18 months worth of data to be processed, which is fine for daily data but not for minute data.
I'm outlining below what I think is the logical approach to take, but hoping to ask for any thoughts/insights/opinions on whether there is a better way of solving the problem:
*Continue to use Daily data only and OnPriceChange.
*Break my code into 'Real-time' & 'Historical'
*On Historical, on the last full bar store the 52wk high in a double variable, and have a bool true/false variable for whether the prior 3 days have all been green candles.
*On Real-Time, remove any indexed bar references like Open[2] and only check if Close[0] > the 52wk High variable and whether the 3 day green candle bool is true/false
Q1: Do you think this is the optimal approach to take?
Q2: Regarding how to do the real-time vs historical split. I'm imagining kicking this off at say 9.15am each day and worry that some sub-daily bars coming through pre-market for the current day might get confused as historical and mess up the 3 day green candle bool, so do I need to add in a date rule each day in my code to do the 'Real-time' & 'Historical' split (E.g. if (Time[0].ToString("mmddyyyy" == 11252022) //realtime code) to ensure the 3 day green candle bool is captured correctly?
Many thanks in advance for any help or guidance on this.
ChainsawDR
Comment