Hey,
I want to plot candlesticks on hourly forex data. Can anybody tell me how to do this?
Don't have an account? Join QuantConnect Today
QuantConnect Community Discussions
QUANTCONNECT COMMUNITY
LEAN is the open-source algorithmic trading engine powering QuantConnect. Founded in 2012 LEAN has been built by a global community of 180+ engineers and powers more than 300+ hedge funds today.
Join QuantConnect's Discord server for real-time support, where a vibrant community of traders and developers awaits to help you with any of your QuantConnect needs.
The Open-Quant League is a quarterly competition between universities and investment clubs for the best-performing strategy. The previous quarter's code is open-sourced, and competitors must adapt to survive.
Request for assistance in plotting hourly forex candlesticks.
Continue ReadingRefer to our Research Guidelines for high quality research posts.
Create an account on QuantConnect for the latest community delivered to your inbox.
Sign Up Today
|
|
|||||||
|
|
||||||||
|
Help me to plot candlesticks
Darko Alexander | April 2019
Hey,
I want to plot candlesticks on hourly forex data. Can anybody tell me how to do this?
QuantConnectâ„¢ 2025. All Rights Reserved
Douglas Stridsberg
Hey, gonna assume this is a repost of
https://www.quantconnect.com/forum/discussion/5574/need-help-to-plot-candlesticks/p1Please check the documentation on Charting and start there. Should be relatively self-explanatory but do let us know if you run into any issues!
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.
Darko Alexander
Hey Douglas,
Thanks for replying. I did read the documentation. But it doesnt answer my questions. First, why is there skipping going on.? Candles are only plotted for every other hour, as opposed to every hour. Second, how do you attach low, high, open, close price data to the same candlestick? If I create a separate series for each of these, then four candle sticks will lay on top of each other, instead of one candlestick for all four.
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.
Douglas Stridsberg
I'm attaching an example of as far as I understand candlestick plotting in QC. I don't know how to add OHLC to the candle - as far as I know, the chart will generate this itself based on the data you feed it. So if you feed all of the values into the same series (and make sure you feed your open first and your close last), you should get a bar that represents this accurately.
I'm sorry I can't help you fully - I haven't played enough with the charting to fully be able to help you.
To view the candles, try cloning the algo and backtesting it on your end. (I can't get the candles to show on the forum).
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.
Douglas Stridsberg
This may also help:
https://www.quantconnect.com/forum/discussion/1326/creating-ticks-from-bars-begnning-end-of-day-execution/p1/comment-16081The 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.
Darko Alexander
Thanks for your help Douglas. I cloned your example and ran it, there was no OHLC data printed on the bar. Only date and "Series1" were printed on the bar, Also, the examples were not written in Python, and the data in the example was not Forex. You know, Quotebars behave differently than Tradebars.
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.
Douglas Stridsberg
My example was meant to highlight a point - candles in Lean do not themselves contain OHLC values that you can set yourself, but rather the candles are simply visually generated based on the amount of data and time you've zoomed into. This is as far as I understand the candle concept - if you study the source code for how the candles are generated I think you will come to the same conclusion.
Please also take a look at the link I gave you - it illustrates how you can approximate a candle as best as possible, and it again highlights that the candles are visually generated based on the underlying point-by-point data rather than by 4 different series (OHLC).
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.
Darko Alexander
Hey Douglas, the link that you sent was not very helpful because it wasnt Python code, which is the language that I work with... It is interesting, there are so many comments in the community that contain charts with candlesticks that show all four OHLC values. Yet, nobody seems to know anything about the issure. It is very weird.
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.
James Barnes
Hey All,
so I figured out how to plot candles in Python and wanted to share.
class QuantumVerticalProcessor(QCAlgorithm):
chart = None
series = None
def Initialize(self):
self.SetStartDate(2019, 11, 8) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.AddEquity("SPY", Resolution.Daily)
self.candles = Series('Daily', SeriesType.Candle)
self.chart = Chart('Candles')
self.chart.AddSeries(self.candles)
self.AddChart(self.chart)
def OnData(self, data):
time = self.UtcTime
# NOTE: order is important and each point has to be one minute apart because reasons.
self.candles.AddPoint(time + timedelta(minutes=1), data["SPY"].Open)
self.candles.AddPoint(time + timedelta(minutes=2), data["SPY"].High)
self.candles.AddPoint(time + timedelta(minutes=3), data["SPY"].Low)
self.candles.AddPoint(time + timedelta(minutes=4), data["SPY"].Close)
You're welcome!
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.
Charles Naccio
Adding to James' solution, if you're operating within a given resolution, you can at least set the open and close times correctly for the candle. The high/low times can be any time in between the open/start and close/end time. See below for an example plotting hourly candles using an Hourly data resolution.
def OnData(self, data): tradeBar = data["SPY"] self.candles.AddPoint(tradeBar.EndTime - timedelta(minutes=59), tradeBar.Open) self.candles.AddPoint(tradeBar.EndTime - timedelta(minutes=58), tradeBar.High) self.candles.AddPoint(tradeBar.EndTime - timedelta(minutes=57), tradeBar.Low) self.candles.AddPoint(tradeBar.EndTime, tradeBar.Close)
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.
Blake
Hi all,
I am having an issue plotting the candle stick chart correctly on consolidated data. Following the above example, I can plot a EURUSD candle chart perfectly on Daily data, but if I switch the base resolution to hourly and then plot on top of a daily consolidator, the candles plot incorrectly.
There may be a clue in the log of time which I have printed which looks inconsistent between the two examples.
Can anyone please help me plot the candles out correctly using Daily Consolidated data, keeping the raw input to hourly (so I can fill trades better)? Example attached, Thank you.
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.
Marek
@Charles Naccio, have you managed to plot n-minutes candlestick chart on consolidated data in OnConsolidated event handler? I tried and I receive only daily candles... and think that the only workaround for custom bars is to use point data and scatter plot.
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.
Shile Wen
Hi Marek,
The code provided by Charles should work similarly inside a consolidated data function as this function receives a TradeBar object.
Best,
Shile Wen
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!