plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
16.37k stars 2.56k forks source link

add footprint chart for finances #3965

Open quantfreedom opened 2 years ago

quantfreedom commented 2 years ago

i want to create a footprint chart like this one where i am able to make an open high low close but also show how much trading volume was at each y value of the candle

here is an example of what i am talking about

image

alexcjohnson commented 2 years ago

Interesting - that's a whole lot of extra information beyond the open, high, low, close needed to create ohlc and candlestick traces - and yet on its own it's insufficient to create the original trace as just those two sets of numbers don't indicate the open and close, nor (assuming that those numbers are binned as opposed to showing every valid price increment) do they contain as much precision as the OHLC numbers.

So while it would be possible, it doesn't seem like a great fit to shoehorn them into the ohlc and candlestick traces directly. I'd suggest adding the text in a heatmap - with the regular coloration of the heatmap hidden (make a white or transparent colorscale) and just display the text. If you're only showing a single candle the heatmap would have dimension 1xN.

quantfreedom commented 2 years ago

that's a whole lot of extra information beyond the open, high, low, close needed to create ohlc and candlestick traces

its very easy to get that data ... getting and understanding how to organize the data on our end is very very easy ... you can see what a csv file would look like here ... https://public.bybit.com/trading/BTCUSD/

lets say i wanted to create a 5 min candle ... for the info i would just add up all the sell orders at each price point of the candle and do the same for the buy orders ... then i have a dataframe within the candle that tells me the sell column and buy column ... and you can get the open high low close even from that data ... the open is the first trade at the start of the candle then the high is the highest point ... low is the lowest point and the close is the last candle ...

this info helps us visualize at what price point in the candle has the most trade volume ... footprint charts are used in high level trading ... I will be making a ton of videos on this subject if we can get one of these open source plotting platforms to help create something like this

all we would need is send dataframes inside a master dataframe ... so you have the overall dataframe that houses all of the candles and inside each candle is a dataframe of all of the sell and buy data at each price of the candle

ultimately would be nice for it to look like this image

but even something simple like what i showed in the first post would be nice

quantfreedom commented 1 year ago

@alexcjohnson hey .. wanted to check back in and see if you were still interested in doing this

alexcjohnson commented 1 year ago

I haven't gotten a chance to try and make a demo yet (maybe over the holidays, no promises), but your second example makes the heatmap + candlestick idea seem even more appropriate.

nicolaskruchten commented 1 year ago

I feel like a pair of violin traces here would give you the continuous version, and could be implemented fairly easily. One violin visible on the left for sellers and one on the right for buyers, per time-step.

quantfreedom commented 1 year ago

@nicolaskruchten ... that is a nice suggestion ... i tried to do the split violin but i can't seem to get it to work (mind you i didn't try for very long) ... but here is my csv file and what i was able to get to show up ... doesn't seem like i have the right info but it is close to what i would like to do

`import plotly.graph_objects as go

import pandas as pd

df = pd.read_csv("tester.csv") df.candle_time = pd.to_datetime(df.candle_time, unit='s')

fig = go.Figure()

fig.add_trace(go.Violin(x=df['candle_time'], y=df['price'], legendgroup='Yes', scalegroup='Yes', name='Yes', side='positive', line_color='green') ) fig.add_trace(go.Violin(x=df['candle_time'], y=df['price'], legendgroup='No', scalegroup='No', name='No', side='negative', line_color='red') ) fig.update_traces(meanline_visible=True) fig.update_layout(violingap=0, violinmode='overlay') fig.show()`

image

@alexcjohnson not sure if you have any ideas on this ... but i will try to look more into this ... but if you guys can see a very easy problem let me know

i somehow need 3 things here ... x needs to be the time y needs to be the price then inside the violin needs to be the buys and sells at the particular price within the given time ... just like in the picture

tester.csv

quantfreedom commented 1 year ago

@alexcjohnson wanted to check back in with you on this ... i have all the code done and all the csv files needed .... willing to also put in some dev work as well

quantfreedom commented 1 year ago

@alexcjohnson @AaronStiff @nicolaskruchten ... i am still interested in doing this ... so please have a look at this loom video of me explaining the concept ... really would like to use plotly because that is what i am used to using https://www.loom.com/share/76ccbf0a46374256b798f2a237f41f78

here is the github repo https://github.com/QuantFreedom1022/Footprints/tree/main

alexcjohnson commented 1 year ago

@QuantFreedom1022 I can't see that repo, but send me a note at alex@plot.ly and we can set up a call to discuss how to proceed.

quantfreedom commented 1 year ago

@alexcjohnson just changed it to public for you ... sorry about that ... and i will send you a message soon

quantfreedom commented 5 months ago

image we have made our own version if anyone else wants to help build it out more, you can join my discord and message me there ... the link to my linktree with my discord is on my github profile ... once the concept is built out more would be nice to present it to plotly and see if we could work together on this idea