For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
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?
-
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[0] and MSFT would be datas[1].
Calculate a moving average crossover indicator in the
init
or a custom indicator class on the datas[0] 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.datas[1]
to trade MSFT -