DYO: Select a marker's color

Q:  Why not have a dual color histogram marker like the Blue/Red curve line marker?

A:  Here is a dummy example for the sake of illustration to show how to select a color for a marker.

Oft times I have seen users struggle with selecting a color based on some value.   Their approach has been to use a bunch of Do Next If flag tests to skip a line when the test fails.  The multiple Do Next If line pairings are being used to basically plot the same marker in different colors.  Well, there is an easier way to accomplish setting the color to use.

In this example, Line A through Line D are tests and when they are True, they do not plot any marker, yet I have the Show box checked.  What they are accomplishing is setting the color in a paint can used by this DYO.  When Show is checked, and the Marker is BLANK, this combination will remember the color from this line by defining the color in the form's paint can.

So, say our GV[2] value is 2.5 and we start done through the DYO logic.  Line A is True, and the color loaded into the paint can is the orange color.  Then Line B is evaluated and is also True, so the color loaded into the paint can is the darker orange, replacing the orange.  Lines C and D are False, so no color transfer is done.

Now for the trick.   When a color box is BLACK, and the paint can has been loaded through the use of the blank marker, the DYO will use the color in the paint can instead of the color BLACK.  So Line E is painting its curve segment in one of 4 colors from orange, to dark red.   The paint can is initialized to Black, so if none of the tests had changed the paint can's color, then the curve marker color would have been black.

Black for the marker color is just the tag color to use the form's paint can.   In this example we have 4 tests, 4 colors, and a single line to plot the Value.  The value tested and plotted is coming from GV [2].   What I am teaching is the special effect you can implement by having Show checked, and the Marker blank.  This loads a special paint can, remembers this line's color which can be used later by any marker trying to paint with the Black color box selection.  If you do not load this special paint can in this manner, painting with the color black will indeed paint with black.  The special paint can is preloaded with the color black.

In this example, if Value is a zero or negative, none of the tests will be true and the curve will be painted with black.  If Line E had a label, the label would have used the loaded paint can color as well.  In summary, pick the color by having Show be checked, and the Marker be blank.  Use the selected color by selecting Black as the color for the marker after the color has been picked.  If a color has not been picked, black will paint with black as the default.  The paint can concept should lead to DYO code reduction for selecting from multiple colors.

Let me show another simple example

Here is an example of plotting the average line in Red or Green.   Yes we can do it directly on the study property form, but I am using the DYO example to teach about color selection.   Line A primes the paint can with Red.  The Line B test for the study line to be Rising (ascending) can change the color bucket to green.  Now Line C plots the curve using the selected color, which will be either Red or Green, but not black   The visual result is the EMA line in the chart (top curve line) is red when descending and green when rising.

read more » DYO:  Change a Study's Color Based on a Criteria