Black Lives Matter. Please consider donating to Black Girls Code today.

Expanding Candlestick charting in R with Buy/Sell text: Solved

I have been learning R for a couple of months now and was looking for a way to do interactive candlestick chart with buy/sell signals on the chart for the respective buy/sell days.

I came across a blog post on candlestick chart using plotly and am able to
do the same on my csv data file which contains OHLC data Plus the buy/Sell column in it.
Here is a link to the blog: http://moderndata.plot.ly/candlestick-charts-using-plotly-and-quantmod/

I also read my last column which has a Buy/Sell string in it to show that we have a trade on a given day.
Many days we will not have any trade signal.

I wanted to show a B or S on the candle stick chart for the days when we had a Buy or a Sell trigger.

Using the code when I try to set the mode to “lines+text” and set my text to the B/S label where the B/S label is stored as a separate column in the data frame.

For some reason the B/S signals only gets collected over the first two years of my dataset on the chart, while for the rest 5 years no signal show up on top of my candlestick even though I have some signals that should be displayed.

Can someone provide your thoughts and insight into how can I solve this particular problem? Or do you think I should be using annotation instead of text to display my signals?

Thank you very much!

SOLVED:
I found the solution. I still use text but now I am associating my Buy/Sell column with the plot.base data frame instead of keeping it as a separate entity. This seems to work as the plot_ly call was associating with the buy/sell inside of the data frame with different dates, i.e. the buy/sell text column was somehow not aligned with the dates.

1 Like