Back

Help with indicator coding

I'm developing an indicator that is either greater than 0, or less than 0. I'm using a universe selection, and not picking single stocks to trade. how can i set this up in OnData()?

pseudocode:

if indicator <= 0
    if not paused, pause trading
    if invested, liquidate
    return

if indicator > 0
     if paused, resume trading
 

Thanks!

   

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.


Does this code allow me to keep my universe of symbols, but still move in and out of positions? ie When I liquidate, do the symbols from SetUniverseSelection remain in Portfolio object even if I'm not invested?

This code seems to suggest that. I'm just trying to understand the different objects.

var holdings = Portfolio[symbol];

if (!holdings.Invested)
{
MarketOrder(symbol, 10);
}
else
{
MarketOrder(symbol, -holdings.Quantity);
}

 

0

Hi Tim,

Could you please specify how do you want to combine the indicator and universe for your strategy? We can provide a better help if you could clarify your strategy and functions, or attach your backtesting code below. Here is an example strategy of using a combination of indicator and universe, which might help.

For second question. The Portfolio property is only the collection of SecurityHolding objects for accessing to the holding properties. Universes are stored in the IDictionary<string, Universe> UniverseManager. If you would like to keep or access your universe of symbols, We can loop through the dictionary entries to keep or access symbols in your universe. Here is the forum discussion for how to get symbols in universe.

Thanks 

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 looked over the provided examples, but I'm still trying to figure out where to do this. If my alpha is emitting positive insights as long as my indicator is positive and negative insights as long as my indicator is negative, I want to do:

(in onData?)
   if alpha is positive
       if not invested, invest at target percentage (stay long, don't keep buying)
  if alpha is negative
     if invested, liquidate symbol, don't remove from universe and don't go short

Is QCAlgorithm::OnData the handler for insights? According to the Framework model, I should be handling orders in my execution model. Is there a model already setup that will do the above logic?

 

0

Hi Tim, yes most of that is handled in the modules provided. Your primary job is to create the signals in the alpha model, and then I suggest the other modules we supply should be enough. If your strategy is literally that simple above you don't need the framework. 

First please read the Framework documentation thoroughly. Its a fairly abstract series of concepts so it might be hard to grasp. If not clear I'd recommend the book, "Inside the Black Box".

This is a good example of a custom alpha model with stock other models. 

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'm not sure what's wrong. Jared, can I send you my backtest link and have you take a look?

The model is doing 10000 trades in one day and failing out/stopping. I would rather not post here at this time, as this is an idea for the competition, and not sure I'm coding it right.

0

disregard. I'm going in a different direction for now.

0

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