Hi All,
I've built a Volume Profile indicator in C# and would love feedback, suggestions, or algo ideas. It's based on the TradingView implementation of Volume Profile. The indicator value is the Point of Control. The PoC appears to be accurate and close to TV's.
Other available data from the profile:
ValueArea - Returns the lower and upper bound of value area. This needs work, the area is too wide at the moment.
RelativeVolume - Returns the percentage volume of the current price area compared to the entire profile.
UpDownPercent - Returns the percent of UP candles in the current price area.
Run the backtest to see example values for AAPL.
Cole S
Made some bug fixes to the Value Area calculation.
Cole S
I've made more improvements to the indicator.
- After changing to minute resolution, the values are very close to TradingView
- Recalculating the profile every minute is expensive. I added a parameter to only recalculate after N periods.
I also added a Probability Density Function to create a continuous curve. This is experimental, but seems like it could be more accurate because a single bin can be an outlier. Need to do more exploration here. My thoughts are that there is quite a bit more useful information in the profile than the PoC, but we need a good way to represent that information. We want to find smaller, but still meaningful, peaks in the profile that show areas of strength or weakness.Let me know if you have thoughts or ideas on how we can improve this.
Derek Melchin
Hi Kctrader,
Nice indicator. The attached backtest extends the indicator to include a definition for the `Reset` method. In addition, a `lastRefresh` property has been added to track when the POC and ValueArea were last updated. One thing to note with the current implementation is `recalculateAfterNPeriods` must be larger than `period` or the indicator will initially return a value of 0, even though it `IsReady`. This is a result of the following conditional in `ComputeNextValue`:
if (_periodsPassed < _recalculatePeriod) return _pointOfControl;
See the attached backtest for reference.
Best,
Derek Melchin
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.
Cole S
Thanks for the improvents Derek!
.ekz.
This is good stuff. I had just started jotting down plans for a volume profile indicator based on a GitHub project mentioned in a QC ticket for the same. At first glance at this, it seems I might not have to. Thanks kctrader.
Regarding algo ideas, for your consideration: a pullback strategy that trades small-cap low-float stocks in the mornings, based on support levels determined by the volume profiler. I have plans to attempt this some day in the future, inspired by this strategy described n r/algotrading (with more detail in the comments). I probably wont get around to this for another month or two. Feel free to give it a go if it's of any interest.
Cole S
Thanks for the idea ekz! I have not tested this out much at this point. I built out a basic support/resistance indicator (that still needs work) and my plan was to use them in conjunction. Will definitely look inot small-cap/low-float.
.ekz.
Noticed some odd behaviour here. See simple backtest attached. When i try to enter a limit order with the value returned by the indicator (bottom of the value area), i get an invalid entry --some issue with buying power. However when i manually use the same value, the order goes through.
Try swapping out lines 69 and 70, and checkout the order list
Any thoughts?
.ekz.
Never mind. It's working as expected.
The volume profiler gives a different value every time so a diff limit order is opened every time. The error is thrown because too many of the limit orders got triggered at the same time.
Mystery solved.
.ekz.
kctrader
I'm working on getting this indicator added to Lean, officially. Would love to discuss it with you, off the forum and in real time if possible.
Are you on the slack and/or discord channels? I'm in both as ‘@ekz’
Mislav Sagovac
.ekz.
I have head for volume profile for the first time few days ago. I come here, to QC community to see if somebody has tried it already. Found his thread.
.ekz.
Not yet. Do check back in a few weeks though.
Mallikarjuna Reddy Palle
.ekz. I was wondering if you got this added to the repo.
Cole S
Mallikarjuna Reddy Palle I’m pretty sure it got implemented by someone else as ekz was working on it. Not at a como right now but I think it was called MarketProfile.
Mallikarjuna Reddy Palle
Found it:
Thank you Cole S
Anthony Bauer
Hi .ekz., I've been using the Volume Profile indicator in some of my backtests, and the results were different than what I was expecting. When inspecting the MarketProfile code, we noticed all the volume is assigned to the close price which is used in the volumePerPrice calculations rather than distributing the volume across the range of the trade bar (high to low).
Ideally, we would like to pass in a row size. Row size could be calculated more granularly from tick size and price per row as well. See here for the parameters passed into the py market profile implementation: https://github.com/bfolkens/py-market-profile/blob/master/src/market_profile/__init__.py#L11-L13.
Do you have thoughts on how to do this? Would this require an update to the LEAN code here: https://github.com/QuantConnect/Lean/blob/master/Indicators/MarketProfile.cs#L201-L213?
Thanks in advance!
Louis Szeto
Hi Anthony
You can specify the selector argument in the VP helper class, or update a manual VolumeProfile indicator with a custom value to override the “close price distribution”.
e.g.
Best
Louis
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.
Anthony Bauer
Hi Louis Szeto , thanks for the response. I tried the implementation you provided, and received the below error.
I believed the initialization was just missing the resolution, but even when updating the instantiation to below, the same but slightly different error occurs
Do you have any thoughts on either of these?
Louis Szeto
Hi Anthony
Sorry, the output of the selector has to be TradeBar object in VP
Best
Louis
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.
Frank Schikarski
Hi Guys, @cole-s, @derek-melchin,
some lunch break fun: please find an idea on how to further improve the calculation of the value area. It uses two loops to derive ValueAreaHigh and ValueAreaLow to ensure all (price, volume) buckets are adjacent which leads to the resulting value area being closer to valueAreaVolumePercentage. Below you see more smoothness in the evolution of ValueAreaHigh and ValueAreaLow with a lookback of 380 minutes with the custom version. Also, the number of buckets can be accessed using self.vp.NumBuckets for tuning priceRangeRoundOff. Please ensure to see the resulting plots by activating windows V1 to V4.
Best,
Frank
Built In
Custom
Cole S
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.
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!