1
$\begingroup$

I want to plot a trading chart with my indicator that is colored depending on its height.

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] &, "IndexLine" -> 0, "LineStyle" -> Blue, Filling -> 0];

The plot is given by

TradingChart[spy, {myIndicator}]

with "the uniform Blue color" indicator. It is natural consequence because in myIndicator I chose "LineStyle" to be Blue.

enter image description here

Now, I want to change the blue curve to new one that changes its color depending on its value (height). For example, the curve is red when its value is higher than 1, while it is blue when it is lower than 0.

Is it possible to do this?

I tried a simple attempt by changing "LineStyle" -> Blue to "LineStyle" -> "Rainbow", but, this did not work.

This question may be related to my previous question.

Any comment is welcome.

$\endgroup$
2
  • 2
    $\begingroup$ does this give what you need: myIndicator = FinancialIndicator[TimeSeries[indicatorData] &, "IndexLine" -> 0, "LineStyle" -> Opacity[0], Filling -> {1 -> {0, {Red, Blue}}}]; TradingChart[spy, {myIndicator}]? $\endgroup$
    – kglr
    Apr 25 at 10:02
  • $\begingroup$ @kglr Thanks, your suggestion worked, but, actually I need more. For instance, I want my indicator to be exactly like this: Plot[Sin[x], {x, 0, 2 Pi}, ColorFunction -> Function[{x, y}, Hue[y]], Filling -> Axis, FillingStyle -> Automatic]. This plot gives a curve filled with rainbow color that depends on its height. $\endgroup$ Apr 26 at 6:39

0

Your Answer

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

Browse other questions tagged or ask your own question.