Trade a stock using a moving average crossover of a different stock
I just installed backtrader (thanks, developers) and ran the example that trades MSFT using a moving average crossover of MSFT. How do you test a strategy that trades MSFT using the moving average crossover of another symbol, for example QQQ?
run-out last edited by
This is no problem. First you need to enter two symbols, QQQ and MSFT. You'll need to know the order entered. I like to put the signal first, so QQQ would be datas and MSFT would be datas.
Calculate a moving average crossover indicator in the
initor a custom indicator class on the datas line which is QQQ in this example.
Then in next you can use the moving average crossover indicator to trigger your buy, but then use
self.datasto trade MSFT