Message Boards Message Boards

How can I add the index of a candlestick to a TradingChart

When I display a TradingChart or InteractiveTradingChart I can see the Open, High, Low, Close and Date at the top of the chart whenever I move the cursor over a particular candlestick. So far, so good. However, I would also like to display the index of the candlestick. So, at the top of the chart, before displaying the usual O,H,L,C,Date information, I would like to display the Index which would start with 1 and go up by 1 for each subsequent candlestick. I have an application that refers to the candlesticks by their indices (e.g. 1,2,3,....) rather than by their date. How can I add the index to the information displayed by the TradingChart or InteractiveTradingChart? Is it even possible to do so or in general add other information to the chart?

POSTED BY: Henrick Jeanty
6 Replies
Posted 1 year ago

I haven't been able to figure out a way to do this yet. But maybe we can come up with a workaround. Are you building your TradingChart from explicit data (e.g. FinancialData)? Can you clarify what you mean by "an application that refers to the candlesticks by their indices"? Do you mean you want something to work programmatically, or do you just want to see the indices so that you can visually compare two different representations? Or do you mean something else entirely?

POSTED BY: Eric Rimbey

Thank you for offering help Eric. Let me be a bit clearer.

1) Yes, I use explicit FinancialData of the form {{#Date, {#Open, #High, #Low, #Close, #Volume}}}. using the following code

makeChart[currentCandles_Dataset] := 
  TradingChart[{#Date, {#Open, #High, #Low, #Close, #Volume}} & /@ 

where I have a Dataset called currentCandles which, among other things, contains the Date,Open,High,Low,Close and Volume of each candle.

At the moment, if I display a TradingChart or an InteractiveTradingChart, the information at the top of the charts is O,H,L,C and Date of the candle currently under the cursor.

My application provides information such as "There is a peak at bar #6" or "A trendline was broken at bar #23". So, when I want to visualize if the output of my algorithm is correct, I use the TradingChart and I try to go to bar #N rather than go to bar on Tuesday, December 4.

It would be easier for me to zoom in on a bar quickly if I simply could see the index of the bar (meaning its index in the Dataset). That is why I would love to be able to add a string like "I: N" at the front of the information currently being presented by the TradingChart.

Is this clearer? Thank you for any help.

POSTED BY: Henrick Jeanty

Wouldn't it be better if your application returned a date rather than an index? Easier to interpret "There is a peak on 2022-07-25" rather than "There is a peak at bar #6". An index can change depending on the date range being analyzed, the date will not change.

POSTED BY: Rohit Namjoshi

Hello Rohit, actually it is easier for me to think of a bar location in terms of its index. If I know that I am displaying 64 bars and I want to look at bar# 32, I know that it is roughly in the middle (actually exactly in the middle) of the chart. Once I get the cursor over the bar that is roughly in the middle, I would want to see its index and if the current bar was at index 28, I would know to move 4 bars to the right. Quite easy and simple.

On the other hand, dealing with dates, assume the chart is running from Feb. 4 to November 24 and you are interested in the bar on September 13. It simply is not as easy.

And from a more general perspective, I would like to know if it is possible to modify what is displayed at the top of the chart.

And, yes, the date doesn't change but the index does, depending on the date range being covered. But when I debug the code and something goes wrong on bar# 23, I may want to see what the values were for, say the last 15 bars because I am calculating a 15-day moving average for example. Or I might want to look at the last N bars or the 5th to last bar [[-5]]. All of that is much easier (at least for me) to deal with in terms of indices rather than dates.

So, I still would like to know if I can modify the string/information displayed at the top of the chart whenever I move the cursor over a particular bar. At that point working with indices

POSTED BY: Henrick Jeanty
Posted 1 year ago

It seems to me like TradingChart is very hard-coded in terms of its display. I wasn't able to add labels or tooltips, and I couldn't find any option like DisplayFormat or something that would allow me to provide my own display function. There is an option called EventLabels, but I wasn't able to get it to do anything dynamically. I think if you created an event label for every date, it would be too cluttered to be useful. The next thing I would try is to look at FullForm[TradingChart[...]] and try to find where the mouseover display is happening. Maybe you could just directly replace that for testing purposes.

POSTED BY: Eric Rimbey

Again thank you Eric for the suggestion. Looking at the FullForm will also be a good learning exercise. By the way, another reason I want to see indices is because, many of my calculations use indices. For instance, if you are calculating trendlines, their equations are based on the index of the bar. not the date. So, if a trendline says that it is based on the lows of bars 11 and 43, I want to see bars 11 and 43 on the chart.

Thanks again for the suggestion.

POSTED BY: Henrick Jeanty
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract