Hi everyone!
I'm building a strategy where I'll need to draw daily candles. Ideally I would like to plot daily candles where you see the max and low price of that day. Is that possible?
The strategy so far is like this:
from AlgorithmImports import *
### <summary>.
### The entire charting system of quantconnect is adaptable. You can adjust it to draw whatever you'd like.
### Charts can be stacked, or overlayed on each other. Series can be candles, lines or scatter plots.
### Even the default behaviours of QuantConnect can be overridden.
### </summary>
### <meta name="tag" content="charting" />
### <meta name="tag" content="adding charts" />
### <meta name="tag" content="series types" />
### <meta name="tag" content="plotting indicators" />
class CustomChartingAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2010,1,1)
#self.SetEndDate(2017,1,8)
self.SetCash(100000)
self.instrument = "SPY"
self.instrument_to_trade = self.AddEquity(self.instrument, Resolution.Minute)
self.order_quantity = 100
# In your initialize method:
# Chart - Master Container for the Chart:
stockPlot = Chart("Trade Plot")
# On the Trade Plotter Chart we want 3 series: trades and price:
stockPlot.AddSeries(Series("Price", SeriesType.Candle, 0))
self.AddChart(stockPlot)
self.numberOfTradesPerDay = 1
self.lowWindow = RollingWindow[float](3)
self.highWindow = RollingWindow[float](3)
self.highNumber = 5000000000000
self.storedPriceHigh = 0
self.storedPriceLow = self.highNumber
self.Schedule.On(self.DateRules.EveryDay("SPY"),self.TimeRules.BeforeMarketClose("SPY", 10),self.EveryDayBeforeMarketClose)
def OnData(self, slice):
if slice[self.instrument] is None: return
self.lastPrice = slice[self.instrument].Close
if self.lastPrice > self.storedPriceHigh:
self.storedPriceHigh = self.lastPrice
if self.lastPrice < self.storedPriceLow:
self.storedPriceLow = self.lastPrice
if self.highWindow.IsReady and self.lowWindow.IsReady:
if self.numberOfTradesPerDay > 0 : #max 1 trade per day
if self.storedPriceLow > self.lowWindow[0] and self.lastPrice > self.highWindow[0]: #here there's the check that the current candle is "inside" yesterday's
self.ticket_buy = self.LimitOrder(self.instrument, self.order_quantity, self.highWindow[0])
self.numberOfTradesPerDay = self.numberOfTradesPerDay - 1
if self.storedPriceHigh < self.highWindow[0] and self.lastPrice < self.lowWindow[0]:
self.ticket_sell = self.LimitOrder(self.instrument, -self.order_quantity, self.lowWindow[0])
self.numberOfTradesPerDay = self.numberOfTradesPerDay - 1
def EveryDayBeforeMarketClose(self):
self.Liquidate("SPY")
def OnEndOfDay(self, symbol):
#Log the end of day prices:
self.Plot("Trade Plot", "Price", self.lastPrice)
self.lowWindow.Add(self.storedPriceLow)
self.highWindow.Add(self.storedPriceHigh)
self.storedPriceHigh = 0
self.storedPriceLow = self.highNumber
self.numberOfTradesPerDay = 1
'''
def OnStartOfDay(self, symbol):
#Log the end of day prices:
#self.Plot("Trade Plot", "Price", self.lastPrice)
pass
'''
Emiliano Fraticelli
As you can see in this screenshot on the trade plot ( that's what I'm interested in), when you zoom in you have daily “candles” but where just the closing price? is recorded… you don't have a “true” candle with min and max for that day.
Emiliano Fraticelli
I need candles like these ones, using the min and max for that day:
Alexandre Catarino
Hi Emiliano Fraticelli ,
When an algorithm calls the Plot method, it saves only one timestamp/datapoint pair. It's not possible to save a timestamp/OHLC pair. This information is sent to the charting software, HighCharts, which will group the datapoints automatically, meaning that we don't have much control.
This is a charting limitation that we hope to address in the future. Meanwhile, we can save the data in ObjectStore and load it in the Research Environment where there are charting packages that can help us achieve the desired view.
Emiliano Fraticelli
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!