Back

Issue with custom indicator - Rolling window is empty

Hi guys,

I am trying to create my first custom indicator aiming at detecting W Bottom patterns. I have spent quite some time going through the doc and various posts on the forum and tried many different things, but I am stuck with the coding part (I have no prior coding experience before starting using QuantConnect). At this stage I just would like to be able to retrieve the data I need within my custom indicator class to perform my analysis, the usefulness of the indicator itself doesn’t matter.

The issue I am currently having is that I don’t know how to feed in the data to the rolling window I created in a custom class within the custom indicator class. Please see backtest attached (you need to uncomment lines 32, 33 and 43 in Main.cs and line 23 in SymbolData.cs to get the error, otherwise I could not upload the backtest). I may also have got everything wrong in the way I tried to structure the code.

Any help would be greatly appreciated.

Cheers

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.


Hey Pi R,

I reorganized your code so that the indicators, consolidators and rolling windows are defined within your SymbolData class. The event handler for your consolidator will automatically update the rolling window with the latest bar data. In general, you should try to include all data related to a symbol within the SymbolData class.

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.


Hi Rahul,

 

Thank you very much, that is super useful feedback! I will need to do a bit of reading to understand the use of passing "CAlgorithm algorithm" as an argument to the SymbolData class, but I can see this is a much cleaner way of organising the code and I will aim at reorganising my algo like that.

 

I don't get the "Rolling window is empty" error message anymore, but it seems like I still can't retrieve the values from my custom W_Bottom indicator. I have added a debug function to track some values (line 52 in Main.cs) and it only returns zeros. Can you help with that by any chance?

0


Hey Pi. R,

Your custom indicator isn't returning values because you aren't updating it with data. We can update the WBottom indicator in the consolidator event handler.

 

Consolidator.DataConsolidated += (sender, baseData) =>
{
// '_bar' here is our newly consolidated data
var _bar = (IBaseDataBar)baseData;
// Update the indicators
ConsolidatorFlag = true;
BarsWin.Add(_bar);
W_Bottom.Update(_bar);
};


We also need to add the bars to the rolling window WBottomClass and wait until the window is ready before we make any calculations.

 

protected override decimal ComputeNextValue(IBaseDataBar input)
{
wBottom.BarsWin.Add(input);
if(!wBottom.BarsWin.IsReady){
return wBottomFlag;
}
......
}


This lets you update your WBottom indicator with data from your algorithm. However, there is still some faulty logic in the way you calculate your WBottom values in this line.

 

wBottom.A_High01value = wBottom.BarsWin[wBottom.B_Low01index +1].High;


The index for BarsWin is out of bounds. I changed the end of the following loop from wBottom.Period -1 to wBottom.Period - 2 to prevent
wBottom.B_Low01index + 1
from going out of bounds.

 

for(int i = wBottom.B_Low01index; i <= wBottom._Period - 2 ; i++)
{
decimal number = wBottom.BarsWin[i].Low;
if(number < wBottom.B_Low01value)
{
wBottom.B_Low01value = number;
wBottom.B_Low01index = i;
}
}

 

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.


Hi Rahul,

Thank you very much for all your help, this is awsome. I now have a template I can play with to try to identify patterns. It is opening a lot of posibilities :)

 

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