ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Line segments with alternating colors
Posted by albruno on May-26-2009 18:36
Is it currently possible to do the following:


Can I create line segments, where the beginning of the segment is in the middle of the chart?

Can I alternate colors bar-by-bar (if needed) of a segment (or plot-point to plot-point)?

How do you no-plot a segment or bar or make the segment transparent in color?

  Re: Line segments with alternating colors
Posted by Peter Kwan on May-27-2009 01:58
Hi Alburno

Can I create line segments, where the beginning of the segment is in the middle of the chart?

Yes. Please refer to the "Missing Data Points" sample code for an example. (You may look for "Missing Data Points" in the ChartDirector documentation index.) You can see one of the line does not start from the left, but from the middle of the chart.

Can I alternate colors bar-by-bar (if needed) of a segment (or plot-point to plot-point)?

I am not too sure the exact arrangement of the bars you need. If you are using a simple bar chart, you may configure the color of each bar using addBarLayer3. See the "Color Bar Chart" sample code.

If you are using a "stacked bar chart", and you want to change the color of one of the segments of the bar, you need to create one data set for each color you want to use. For example, if in a stacked bar chart with 2 bars, the first stacked bar is "red / blue", and the second stacked bar is "red / green", in total you need 3 data sets because there are 3 colors. If a color is not used in a certain bar, just fill the value of the data set at the corresponding position with NoValue.

How do you no-plot a segment or bar or make the segment transparent in color?

I am not exactly sure what is "no-plot" mean. I assume it mean transparent. (A stacked bar with a transparent segment will look like there is a "gap" in the bar. In other words, the transparent segment will still occupy space, but it is not visible.)

To create a stacked bar with a transparent segment, just create the stacked bar normally, but with one data set using the transparent color.

Hope this can help.

Regards
Peter Kwan

  Re: Line segments with alternating colors
Posted by albruno on May-27-2009 02:11
Attachments:
Can I alternate colors bar-by-bar (if needed) of a segment (or plot-point to plot-point)?



referencing alternating colors for line segments:

this is a standard feature in most financial trading platforms...

where for example
you have a moving average

and you want to change the colors of the plots or segments as the average rises or falls

so that a direction is more visible

this was done in tradestation.
cd_4.png

  Re: Line segments with alternating colors
Posted by albruno on May-27-2009 02:29
Attachments:
i posted this too in a thread on candles....

Financial Candle charts

* Is it possible to plot the bars in more than two colors?

i am guessing that i need to build several data feeds in advance to achieve this?
and overlay    ..some with missing bars?

below
this particular method does not value O,H,L,C of a bar for coloring a bar,

but uses logic algorithm for trending colors.

again this is from Tradestation...
cd_3.png

  Re: Line segments with alternating colors
Posted by Peter Kwan on May-27-2009 19:20
Attachments:
Hi Albruno,

From your attached chart, I think I mis-understand what is meant by a "bar" in your earlier message. I was think about a bar as in a bar chart. I am aware in financial charts, sometimes a bar can refer to a "candlestick", an OHLC symbol, or some other price symbols.

For line charts with multi-color segments, you would need to split your data series into multiple series, one for each color. I am not sure what algorithm you are using to color the lines. I remember someone in this forum posted a piece of code that color the segments based on whether it is "rising" or "falling". It splits the data into 4 series instead of 2, but I think the algorithm is efficient. It is like:

#
#assume the original data array is in "data"
#split into arrays for red and green line segments
#

#initialize the arrays
redLine = [[NoValue] * len(data), [NoValue] * len(data)]
greenLine = [[NoValue] * len(data), [NoValue] * len(data)]

#the actual splitting code
for i in range(1, len(data)) :
    #the algorithm used to pick the color
    if data[i - 1] >= data[i] :
        selectedLine = redLine
    else :
        selectedLine = greenLine
    #copy the data to that line
    selectedLine[(i % 4) / 2][i - 1] = data[i - 1]
    selectedLine[(i % 4) / 2][i] = data[i]

# Add a line layer to the chart
layer = c.addLineLayer2()
for i in (0, 1) :
    layer.addDataSet(redLine[i], 0xff0000)
    layer.addDataSet(greenLine[i], 0x008800)

I think you can modify the code above to use your own method to color the line segments.

For the bars (candles in the candlesticks), if you are using a special coloring algorithm, you would need to split your data series into multiple data series, one for each coloring scheme (remember to use NoValue to initialize the data arrays).

Hope this can help.

Regards
Peter Kwan
multiline.png

  Re: Line segments with alternating colors
Posted by albruno on May-27-2009 20:37
Attachments:
Peter,
Thank you it was a big help!


A bar on financial charts is also 'slang' for any increment:
by time, tick, share, (or synthetic etc...) on a chart.


my example:
since i did not want the entire range of of bars plotted
I read through the file and then filtered to take the last x range of bars
so i have two counters x and cnt


red    = 0xff0000
green = 0x00ff00

Up     = []
Dn     = []

cnt    = -1 # counter

~~~~~
#.... looping and filtering to select range of bars or plot increments

Up.append(NoValue)
Dn.append(NoValue)

cnt+=1
if cnt ==0:
Up[cnt]= data[x]) # first record
if cnt >= 0:
if data[cnt]   > data[x-1]:
Up[cnt]    = data[x]
Up[cnt-1] = data[x-1] #backplot
else:
Dn[cnt]    = data[x]
Dn[cnt-1] = data[x-1] #backplot

# end of loop....


# Add line layer to the chart
lineLayer= c.addLineLayer()

lineLayer.addDataSet(Dn, red, "Dn")
lineLayer.addDataSet(Up, green, "Up")
lineLayer.setLineWidth(1)
cd_1.png

  Re: Line segments with alternating colors
Posted by Peter Kwan on May-29-2009 00:35
Hi albruno,

The method you use to split the data into two data sets may not work:

lineLayer.addDataSet(Dn, red, "Dn")
lineLayer.addDataSet(Up, green, "Up")

To illustrate, consider a data series with only 4 points [100, 50, 100, 50]. You can see that there are 3 line segments. The first and third line segments are down segments, and the second segment is an up segment. So the "Up" data series is:

[NoValue, 50, 100, NoValue]

while the "Dn" data series is:

[100, 50, 100, 50]

But then the "Dn" data series is the same as the original line, which contains 1 up data segment. Therefore the "Dn" data series is incorrect.

That is why in the code suggested in my earlier message, the data are splitted into 4 arrays instead of 2. If you use the code in my previous message, the data series will be:

up[0] = [NoValue, NoValue, NoValue, NoValue]
up[1] = [NoValue, 50, 100, NoValue]
down[0] = [100, 50, NoValue, NoValue]
down[1] = [NoValue, NoValue, 100, 50]

This will then produce the correct chart - 1 up segment and 2 down segments.

Hope this can help.

Regards
Peter Kwan

  Re: Line segments with alternating colors
Posted by albruno on May-29-2009 00:46
the code above works well
...i submitted it to help others


i have actually split it into 3 data sets (3 colors) with no problems

~~~

I populate the all overlay collections with NoValue first

then as a signal direction is changing

I  change the arrays previous and current data - that apply

to get a segment that has color starting from the period before



Thanks...
your product is easy to code once you understand the concept
...have more questions but not on this concept