IronPython conditioned coloring and averages

I am trying to take an average of gray curves only using manipulation with axis, not using a computed column, so it would respond to filtering. Please see the picture. 

The average curve is usually computated as following: 

Avg([ColumnValue]) over (All([Axis.Line])) then Sum([Value]) over (AllPrevious([Axis.X])) as [TrendLine]

This expression does not work, because I colored the curves manually, so Spotfire does not understand which curves are together and which are not. So I am trying to use conditional coloring using IronPython, and it doesn't work. 

Here is my code - I found it online. When I use it, the code runs, but Spotfire colors all curves blue instead of selecting the 5 curves with the highest value red. I presume it coloros it blue, becuase it is a default coloring for empty values. How do I fix it. 

I food prefer Boolean operator such as: If MyValue >=120000 then color all curves Red. Else color all of them blue. I do not know how to code it in IronPython. I tried to include rules for coloring in Properties. But it is a Line Chart, so it does not allow me to have this option. 

# ColorTop5

# Set the color for the top 5 values in a color by column.

from Spotfire.Dxp.Application.Visuals import *

from Spotfire.Dxp.Application.Visuals.ConditionalColoring import *

from System.Drawing import Color

# Get the visualization reference

for visualization in Document.ActivePageReference.Visuals:

if visualization.Title == "MyColumnName":

visualContentObject = visualization.As[VisualContent]()

# Clear any existing coloring visualContentObject.ColorAxis.Coloring.Clear()

# Add the color rule

visualContentObject.ColorAxis.Coloring.AddTopNRule(5, Color.FromName("Red"))


Image icon average.png68.22 KB