Back

Custom charting

Hi,

I'm trying to create some custom charts but couldn't figure it out from existing examples. Joined the prime account and tried to get support but I'm told to ask the question in this forum.

How would I be able to create the following plots:
1) line chart of close prices
2) buy and sell prices and some sort of indicator showing long or short position
3) rsi indicator

I have been using the RSI alpha model as a starting point:
 

https://github.com/QuantConnect/Lean/blob/master/Algorithm.Framework/Alphas/RsiAlphaModel.py

 

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.


Hi Dat,

To create custom charts, we would use the self.Plot method inside the algorithm, but outside the algorithm, such as in the Alpha Model, we would need to call algorithm.Plot. I’ve attached a backtest demonstrating how to develop the plots for the three items mentioned.

Best,
Shile Wen

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.


Shile, you're a legend thank you now I understand...

The doc below is slightly different but both seems to work. The algorithm reference usees data.Bars. What's the difference there? 

https://www.quantconnect.com/docs/algorithm-reference/charting

self.Plot('Close', 'SPY', data[self.spy].Close)
self.Plot('Trade Plot', 'Price', data.Bars["SPY"].Close)

My understanding is data.Bars gives the trade bar and data.QuoteBars gives the quote bar. Tried to use quote bar below but didn't work. Any hints please?

from MyRsiAlphaModel import MyRsiAlphaModel
class ParticleQuantumCompensator(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 3, 1)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        self.AddAlpha(MyRsiAlphaModel())
        self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
        
        self.ibm = self.AddEquity('IBM', Resolution.Daily).Symbol

    def OnData(self, data):
        if self.ibm in data:
            self.Plot('Close', 'IBM', data.QuoteBars["IBM"].Close)
           
        
    def OnOrderEvent(self, orderEvent):
        if orderEvent.Direction == OrderDirection.Buy:
            self.Plot('Price', 'Buy', orderEvent.FillPrice)
        elif orderEvent.Direction == OrderDirection.Sell:
            self.Plot('Price', 'Sell', orderEvent.FillPrice)

0

Hi Dat,

This is because there is no QuoteBar data for Daily Resolution (QuoteBar data is only available for Minute/Second/Tick Resolutions). If using QuoteBars, data.QuoteBars["IBM"].Close is the mean between data.QuoteBars["IBM"].Ask.Close and data.QuoteBars["IBM"].Bid.Close. I’ve shown how to access all three of these values in the attached backtest. However, if using Daily data, I suggest using data.Bars because of the reason mentioned earlier. To see more on handling data, see our docs here.

Best,
Shile Wen

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