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'm new to QC. I would like to automate some of my daytrading setups. I have briefly read all the documentation, but did not see any clear discussions on picking a symbol set before the open.
For example if I want create an algo that would do the following:
1. at 9:20AM pre-market, find symbols (equity) that are over $1 and under $10, where the last price at 9:20AM is > 20% from previous days closing price.
2. volume at 9:20AM must be > 200k
3. Get the highest high between yesterday's close and 9:20AM (pre-market high)
4. After the market opens go long on break of PM high.
How would i go about doing that.
Is there a sample algo already written that does something similar to this?
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.
Alexandre Catarino
100.6k
,
Since your algorithm creates an universe of symbols that fall under some criteria, you should start developing a Universe Selection algorithm. In the Coarse Universe, we have price and volume information, the ingredients for your selection. However, since you need the previous close, please save it in a dictionary:
private Dictionary<Symbol, decimal> _prevClose;
// In Initialize
AddUniverse(coarse => {
var symbols = (from c in coarse
where _prevClose.ContainsKey(c.Symbol)
where c.Price > _prevClose[c.Symbol] * 1.2
where c.Price > 1
where c.Price < 10
where c.DollarVolume > 200000
orderby c.DollarVolume descending
select c.Symbol).Take(50);
foreach (var c in coarse)
{
if (_prevClose.ContainsKey(c.Symbol)
{
_prevClose[c.Symbol] = c.Price;
}
else
{
_prevClose.Add(c.Symbol, c.Price);
}
}
return symbols;
});
After this pre-selection is done, you need to make a History Request to fetch the High for each symbols and continue with your trading logic.
3
Dean Gutierrez
29
,
thanks Alexandre, will try it out
0
Kbsaravana
1.1k
,
Dean Gutierrez , I'm also interested in that pre-market gap analysis, If you dont mind, could you share the code?
1
Jared Millman
206
,
Hi, I'd love that code as well. am trying to implement something similar. I have been looking for patterns with a data scientist and wanted to implement some of the strategies. I am looking for gap ups 30% and making a decision on the first three 5 min candles for a trade at 9:45-9:50. Â I wasn't sure how accurate a program like this would be real time since it would have to calculate gap ups. Â I assume that would take time and didn't know if there were limits.
 I'd love to share work.
Thanks!
Â
0
Edited by Jared Millman
Louis Szeto
STAFF
,
Hi Jared
We recommend using self.History method with extended market hour data for additional filtering:
# in a scheduled event at like 0925 of trade day
history = self.History(self.ActiveSecurities.Keys, timedelta(hours=6), Resolution.Minute, extendedMarketHour=True)
if not isinstance(history, pd.DataFrame) or history.empty: return
# Let’s say we want some range of stocks
history = history.close.unstack(0)
range = history.max() - history.min()
return range[range > your_threshold].index
return []
Best Louis
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!