Back

Trading Minute on Daily Indicators

Assume a security with last 2 days closing [10, 12]. If my strategy is to trade when price is above 2 day SMA (daily close).

On  3rd day:
before market opens 2d SMA is (10+12)/2 = 11.
After market opens, first minute, price is 11. The running 2d SMA should be (12+11)/2 = 11.5.
second minute, price is 11.5. The running 2d SMA should be (12+11.5)/2 = 11.75.

Now this is very simple case and I could do this manually. But thigs could go complicated. For example, what is I need to consider RSI instead.

What's the most simple/ elegent way to get indicator values based on a different resolution than ticker data, but updated live to consider last available price?

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.


public override void Initialize()
{
//...
AddSecurity(SecurityType.Equity, symbol, Resolution.Minute);
_sma = SMA(symbol, 2, Resolution.Daily);
//...
}
public override void OnData(Slice data)
{
//...
_sma.Update(Time.Date, data.Bars["SPY"].Close);
//...
}

One approach I found is to use call Update function on indicator. I supplied only date part and closing price of the Slice. Not sure if this is the right approach though.

0

Hi Mukesh Chakravarti ,

When the algorithm creates an indicator with a helper method, it is automatically updated by the engine with the required resolution. No need to use the Update method, just this:

_smaDaily = SMA(symbol, 2, Resolution.Daily);
_smaHour = SMA(symbol, 2, Resolution.Hour);
_smaMinute = SMA(symbol, 2, Resolution.Minute);

 

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 knew that Alexandre. If the data resolution is minute and indicator rsolution is daily, indicator gets update once per day. Which might be right behaviour in many cases but not something I am looking at. The indicators should use the latest price data available at that point in time.

If I am trading on 200 days SMA crossover, and the price moved significantly intraday, the daily indicator will still be showing the SMA based on yesterday close. 

I wanted the minute data to be reflected in the daily indicator calculation.

1

Hi Mukesh Chakravarti ,

Sorry about the wait.

In order to achieve that behavior, you will have to create a custom indicator, since Lean indicators were not designed to recalculate its last value until the resolution frontier is crossed.

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