Dynamically Updating Indicator Color

SA1

Member
Joined
May 18, 2020
Posts
10
Likes
1
Hello everyone!

I am trying to dynamically change the color of an indicator on the MotiveWave side bar.

Screenshot 2022-04-19 113117.png

Based on the values of the study, I need that color (currently green) to change to some other color (like red). What happens currently is that wherever I start the study, the color is correct, but it never changes color when it should. So if the color should be green when the study is added to the chart, it will be green, and if it should be red, it will be red. However it will never switch from green to red or red to green. It always stays the initial color.

This is the code I am using to set up the colors

Java:
var settings = getSettings();
var upColor = getSettings().getColor(Inputs.UP_COLOR);
var downColor = getSettings().getColor(Inputs.DOWN_COLOR);
IndicatorInfo ind = new IndicatorInfo(get("Indicator"), null, null, false, true);

and this is the code I am using to actually change the color when the study values change to the opposite values.

Code:
ind = new IndicatorInfo(get("LBL_INDICATOR"), upColor, null, false, true);
settings.setIndicator(Inputs.IND, ind);

This code seems to do nothing after the study is added to the chart. Without this code, it will not even have the correct initial color, so it seems like it is doing something, but it never updates. Is there a way to do this or am I running into some kind of limitation?
 

igor.s

Well-known member
Joined
May 22, 2019
Posts
278
Likes
150
You have an indicator declared in the initilize().
Try the following: instead of creating a new instance, update the color of the existing indicator instance.

IndicatorInfo ind = getSettings().get("Indicator").
ind.setLabelColor(color) or ind.setTextColor(color) whichever works.
I haven't tried it - just throw an idea to test.

cheers.
 

ScottyA

Well-known member
Joined
Aug 1, 2019
Posts
271
Likes
183
Would it be possible to achieve the same by setting the Color Policy? Not sure if that's doable with a Price Axis indicator.
 

SA1

Member
Joined
May 18, 2020
Posts
10
Likes
1
Would it be possible to achieve the same by setting the Color Policy? Not sure if that's doable with a Price Axis indicator.
What is the color policy? I have not run into that. Unfortunately, I haven't found a solution to this yet.
 

ScottyA

Well-known member
Joined
Aug 1, 2019
Posts
271
Likes
183
What is the color policy?

I'm a hack Java Developer at best. Nonetheless, I used the following snippet for a Study where I wanted VWAP to change color depending upon it rising or falling:

PathDescriptor vwapPath = new PathDescriptor(etc...
vwapPath.setColorPolicy(Enums.ColorPolicy.HIGHER_LOWER);
vwapPath.setColor(new Color(r: 70, g:160, b:255)); //cool light blue
vwapPath.setColor2(new Color(r:255, g:0, b:0)); //red

Hope that points you in the right direction. Let me know if I may provide anything else.
 
  • Like
Reactions: SA1

SA1

Member
Joined
May 18, 2020
Posts
10
Likes
1
I'm a hack Java Developer at best. Nonetheless, I used the following snippet for a Study where I wanted VWAP to change color depending upon it rising or falling:

PathDescriptor vwapPath = new PathDescriptor(etc...
vwapPath.setColorPolicy(Enums.ColorPolicy.HIGHER_LOWER);
vwapPath.setColor(new Color(r: 70, g:160, b:255)); //cool light blue
vwapPath.setColor2(new Color(r:255, g:0, b:0)); //red

Hope that points you in the right direction. Let me know if I may provide anything else.
I was excited to try this. Looks like your original guess was right though - it appears that it only works with PathDescriptors. Looks like a really cool feature - MotiveWave should add this functionality for Indicators too!
 

ScottyA

Well-known member
Joined
Aug 1, 2019
Posts
271
Likes
183
MotiveWave should add this functionality for Indicators too!

@MotiveWave_Jason

Hey, Jason! Long time, no talk. Would you please add the Color Policy functionality for Indicators to the Feature Request list? Is that an SDK addition? I don't know what would need to happen here.

I asked here so that you'd have the thread to reverence. Thank you, sir!
 
  • Like
Reactions: SA1

Wxll

Member
Joined
Oct 22, 2022
Posts
15
Likes
4
The SuperTrend indicator also available in the public code of the SDK has an example of a changing line color...
Not exacly the question here, but as I tried to figure out how to change the line color I got this question as well. just my 5cnts. :)
 
Top