2
$\begingroup$

With the command CandlestickChart one can create charts such as

CandlestickChart[data]

enter image description here

Let's say, we take the 20-period moving average of the closing values of each candle, and store it in a list called data20MA with the same DateObject time-stamps for the x-axis. How can we display both, the candle stick chart and the 20-period moving average line on top of each other in Mathematica 11.3? (I tried to Show the CandlestickChart with a DateListPlot, but it produced an erroneous picture.)

EDIT:

Perhaps a moving average is too simple for this question. More generally, if we have a list of values list computed for each time stamp of the price data, how can we overlay a ListLinePlot (or equivalent) of list with a candlestick chart of data?

$\endgroup$

1 Answer 1

2
$\begingroup$

You can use TradingChart to get the same chart with the added convenience of a hundred built-in indicators:

data = FinancialData["IBM", "OHLCV", {{2009, 5, 1}, {2010, 4, 30}}];

Row[{CandlestickChart[data, ImageSize -> Medium], 
  TradingChart[data, {"OHLC"}, ImageSize -> Medium]}] 

enter image description here

TradingChart[data, {"OHLC", {"SimpleMovingAverage", 20}}, 
 "IndicatorStyle" -> Directive[Thick, Red], ImageSize -> Large] 

enter image description here

$\endgroup$
3
  • $\begingroup$ This looks useful, but I actually referred to the 20-period moving average just for simplicity. What if I have created my own indicator, which would not be built into Mathematica by default. How can I overlay a line from a list of values of a custom indicator onto a candle stick chart? $\endgroup$
    – Kagaratsch
    Oct 18, 2020 at 21:20
  • 1
    $\begingroup$ @Kagaratsch, set the number n to 20 in {"SimpleMovingAverage", n} to take the simple moving average based on previous 20 periods (see "SimpleMovingAverage"). Re adding a custom indicator see this great answer by Lukas Lang. $\endgroup$
    – kglr
    Oct 18, 2020 at 21:34
  • $\begingroup$ I notice that whenever I put TradingChart (or CandlestickChart) into a Dynamic, the notebook becomes unresponsive, updates to the data displayed on the charts take a whole second to appear and even the mouse becomes laggy. Is there a type of candle stick chart in mathematica that works well with quickly updating dynamic data? $\endgroup$
    – Kagaratsch
    Oct 27, 2020 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.