Back

Using different value for the Indicator

Hi,

I would like to use the change value of the current day in my Indicator.
My custom Data class derives from TradeBar and I added the Change decimal property.

So lets say I would like to use it in an indicator instead of the default Value(Close price).
How can I do it? I get Errors when Casting it.

Here you can see the Fun<IBaseData, decimal> selector

public SimpleMovingAverage SMA(Symbol symbol, int period, Resolution? resolution = null, Func<IBaseData, decimal> selector = null)
{
var name = CreateIndicatorName(symbol, $"SMA({period})", resolution);
var simpleMovingAverage = new SimpleMovingAverage(name, period);
RegisterIndicator(symbol, simpleMovingAverage, resolution, selector);

if (EnableAutomaticIndicatorWarmUp)
{
WarmUpIndicator(symbol, simpleMovingAverage, resolution);
}

return simpleMovingAverage;
}

I have this class (with some reader and more stuff which I don't mention here)

public class LocalData : TradeBar
{
public decimal Change;
}

I did something like this in the algorithm which didn't work

sma = SMA(Ticker, 10, Resolution.Daily, selector: TestMethod);

decimal GetEntry(IBaseData data)
{
return ((LocalData)data).Change;
}

Can someone tell me how I can do this correctly please?

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.


Hi Amir,

Please attach a backtest for what you would like to do.

For now, you could try the following: create a SimpleMovingAverage object instead of an SMA object and manually update our SimpleMovingAverage object with the change value in OnData. Please see the Manual Update section in Custom Period Indicators on how to do this.

Best,
Shile Wen

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.


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