Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
view buy and sell signals on the chart and table

Hi,

How can I see buy and sell signals on the chart and table, can I draw a forward looking chart with this signals ?

Thanks,

4 responses

Hi Joe,

You can create a custom signal to indicate when the algorithm buys/sells positions by track the length of your portfolio. You can then draw it on the custom graph using the record() function.

For example,

record(pos = len(context.portfolio.positions))  
Disclaimer

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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.

Alisa, do you have any example of a video of how it looks like? I was trying to search for any kind of an example, but failed to find any.

I mean an example, where I can see a chart with buy and sell entries for a backtesting strategy, even the simplest one.

There isn't a video of how to record signals that I am aware of. However, attached is a backtest which records both a buy and a sell signal. The specific code is

def record_vars(context, data):  
    """  
    Plot variables at the end of each day.  
    Here we record the buy and sell signals returned from our pipeline  
    Record only supports single numeric values.  
    If a signal is a boolean value convert to integer first  
    """  
    pipe_results = algo.pipeline_output('pipeline')  
    record(buy=int(pipe_results.buy_signal), sell=int(pipe_results.sell_signal))

The plot of the signals appears in the bottom of the IDE graph when running 'build algorithm' and labeled 'custom data' (which can be seen in the attached algo below). The signals can also be viewed in the full backtest results by clicking on the activity tab and then clicking custom data.

A few things to note about using the record function.

  • One is limited to 5 variables.
  • One can use multiple record statements within a program (all the variables do not need to be defined at one time).
  • If multiple values are assigned to a record variable, only the last value is recorded each day.
  • In both the IDE and the full backtest windows, individual variables can be toggled on or off by clicking the variable in the legend. This is helpful to hide some of the variables for easier viewing.
  • Finally, in the IDE as the scale gets larger, the plot will automatically shift from daily values to a weekly average. This can be confusing at times. In the case of a 1 or 0 signal, the weekly average may be displayed as a decimal (eg .3).

Hope that helps.

Disclaimer

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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.

Thank you, Dan. Is there any ability to plot on the graph itself? E.g. to create a short horizontal line (lenth = from date of entry to predious day) and a down/up arrow for short/long entry.