Back

How to include more than 1 symbol in the algo?

I would like to test my algo on a basket of 5 symbols but do not know how to.
Must I create an array variable or something similar?
Update Backtest








If you'd like to add more than one symbol, you'll need multiple calls to the 'AddSecurity' method. This can be accomplished using an array/list and a loop, or just with 5 individual calls: // with a list
var symbols = new List{"SPY","AAPL","GOOG","MSFT","IBM"};
foreach (var symbol in symbols)
{
AddSecurity(SecurityType.Equity, symbol);
}

// with individual calls:
AddSecurity(SecurityType.Equity, "SPY");
AddSecurity(SecurityType.Equity, "AAPL");
AddSecurity(SecurityType.Equity, "GOOG");
AddSecurity(SecurityType.Equity, "MSFT");
AddSecurity(SecurityType.Equity, "ABM");


I tend to prefer the list style, it makes it easier to add/remove symbols.
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.


How do I use the list style with the RegisterIndicator method; I do not know what to put in for the "symbol" parameter slot in the call syntax.
0

RegisterIndicator only accepts single symbols. Please attach a backtest/project so I can be of more help. There are numerous examples in the forums and the QC University showing usages of the RegisterIndicator method.

Also, it's hard to help without knowing what you're trying to accomplish. Are you trying to create indicators for each symbol in your list? A foreach loop may be your friend here :)
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.


I am trying to create a MovingAverage based strategy that runs on MovingAverage based criteria (e.g. if "10 EMA crosses above 20 EMA" buy). Within the entry criteria also exists "lookback" conditions where I use rollingwindow histories to check things such as "Has the 10 EMA been above the 20 EMA for 3 bars or longer?"

A foreach loop to create and register indicators for each symbol in my list would most definitely be my friend.
0

Do you have an algorithm that you could attach and share? I could help more if you share :)
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.


Is there a way to privately share algorithms? If not, I can share a necessary altered portion of my code.
0

Please share a subset of the code that demonstrates where you're having difficulty. It's much easier for myself and community members to help if we have code to look at :)
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.


Here you go:

If you could demonstrate to me how to make this algorithm functionally intact while multi-symbol, I would be very grateful. If you could also adjust the position management using holdings or whatever necessary to achieve the goal of proper entry / exit / sizing (no more than 20% of capital put into one trade, no more than one position of maximum 20% capital allocation in each symbol) I would be evermore grateful.

Thanks in advance.

EDIT: how unfortunate that I accidentally uploaded the full algorithm by accident. Oh well.
0


Edit: it is also the wrong algorithm in the sense that this version doesn't have the "symbols" foreach loop you demonstrated, my apologies
0

Hey @Nicholas, apologies on the delay on this one, was on vacation in California :)

Here's something I threw together that demonstrates the technique I would use. The algo you shared seemed a little too complicated for an example.

Also have a peak at this example algo on another thread. Also have a read through the various example algorithms available in github.
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