Skip to content

Plot.py ‐ Basic Usage

Benny Thadikaran edited this page Aug 18, 2023 · 23 revisions

15th Aug 2023 WIP: New plot.py is ready and will be pushed in a day or two. Just updating documentation ahead of time

Plot.py has been rewritten to provide improved, customizable charts and new indicators for analysis. It adds new visual tools for delivery analysis. It works like any command line application with options.

This tutorial divided into 4 sections

Plotting a chart

To plot a single chart, use the --sym option providing the symbol name. You can also provide multiple symbols but for now lets stick to one.

py plot.py --sym tcs

TCS basic chart

Press 'q' to quit the chart. See Matplotlib keyboard shortcuts

By default, plot.py uses the daily timeframe. To display weekly timeframe charts, use --tf option passing the 'weekly' argument.

py plot.py --sym tcs --tf weekly

Study Charts from specific dates

Its 17th Aug 2023 today, if i want to study charts from 17th March 2023; i can use --date option passing the date in ISO format (YYYY-MM-DD)

This is useful to study charts during specific periods without future bias.

py plot.py --sym 'nifty 50' --date 2023-03-17

Nifty 50 chart on 17 March 2023

Chart Indicators

Volume

To add volume, use -v or --volume

py plot.py --sym sunpharma -v

Sunpharma chart with volume

Moving Averages

To add Simple moving average to the chart, use --sma.

py plot.py --sym icicibank --sma 50

To add Exponential moving average, use --ema.

py plot.py --sym icicibank --ema 30

EMA is calculated exactly the same as TradingView. (Switch on adjusted prices to compare)

To add multiple moving averages, use space separated values.

py plot.py --sym icicibank --sma 50 100 200

Icicibank chart with 50, 100 and 200 sma

Dorsey Relative Strength

This is calculated by dividing the stock closing price by the index closing price. It uses 'Nifty 50' by default but can be configured to use any index.

A rising RS indicates the stock is outperforming the index and vice versa. You can read this excellent article on Dorsey Relative Strength - chartmill.com for more info.

To add this indicator to chart, use --rs option

py plot.py --sym escorts --rs

Escorts chart with Dorsey Relative strength indicator

Manfeild Relative Strength

I read about this indicator in Stan Weinstein's book 'Secrets For Profiting in Bull and Bear Markets'. I highly recommend you to read the book.

The Manfeild Relative Strength (MRS) is calculated by dividing the regular RS by its 52 period moving average.

MRS = ( RS / SMA(RS, 52) - 1 ) * 100

This essentially compares the RS to its 52 period moving average. The MRS value less than 0, indicates the RS line is below the moving average and vice versa.

An RS line along with a moving average of RS line would display the same information as MRS.

You can read more on Manfeild Relative Strength - chartmill.com. Also read Stan Weinstein's book which provides numerous examples on using this indicator.

To add this indicator to chart, use --m-rs option. It is best used with the weekly chart.

py plot.py --sym 'm&m' --tf weekly --m-rs

Take note 'm&m' in single quotes. Stocks with '&' and <space> characters in the name must be quoted to avoid errors.

Other examples would be 'nifty 50', 'il&fseng'.

M&M weekly chart with Manfield relative strength indicator

Notice the helpful zero line (dashed line) on the indicator in the chart above.

By default, MRS uses 52 on weekly and 60 on daily to calculate moving average. Both are configurable.

To replicate the charts from Stan Weinstein's book, see below

py plot.py --sym tcs --tf weekly -v --m-rs --sma 30

TCS weekly chart with 30 Week MA, Manfield RS and volume

Support and Resistance

We can plot support and resistance lines on chart with the --snr option.

  • A resistance level is marked when, 2 candles with successive highs are followed by 2 candles with successive lows.
  • A support level is marked when, 2 candles with successive lows are followed by 2 candles with successive highs.

To simplify, its a 4 bar V shaped price rejection. It's not perfect but does its job reasonably well. See the chart below.

Ratnamani weekly chart with support and resistance

Limiting Number of Candles plotted

By default, plot.py will plot 160 candles on daily and 140 candles on weekly. This is configurable but you can also use the --period passing an integer for the number of candles.

py plot.py --sym apollotyre --period 60

Use it to get a larger perspective or narrow your focus on a particular region of the chart. You can combine it with the date option for better result.

Save Charts to File

The chart window provides many features like displaying candle values, dates etc and mouse/keyboard interaction with the chart.

If you prefer to save the charts to a file, you can do so with --save option.

The images are large so set your image viewer to resize to screen width.

Play around with these options and familiarize yourself. You don't have to type all these options every time. I will show you an easier way in the next section.

Next we will work with watchlists and presets.