4

I'd like to write my own indicators to use with functions like TradingChart. From the context, it's clear that one needs to write a function whose parameters provide access to the underlying list of "OHLC" bars. Also, I don't know whether these indicator funtions are called after every bar is seen or just once. If the latter, then the list is sufficient but if the former, then there has to be another parameter that lets you know where you are.

Artes
  • 57,212
  • 12
  • 157
  • 245
  • Did you see this example? Looks like all the data for a single element is passed in one call per element. Easy. – Sjoerd C. de Vries Oct 21 '13 at 19:29
  • I assume you're talking about the ChartElementFunction. I don't quite see how that helps. For example, suppose one wants to look at the last 50 values (relative to the current value) to perform an operation. How do you know where you are and how do you get at the previous values? – David Jameson Oct 25 '13 at 15:47
  • I'm afraid I fail to understand your problem. The function you pass gets all the information you need automatically passed through its arguments. You use these to draw an indicator in the place where it needs to be and the chart function places it there and proceeds to call your custom function for the next indicator. No need to "know where you are". – Sjoerd C. de Vries Oct 25 '13 at 17:28
  • I appreciate your patience. Can you give me an example of the signature of such a function so that I can see exactly how I would reference all the existing data. It is not clear to me what constitutes a single element? For example, if I have 365 days worth of data (one per day) to handle, do I get a single callback with the entire 365 days of data or do I get a callback for each day of data? If the former, then what do you do if you want to update your charts (or indicators) in real time as data arrives from an external source? – David Jameson Oct 28 '13 at 03:15
  • Your function gets called for each indicator separately. If new data arrives you redraw the entire plot with a new call to the plotting function with the new data. – Sjoerd C. de Vries Oct 28 '13 at 06:21
  • That's what I was afraid of. I'm not a fan of premature optimization but suppose you wanted to implement SMA over the last 50 bars. Every time you get a new bar, you need access to the last 50 bars but for efficency you'd like to keep an accumulator and just remove the oldest value and add in the newest value, then divide by 50. I certainly wouldn't want to have to plot the entire graph again every time this happens. Suppose you have bars coming in every minute or every second. It's sounding like Mathematica may not be the way to go for this. – David Jameson Oct 28 '13 at 14:34
  • Plotting simple charts shouldn't take that long. It wouldn't be a problem to redraw an entire figure several times per second. However, drawing individual indicators based on data of the other indicators is another problem entirely. This could probably be solved by using global variables, so wouldn't be very elegant. Perhaps you should come up with a concrete example of what you want, and someone might come up with a solution. – Sjoerd C. de Vries Oct 28 '13 at 15:32
  • What I wanted (per my original question) was the signature for these callback functions so I can see how to write my own :-) From that, I would have been able to determine what was feasible. However, I do appreciate the feedback you already provided. – David Jameson Oct 29 '13 at 11:52
  • What do you mean by signature then? I know the word from a C++ context where it is the mangled name of a function. If you just want the calling syntax of ChartElementFunction, that's well-documented in the on-line documentation. – Sjoerd C. de Vries Oct 29 '13 at 12:31

0 Answers0