3
$\begingroup$

My goal is to make a figure like this picture in a financial indicator, enter image description here

I want to plot “a colored” financial indicator below a trading chart.

I prepared financial data and data of my indicator:

spy = FinancialData["SPY", "OHLCV", {{2020, 12, 1}, {2020, 12, 10}}];
indicatorData = {{{2020,12,1},1}, {{2020,12,2},2}, {{2020,12,3},3}, 
{{2020,12,4},-1}, {{2020,12,7},-2}, {{2020,12,8},-3}, {{2020,12,9},1}, 
{{2020, 12, 10}, 3}};
myIndicator = 
FinancialIndicator[TimeSeries[indicatorData] &, "LineStyle" -> Blue,
"IndexLine" -> 0];

The plot of the data is

TradingChart[spy, {myIndicator}]

enter image description here

I want to use Hue and Filling to fill the indicator with color, depending on "colorData" which is a set of dates and Hue values,

colorData = {{{2020,12,1}, Hue@0.2}, {{2020,12,2}, Hue@0.3}, 
{{2020,12,3}, Hue@0}, {{2020,12,4}, Hue@0.2}, {{2020,12,7}, Hue@0.5}, 
{{2020,12,8}, Hue@0.4}, {{2020,12, 9},Hue@0}, {{2020,12,10}, Hue@0}};

I need to fill the region between my indicator and x-axis by using Filling.

Although I guess Hue and Filling are keys to my question, any idea would be appreciated.

$\endgroup$

1 Answer 1

3
$\begingroup$

If you are willing to give up interactive display of legends, you can post-process Setting @ TradingChart[...] to get a graphics object with desired filling style:

myIndicator = FinancialIndicator[TimeSeries[indicatorData] &,
  "LineStyle" -> Blue, "IndexLine" -> 0]; 

Setting @ TradingChart[spy, {myIndicator}, ImageSize -> Large] /.  
 subplot : Line[MapIndexed[N@{#2[[1]], #} &, indicatorData[[All, -1]]]] :> 
  {First @ 
   ListLinePlot[First @ subplot, Filling -> 0, 
          FillingStyle -> Automatic, 
          ColorFunction -> (Blend[colorData[[All, 2]], #] &)], 
   subplot} 

enter image description here

$\endgroup$
1
  • $\begingroup$ I appreciate your idea, that never crossed my mind. But, this time I don't want to give up interactive display. This answer is also useful If I don't use Tradingchart... $\endgroup$ Jan 27 at 3:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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