StackPolicy (or how to prevent Markers being drawn on top of one another)

Spin

Well-known member
Joined
May 22, 2019
Posts
478
Likes
191
Hello fellow programmers,

I have been struggling with the following issue for some time now, so I reach out to the esteemed panel on this forum :)

I have a study that draws markers on the main plot when certain conditions are met. Sometimes more than one marker is drawn above or below the same bar, like so:

53

I would like to stop this from happening, and have the diamond and the arrow vertically separated.

This is the code that I use now:
Code:
if (ma9 >= ma15)

    {
        MarkerInfo marker = getSettings().getMarker(MARKER12);
        if (marker.isEnabled())
            addFigure(CHECK_PLOT, new Marker(d3, Enums.Position.CENTER, marker));
    }

As you can see, I use 'addFigure' from the class 'Study'. I noticed the subclass 'SinglePointFigure' (of class 'Draw') contains "SetStackPolicy", but I cannot for the life of me figure out how to implement this :unsure:

Please help. Thanks !
 

Nudge

Member
Joined
May 22, 2019
Posts
17
Likes
6
Have you tried setting the y coordinate on the second marker a point or 2 lower than the first marker?
 

Spin

Well-known member
Joined
May 22, 2019
Posts
478
Likes
191
Sometimes one can no longer see the forest, because too many trees block the sight :rolleyes:

That worked out quite well. Thank you Nudge for that, eeerm, nudge into the right direction ! (y)

55

One remark though (for others / my own future reference):
addFigure - Marker uses the price as y coordinate (instead of the 'true' coordinate in the window), so adding a +5 or even a +1 makes the markers jump very high / low.

So I used a factor of the price to offset the y:

Code:
Coordinate c_dia=new Coordinate(series.getStartTime(index), (series.getHigh(index) * 1.0008));
addFigure(Plot.PRICE, new Marker(c_dia, Enums.Position.TOP, marker));
 
Last edited:
Top