Changing plot colour on the fly problem  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
Sylpha
Posts: 29
Joined: 14 Apr 2015
Has thanked: 1 time

Changing plot colour on the fly problem

Postby Sylpha » 23 Jun 2015

I have tried to change the plot colour based on the indicator value is rising or falling, however it doesn't quite working during the turning point.

Attached the screen shot.

The code is like:

if (hmaSeries[0]>=hmaSeries[1]) {
hmaPlot.Set(0, hmaSeries[0], Color.LightGreen);
} else {
hmaPlot.Set(0, hmaSeries[0], Color.Red);
}
The code to initialize the plot:

hmaPlot = AddPlot(new PlotAttributes("HMA", EPlotShapes.Line, Color.White, Color.Empty, 0, 0, true));


The problem is the plot will still using the previous colour at the 1st bar after turning happened.

The indicator value on the screen from left to right are:

23617
23594
23727
23878

You will see on the screen shot, the line between 2nd and 3rd bar are still in red colour which is wrong. It should be in green colour instead. Any clue about this?
Attachments
Screen Shot 2015-06-23 at 8.20.40 pm.jpg
(8.58 KiB) Downloaded 1086 times

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Changing plot colour on the fly problem

Postby JoshM » 23 Jun 2015

I suspect that this is expected behaviour; if I recall correctly there were also topics about this with the regular MultiCharts edition, although I cannot find them now.

Anyway, try displacing the plot. I think that would give the behaviour you're after (if I understand you correctly). So change the code to:

Code: Select all

if (hmaSeries[0]>=hmaSeries[1]) {
hmaPlot.Set(1, hmaSeries[0], Color.LightGreen);
} else {
hmaPlot.Set(1, hmaSeries[0], Color.Red);
}
(The difference is in the 1 in the `Set()` method as opposed to a 0).

Sylpha
Posts: 29
Joined: 14 Apr 2015
Has thanked: 1 time

Re: Changing plot colour on the fly problem

Postby Sylpha » 23 Jun 2015

I suspect that this is expected behaviour; if I recall correctly there were also topics about this with the regular MultiCharts edition, although I cannot find them now.

Anyway, try displacing the plot. I think that would give the behaviour you're after (if I understand you correctly). So change the code to:

Code: Select all

if (hmaSeries[0]>=hmaSeries[1]) {
hmaPlot.Set(1, hmaSeries[0], Color.LightGreen);
} else {
hmaPlot.Set(1, hmaSeries[0], Color.Red);
}
(The difference is in the 1 in the `Set()` method as opposed to a 0).
Thanks for your advice, however displacement will distort the chart...the value has to calculate & show using current bar, if I move it the left by one bar then the future value will be displayed on current bar which doesn't sound right to me...

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Changing plot colour on the fly problem

Postby Henry MultiСharts » 24 Jun 2015

Hello Sylpha,

If you want us to check this case please attach the complete code of the study and the workspace you are using.

Sylpha
Posts: 29
Joined: 14 Apr 2015
Has thanked: 1 time

Re: Changing plot colour on the fly problem

Postby Sylpha » 25 Jun 2015

Hi Henry,

Attached the workspace and the indicator.
Attachments
export.zip
(32.33 KiB) Downloaded 300 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Changing plot colour on the fly problem  [SOLVED]

Postby Henry MultiСharts » 29 Jun 2015

Hello Sylpha,

The color between the bars is the one from the last calculation. There is no way to change the plot color between the bars as there is no study calculation there. On the next bar will be another calculation and another color will be plotted after it.


Return to “MultiCharts .NET”