Dear All KDB+ guru,
Hope everything great for you so far this week.
I had little but complete experiences on writting backtesting strategy based on 1minute or 2minute candlestick bar. All these strategies creates entry, and exit signal based on closeprice of candlestick bar. Which means that we ignore high, low and open price. The strategy logic make decision once the 1min or 2min completes. For example, we are on the n_th bar, now, the n_bar just completes, and creates a long signal, then we record a long trade on the open price of n+1_the bar.
Now we have a little bit more complicated strategy, for example, we still make decision based on previous n bar high, low, close price. It is no problem for me now. But the signal does not make us to trade on the open price of n+1_the bar. Instead, previous n bars create a price level, fro example, 50 to long, and now the close price of n_th bar is 49, therefore, if in the next coming n+1_the bar, the price reach the 50 level, we make a long, and once we made this long, we create a 49.5 stoploss order and to check whether the price will come down and we close the position. As you can see, in the n+1_bar, we need to get into the bar to see how price really develops. For example, if the price goes up from 49 to 50, we make a long, and price never retreat within n+1_the bar, then after n+1_the bar, we hold 1 long position. For another example, if the price reach the 50, we make a long, then retreat to 49.5, therefore we have to close this long position, then even the price goes up later, we do not make any more trade and we have 0 position after this n+1_th bar. As you can see, we could not judge about the trading details within n+1_the bar if we do not get into the tick price history of this bar.
My question, how to backtesting this trade-within-bar strategy? What is the best routine?
My unmature idea:
-
create all signal with level of price for the next bar.
-
scan? or loop through the next bar tick price to decide what really happened within the next bar?
I just have no idea…
Thank you very much in advance.
Sincerely,
Wenhao