I have the following code:
using System;
using System.Linq;
using QuantConnect.Indicators;
using QuantConnect.Models;
namespace QuantConnect.Algorithm.Examples
{
public class QCUMovingAverageCross : QCAlgorithm
{
private string _symbol = "SPY";
private Symbol symbol;
private Security sym;
private Chart _equityChart;
private DateTime StartDay = new DateTime(2020, 03, 29);
private DateTime EndDay = new DateTime(2020, 06, 29);
private int startCashAmount = 25000;
string chartName1 = "Chart_1";
string chartName2 = "Chart_2";
public override void Initialize()
{
// set up our analysis span
SetStartDate(StartDay);
SetEndDate(EndDay);
SetCash(startCashAmount);
//SetBenchmark(time => 25000);
sym = AddSecurity(SecurityType.Equity, _symbol, Resolution.Hour);
symbol = sym.Symbol;
_equityChart = new Chart(chartName1);
_equityChart.AddSeries(new Series("Plot_my2", SeriesType.Candle));
AddChart(_equityChart);
var myChart = new Chart(chartName2);
myChart.AddSeries( new Series("Plot_my1", SeriesType.Candle) );
AddChart( myChart );
}
private DateTime previous;
bool sl_set=false;
public void OnData(Slice data)
{
if (!slow.IsReady) return;
//if (previous.Date == Time.Date) return;
var X = Securities[symbol];
Plot(chartName2, "Plot_my1", X.Close);
// Candle
_equityChart.Series["Plot_my2"].AddPoint(Time+ TimeSpan.FromMinutes(1), X.Open);
_equityChart.Series["Plot_my2"].AddPoint(Time+ TimeSpan.FromMinutes(2), X.High);
_equityChart.Series["Plot_my2"].AddPoint(Time+ TimeSpan.FromMinutes(3), X.Low);
_equityChart.Series["Plot_my2"].AddPoint(Time+ TimeSpan.FromMinutes(4), X.Close);
}
}
}
and I have 2 questions:
1) why the "chart1" and "chart2" doesn't have same results, specifically i mean, why chart2 doesnt show the correct OHLC values of bar, while in forum examples and everywhere people had that example. Is the approach of "chart1" the only correct approach to have a candlestick chart for equity? (the same chart as we see in i.e. tradingview)
2) why chart2 dissapears from backtesting results page, when i click "chart1" and conversely, chart1 disappears when i click chart2 to show up. why? how can i force to show both of those windows there?
p.s. 3) havent anyone noticed this forum has bug? when i edit the post that contained inserted code, when i click edit again, the code has lost formatting in edit page.
Derek Melchin
Hi T. Todua,
(1) At the moment, QuantConnect/Lean does not support candle from OHLC values. We have a GitHub issue to address the issue:
Enable candle charts using TradeBar #669
We do not recommend the workaround of
_equityChart.Series["Plot_my2"].AddPoint(Time+ TimeSpan.FromMinutes(1), X.Open); ...
(2) This seems to be caused by the specific chart names the algorithm uses ("Chart_1", "Chart_2"). After changing these names, we're able to display both charts at once. See the attached backtest for reference. I've created a GitHub Issue to have this bug resolved. Track our progress here.
(3) Thanks for reporting this bug, I've forwarded it to our UX team to resolve.
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.
T. Todua
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!