Back

How to plot indicator on price chart

Hi team,

What's the best way to plot indicator with a price chart in Backtest, like MA inside SPY chart or RSI below SPY chart?
Is there any existing that I can follow?
Thank you.

jianwei
Update Backtest








When plotting indicators overlayed on price I like to use something like the following:var close = Identity("SPY");
var ema = EMA("SPY", 14);
var rsi = RSI("SPY", 14);
PlotIndicator("SPY", ema, close);

Placing the code above in Initialize will cause the EMA indicator to automatically plot. The identity indicator just returns the current price, so you'll get both your EMA and the closing prices on the same plot.
If you want to do a stacked chart you'll need to create your own chart objectvar chart = new Chart("SPY", ChartType.Stacked);
chart.AddSeries(new Series(close.Name, SeriesType.Line));
chart.AddSeries(new Series(rsi.Name, SeriesType.Line));
AddChart(chart);

This will define the chart as a stacked type (vs overlay default). You could then plot your indicators using:PlotIndicator("SPY", close, rsi);
One thing to mention, you currently can't combine stacked and overlayed charts on a single chart. So it will either stack them all or overlay them all.

Hope this helps!
0

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.


Thanks Michael, tried the above which works fine.
Just one more thing, I see the framework already has a defualt chart for "SPY" which has the Buy/Sell orders plotted on it also. Just wondering is it possible to overlay indicator like EMA on that chart, as it would help a lot to visualize the strategy? Thx.
0

I *think* that those plots are kind of special and I'm not sure you can overlay other stuff on them. If you want your executions on the plot we can add that as well. I've attached a simple EMA cross algorithm that plots price, emaFast, emaLow and the buy/sell points on the same chart.
0

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.


That also works. Thank you.
0

Just an update - today we shipped this feature so you can stack or overlay indicators in anyway you'd like! Check out the announcement with examples: https://www.quantconnect.com/forum/discussion/924

1

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.


Update Backtest





0

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.


Loading...

This discussion is closed