Page 1 of 1

Changing plot colour on the fly problem

Posted: Jun 23 2015
by Sylpha
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?

Re: Changing plot colour on the fly problem

Posted: Jun 23 2015
by JoshM
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).

Re: Changing plot colour on the fly problem

Posted: Jun 23 2015
by Sylpha
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...

Re: Changing plot colour on the fly problem

Posted: Jun 24 2015
by Henry MultiŠ”harts
Hello Sylpha,

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

Re: Changing plot colour on the fly problem

Posted: Jun 25 2015
by Sylpha
Hi Henry,

Attached the workspace and the indicator.

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

Posted: Jun 29 2015
by Henry MultiŠ”harts
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.