This is a pure Python project to calculate various Market profile related operations in python and visualize them interactively with the help of plotly and dash components. The motivation behind this project is to feed price distribution (TPOs with alphabets) and other visual cues to convolution neural networks and see if NN learns from the visualization. Therefore this project will be heavy with all the visual cues, colours and different shapes. While working on the project realized that it is possible to use this entire framework for regular charting as well.
Okay, let's get started.
pip install plotly (update if previously installed)
pip install dash (update if previously installed)
pip install pandas
Finally, download all the files or clone this repo as zip and extract in local folder.
-
Open tpo_project.py from the folder in python editor
-
Run the code
-
In the console, you will see the message something like Running on http://127.0.0.1:8050/ copy the server address your console printed and paste it in your browser
-
That's it, you will get the TPO chart in browser with sample file provided in the folder.
-
About sample file: There is live.txt file in the folder. Add data manually and you should see new updated price in the chart.
-
Marker shows the last closing price. The market color changes to green if price >= POC else it is red.
-
If the test runs successfully replace live and historical data with your desired data feed.
-
Stop the server by pressing ctrl + c in the console.
Simply run static_tpo.py and the chart will open in your browser. It uses a single file as a source for generating charts (unlike dash version which uses history.txt and live.txt), you can replace history.txt with your own data while making sure header names are matching.
Run 'static_tpo_slider.py'. Copy or click the IP address and chart will open in the browser. It uses Dash for dynamically updating Y-axis as you move the slider on X-axis. Minimum number of days to display set to 5, you can increase if you want by sliding to the left. The reason using Dash for slider because PLotly's zoomin option do not update Y-axis dynamically which makes chart really squeezed up on larger range.
-
Match data format and headers exactly with given sample file.
-
It is not necessary to have the same data source for historical and live data as long as the format matches. It wouldn't matter even if symbol name is different, or there is price overlap the algorithm will drop the duplicate entries automatically.
-
Algorithm uses historical data for generating context. In tpo_project.py at the start, there is 'avglen' parameter. That number should be lower or equal to the sample size of your historical data. If you have 31 days of historical data then use avglen = 30
-
Make sure your historical file is up to date, especially entries representing day 1 and day 2. The algorithm automatically calculates session time and Initial Balance period using that info. IB is of 60 minutes. It assumes you have 1-minute data. I haven't tested on daily data.
-
If your live feed is of 1 minute instead of a tick, you may want to increase the refresh time 'refresh_int' which is set to default 1 second.
-
Chart update will not work until live file gets at least 30 minutes worth of data. To remove the limitation reduce frequency-time 'freq' from default 30 to 5 minutes or lower. But it will affect TPO chart calculations. So if possible don't change the parameter.
Run no_dash.py The flow is exactly the same as live version but without dash.
eg for square box. IB>yPOC<yVAH: 1> Explanation: It means Mid of IB range is above Yesterday's POC ( point of control ) but below yesterday's value area high (VAH)For that the algorithm gave the weightage of '1' RF means Rotational factor. RF Calculated on 1 minute bar. For a single bar RF can be at maximum 3 when there is higher high, lower low and higher close. Minimum value is -3 for a single bar. Then we sup up all the values for the day for daily RF and for IB RF summation for the 1st 1 hr. If you observe the breakdown for IB values, it doesn't have a lookahead bias so whatever the prediction or the strength of the IB at the end of 1st hour of the session it will remain the same and won't get updated. If size and color of squares matches with bubbles (which gets updated as day progress) IB predictions were right on the track.
Everything cannot be explained here, if you're interested do read this small handbook on Auction Market Theory CBOT Market Profile handbook (it is 13 mb pdf file) https://t.co/L8DfNkLNi5?amp=1