LEAN is the open source
algorithmic trading engine powering QuantConnect. Founded in 2013 LEAN has been built by a
global community of 80+ engineers and powers more than a dozen hedge funds today.
Alpha League Competition: $1,000 Weekly Prize Pool
Qualifying Alpha Streams Reentered Weekly Learn
more
I was looking at the Example DailyAlgorithm.cs and trying to apply that to the 4 hour time frame. In the attached project I am not seeing what I would expect in the log statement based on the criteria of the if, I've tried several different properties of the data object but they all seem have the same result.
I also had questions as to the Resolution. of the Security and the SMA indicator - Are these set right to ensure that the SMA6 value is for the close of a 4 hour bar in the OnData method?
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.
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.
It looks like the project never got attached. Remember to include a back test or else it won't work!
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.
Sorry about that, didn't know I had to attach the backtest. Also to elaborate the Log statement seems to execute every minute of the backtest data which is not what I expected, I would have expected to see 0, 4, 8, 12, 16, 20....... when the Hour is logged out, not just repeated 0. Not sure what I am doing wrong here.
Also on a different note all together could you tell me what the ? in the below declaration means
decimal? last = null;
I saw this in DisplacedMovingAverageRibbon.cs but could not find what it means in the C# documentation.
It looks like there's a few issues here. First, the 'Date' property will always have a TimeOfDay = 0, since it's the date portion of the DateTime. Secondly, it looks like the logic for detecting 4 hour marks wasn't correct.
I've attached an updated version of your code that will fire each day at 12pm and 4pm for equities.
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.
Not sure if you or Michael can help on this one but the last question I had in this thread was about the Resolution value for the Equity/Instrument and Indicators. To use this in a 4 hour time frame would Resolution.Hour be the right value or would I have do so something custom to make this work properly?
Greg, here's some documentation on nullable types.
As for your 4 hour time frame, what exactly are you trying to do? Are you trying to have indicators based on 4 hour data? Are you trying to make decisions every 4 hours? Is this 4 trading hours or 4 rounded clock hours (8/12/16)?
If you're looking to have indicators defined on the 4 hour interval, I would recommend usage of a consolidator. Consolidators allow you to 'consolidate' higher resolution bars into lower resolution bars (hours -> 4 hour bars).
I've attached an example of consolidating some SPY hourly data into 4 hour bars. Each day you'll receive data at noon and at 4pm.
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.
Thanks Michael, I will have a look at his code, I appreciate your putting it together for me.
I lean towards trading spot forex which is a 24 hour market starting Sunday night through Friday afternoon EST. I found a 4 SMA trading system on the internet that uses a 4 hour time frame (so in specific answer to your questions trying to have indicators based on the close price of a 4 hour bar to make trading decisions based on those indicators each 4 hour period for all the time the market is open) - I don think it will make any money but I thought it was a good place to start so I can learn more about the QuantConnect LEAN apis and how to build, optimize and measure strategies. I am also interested in ETF's as well but I dont have much experience trading those.
When using the RegisterIndicator method of the QCAlgorithm.Indicators.cs as shown in the example you attached in a local copy of the LEAN project (pulled from git this morning), the code throws an error due to ambiguity. Looks like a couple of the method signature allows a null value in the last (4th) argument but it can be of different types (decimal or T)
Hey sorry Greg for the very delayed response, somehow this slipped past me. The value 'x => null' I wouldn't expect to work. You could just pass 'null' and then we'll default to 'x => x.Value' which is the closing price of the bar.
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.
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...
To unlock posting to the community forums please complete at least 30% of Boot Camp. You can
continue your Boot Camp training progress from the
terminal. We hope to see you in the community soon!
You do not have enough QC Credit to send this award, get a QC Credit Pack
here.
Award Sent Successfully
Thank you for giving back to the community.
Processing...
Choose a Credit Pack
Payment Confirmation
QuantConnect Credit (QCC) can be applied to your cloud-invoices or
gifted to others in the community with Community Awards in recognition of their contributions.
Community Awards highlight the awesome work your fellow community members are doing and inspires
high quality algorithm contributions to the community. Select an option below to add
QuantConnect Credit to your account:
$5
500 Credit Points
 
$10
1,000 Credit Points
 
$18
2,000 Credit Points
10% bonus
$45
5,000 Credit Points
10% bonus
03/23XXXX XXXX XXXX 0592
We will charge your default organization credit card on file, click
here to update.