Hi all,
I would like to plot a candlestick chart based on tradebar information (high, low, open close, so candle bodies and tails...) however I am not sure on how to use Plot with SeriesType.Candle for the purpose, as it takes only one value as an argument.
Can anybody assist with an example?
Eugene
Hi all,
same for me. I just cant figure our how to plot candle sticks.
Plot("A", "B", data["SPY"]); --> does not work.
Plot("A", "B", data["SPY"].Close); --> works and gives a line
thx for help
Douglas Stridsberg
Hey guys, a quick forum search leads to the below link, which describes the process in a bit more depth. There's also a section in the documentation relating to charting.
@E S, your code example would never plot candlesticks as you've omitted any information that would tell the engine you're looking for a candlestick...
https://www.quantconnect.com/forum/discussion/5591/help-me-to-plot-candlesticks/Â
Eugene
Hello Doaglas,
thx for your answer. I read the documentation and I also searched the forum and saw your example here:
https://www.quantconnect.com/forum/discussion/5591/help-me-to-plot-candlesticks/p1And that's exactly what drives me crazy.
public override void Initialize() { //Set the date range you want to run your algorithm: SetStartDate(2015,1,1); SetEndDate(2015,1,31); //Set the starting cash for your strategy: SetCash(100000); //Add any stocks you'd like to analyse, and set the resolution: // Find more symbols here: http://quantconnect.com/data AddSecurity(SecurityType.Equity, "SPY", Resolution.Hour); var myChart = new Chart("Chart1"); var mySeries = new Series("Series1", SeriesType.Candle); myChart.AddSeries( mySeries ); AddChart( myChart ); } /// <summary> /// On receiving new tradebar data it will be passed into this function. The general pattern is: /// "public void OnData( CustomType name ) {...s" /// </summary> /// <param name="data">TradeBars data type synchronized and pushed into this function. The tradebars are grouped in a dictionary.</param> public void OnData(TradeBars data) { var _lastPrice = data["SPY"].Close; Plot("Chart1", "Series1", _lastPrice); } } }
In the very last line:
Plot("Chart1", "Series1", _lastPrice); How to Plot Candles instead of the close price?Something like: Plot("Chart1", "Series1", data["SPY"].Candle);--> This gives: Runtime Error: 'QuantConnect.Data.Market.TradeBar' does not contain a definition for 'Candle' (Open Stacktrace)Douglas Stridsberg
Did you try actually running the code I provided?
On line 17 I am defining the Series to be of type "Candle". That's what makes the plot a candle.
In the thread I linked, I explain why this type of plotting might not be exactly what you're expecting it to be. You don't plot OHLC values independently - instead the charting engine calculates these for you.
If you're looking for a plotting solution, perhaps try opening a Research Notebook instead and using one of matplotlib's candle charts?
Eugene
thx again Doaglas
My error was to set the resolution to .Daily. So I just got the closing prices.Â
The engine calculates from the .Hourly closing prices the OHLC candle. Interessing.Â
What is the reason behind it? Which advantage or disadvantage comes with it?
I read all (many) docs, but can't find any logic in it.Â
Douglas Stridsberg
The data resolution does not affect whether or not you're seeing candles.
If you don't see closing prices, it's because the resolution of your chart view is too fine. On line #34, you can see we are only plotting the closing price. So if our chart is zoomed in such that one point per day is shown, it will only show a "line" (i.e. a candle where O=H=L=C).
Let me show you an example. Please change the range of your backtest so you have at least 1-2 years between the start and end dates.
Image #1 - daily data, but I'm zoomed in, so the charting engine will show me one point per day:
https://user-images.githubusercontent.com/4928988/57196528-a7d26e80-6f55-11e9-891d-93137d78277f.PNGÂ
Image #2 - daily data (again) but now I've zoomed out. The charting engine shows me one point per week which means each candle will now be composed of 5 days' worth of data. O, H, L and C will be generated from the closes you've provided:
https://user-images.githubusercontent.com/4928988/57196547-d2bcc280-6f55-11e9-8322-3e9d6608afe6.PNGEugene
I got it, hopefully :)
But still, why is (whats the reason for) the engine not plotting OHLC candles? All the data is available for each slice of data.
Anyway it is like it is.
thx Douglas!
Nextstep
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!