-
Notifications
You must be signed in to change notification settings - Fork 653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More easily Plot Trades or Trade Signals #49
Comments
A few points
When this
|
Yes to 4, and that and your explanation of how to simplify the nan list is brilliant. Thank you so much! |
+1 to this feature. You could also consider combining it with: What if you had a generic way of adding "annotations" to the graph. An annotation would only require a start_time, but can also include many other parameters like end, color fill, etc. The interface could look like:
This could combine all the various use-cases for marking up the graph with annotations. Thoughts? |
Hi all. Is anyone actively working on this? If not, I think I can handle this with a few clarifications. |
No one is actively working on this presently. Glad to have you contribute. |
Please let me know what you need clarified, and/or what you have in mind for this. |
Just to note, I had nicely handled this with a long list of make_addplot with scatter=True as below: apd = [mpf.make_addplot(sell_signal, scatter=True, This made the code longer due to heavy numbering needed (300 lines only for plotting tasks) but very effective for my purposes |
Hi all, I've got something for plotting trades done. It assumes the data is just a DataFrame where the index is a Datetime and the price column is named "Price". It does not assume the lengths are equal, it simply plots things the way the first post ask for, essentially along the lines of
while doing all of the necessary checks while attempting to maintain the conventions of the project (at least I hope). Below is a simple example of what things look like:
or if you want to customize the trades marker, markersize, and/or color you pass a dict:
@DanielGoldfarb, I am unsure how to proceed with the signals though. Will the data be passed into signals be sparse as well, and I should try to calculate the shaded regions? Or will I be given a list/series of something like [0, 0, 0, 1, 1, 1, 0, 0, ... -1, -1, 0, 0] that equals the length of the plot data, where 0 is no active trade, 1 is a long signal, and -1 is a short signal? If you want, I can make a pull request of what I have so you can review before moving forward, whatever you think is best. edit: minor wording |
I was also thinking that passing in trades (buys, sells) would only make a scatterplot (ie if you want to plot simulated/actual trades) whereas if you want to plot a signal, it would automatically plot a shading region to keep things simple. |
@CNich -- Thank you so much for getting involved with this! I don't have a lot of time to look into this with much detail; hopefully within 2 to 3 days, but I will give you some immediate thoughts:
As mentioned, I will put some more time and thought into this in two or three days time. In the meantime I hope the above comments are somewhat helpful, and feel free to take a look at the code in my fork to see what's coming (keeping in mind that it may change a little more before it is merged in another day or two). All the best. And thanks again. --Daniel |
Also, please take a look at this issue. It would be nice if as part of this trades/signals enhancement, we can also make it easier to have different "markers" for one set of trades or signals. Presently the underlying matplotlib does not support having a sequence of markers (although there is an issue on matplotlib requesting it). In the meantime, we probably can handle it in mplfinance by abstracting it for the user. |
Thanks for the feedback, I am more than happy to be involved! My initial reaction is that addplot seems to be doing much more under the hood than what I added, but I am not fully familiar with the code base yet. In the coming days, I will look into rewriting my code to enhance addplot instead of making a separate scatter function like it is currently -I just didn't want to make big changes to code you wrote but if you think it's the best way then I am happy to help. I will also take a look at the marker issue #97 when I get the chance. |
Hi @DanielGoldfarb, I can't seem to find your fork/branch that you are talking about, could you link to it? Is it in this repository? As for adding custom markers, will the input also be a specialized arg like buys and sells, so it might be something like:
where df_markers would be a list len(data) or a dataframe with a datetime index and each column could be a parameter?
|
Hi @CNich, My fork is here: https://github.com/DanielGoldfarb/mplfinance and I hope to merge it into the matplotlib/mplfinance repository soon. Regarding Issue #97 , I was inspired to use Elan Ernest's solution here and I now have it working (in my fork, soon to be in the main repository). The user can now call Users still are limited, however, in that the sequence length must be same as the data length for the main That said, I really like your idea of passing in a dataframe describing trade/signal markers! And I like the idea of being able to pass in "low" or "high" etc. for the 'location' column. Ideally that column should also accept numbers (prices). I want to think about the exact implementation, whether to integrate with |
Is your feature request related to a problem? Please describe.
Your addplot.ipynb page is phenomenal and I was able to figure out that I can add scatter points by;
trs = np.zeros((length_to_add, 1))
trs.fill(np.nan)
trs[x] = y
toplot.insert(6, "trades", trs, True)
apdict = mpf.make_addplot(toplot['trades'],scatter=True,secondary_y=False)
mpf.plot(toplot,type='candle',volume=True,addplot=apdict)
Describe the solution you'd like
While this is great it took a lot of energy - I'm moving from the plotpy (for the candles!) and there I simply wrote:
plt.scatter(trade_list_idx,trade_list_price,c='b')
Which was simpler than messing around with a dataframe and so on.
The text was updated successfully, but these errors were encountered: