Back

Trying to exclude overnight data to create SMA from intraday data

Trying to create SMA-40 from intraday 5-min data. The data includes extended hours. I would like SMA-40 to be formed from yesterday's and today's regular sessions' data, excluding overnight hours. So far, I have been unsuccessful not to include hours from 16:00 pm to 9:30 am.

See my code. I would appreciate any advice.

Update Backtest








I found a solution to the above problem. I created another class for my data and excluded the overnight hours by the following code inside of BaseDate Reader:

if (cmBar.Time.TimeOfDay < new TimeSpan(9, 30, 00) ||
cmBar.Time.TimeOfDay > new TimeSpan(16, 10, 00))
{
return null;
}

Now I have 2 classes that hold the data: 1st - original, 24hrs data; and 2nd - data excluding overnight hours. After that, I had to create another OnData method, that passed the data from newly created class, specifically for SMA.

See the algorithm.

1


I am new to this, so don't know the anwers. However, As a C# dev i suggest you start use variables for readability. It also prevents you to make errors.

var a = BarHistory[0];
var b = BarHistory[1];

if (a.RealBody > (decimal)0.75 && a.Close < a[0].Open && a.Volume > b.Volume &&
0

Anne

Thank you for your great and timely advice. I just began thinking how cumbersome my algorithms are beginning to look.  Even to myself, and I wrote them. Readability is definitely very important .

1

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