Back

Rolling window from a subroutine

Is there an easy way to use the rolling window of an indicator while in a subroutine called by the OnData()? Do we pass the tradebars data to the subroutine?

 

Thanks,

Update Backtest








Could you please illustrate your question with an algorithm (use attach backtest feature)?
It is a good practice that helps the community a lot.

If we are using a indicator method helper that updates the indicator, we don't need to pass tradebars. If we are not, one option would be passing the tradebars from OnData into a subroutine.

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 is an attempt to use the tradebars/rolling window in my subroutines.  I have something not quite correct although since no trades are taken.

0


At first sight, I understand that you try to update the mp and cc RollingWindow like this.

mp[0] = Portfolio[symbol].IsLong ? 1 : Portfolio[symbol].IsShort ? -1 : 0;
cc[0] = Portfolio[symbol].Quantity;

but the right way to do it is

mp.Add(Portfolio[symbol].IsLong ? 1 : Portfolio[symbol].IsShort ? -1 : 0);
cc.Add(Portfolio[symbol].Quantity);

But even with that fix, the strategy doesn't trade. Have you chack the trading logic implementation?

 

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.


Thanks,  I am going to go over my logic with debug and make sure I am updating the vars as expected.

0

ok, I found the problem.  The rolling window should be visible to the functions and subroutines as long as the data history is updated from OnData();

 

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