Back

MultipleSymbolConsolidationAlgorithm

I am trying to add multiple time consolidators to the multiple symbol consolidation algorithm. I want to use both 5 and 15 minute time frames. The problem is the algorithm is only trading the last symbol in the equity list but Im not sure where the problem is. Any help would be appriciated. 

Update Backtest








0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


for symbol in self.Data.keys():
symbolData = self.Data[symbol]

you loop through and safe only the last one? maybe its this line
0

Hi Eric,

Looks like Michael found the right spot. Given the way the for-loops in the OnData section are currently written, the algorithm will only trade the last equity in the list. Instead, if I understand the general idea of the code correctly, the algorithm should evaluate the trade logic inside the for-loop rather than outside of it. Take a look at the code snippet below and this should solve the problem.
 

def OnData(self,data):
# Loop through symbols. Since symbols are ordered for both dictionaries,
# 'symbol' with properly access both self.Data and self.Data15
for symbol in self.Data.keys():
symbolData = self.Data[symbol]
symbolData15 = self.Data15[symbol]

## Keep trade logic inside for-loop to enrue all assets are traded
if not self.Portfolio[symbol].Invested and
symbolData15.MACD15.Current.Value > symbolData15.MACD15.Signal.Current.Value and
symbolData.MACD.Current.Value > 0 :

self.SetHoldings(symbol, self.PositionSize)

if self.Portfolio[symbol].Invested and symbolData.MACD.Current.Value < 0 :
self.Liquidate(symbol)
1

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed