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

Message ListMessage List     Post MessagePost Message

  Candlestick Graph attributes
Posted by Marcelo Camarate on Mar-27-2006 02:43
Hi Peter,

Thank you very much for your last explanations. I need two more elucidations.

1) How can I attribute a name to a Candlestick Graph as in a Line Graph in c.addLineLayer(data, color, NAME, depth)?

2) How can I modify the color of the outline and of the wick in a Candlestick Graph?

Thanks,
Marcelo

  Re: Candlestick Graph attributes
Posted by Peter Kwan on Mar-27-2006 14:21
Hi Marcelo,

>
> 1) How can I attribute a name to a Candlestick Graph as in a Line Graph in c.addLineLayer(data, color, NAME, depth)?
>

I assume you are using the FinanceChart object.

The addCandleStickLayer does not have a "name" for the layer, because each chart typically only has one candlestick layer, thus there should be no particular need to distinguish the candles on the legend box. Also, a candlestick layer has multiple colors, so it is not known what color to use if we should show the candlestick layer on the legend box.

For the FinanceChart object, there is also already a High/Low/Open/Close entry in the legend box to indicate the prices. It is believe that anyone who knows what is a candlestick should know what does it means.

So for your case, would you please inform me why you need a name associated with the CandleStick layer? If it is for the purpose of additional legend key, I suggest you may use LegendBox.addKey to add the key to the legend box directly. If it is for other purpose, please kindly let me know of the purpose to see if I can find a solution to the issue.

>
> 2) How can I modify the color of the outline and of the wick in a Candlestick Graph?
>

For the FinanceChart object, first get the CandleStick layer object, then set the data set colors as follows:

'Add the candlestick layer
Set layer = financeChartObj.addCandleStick(&Hff00, &Hff0000)

Call layer.getDataSet(0).setDataColor(riseColor, boxBorderColor)
Call layer.getDataSet(1).setDataColor(fallColor, centerLineColor)

riseColor = fillColor of candle for up days
fallColor = fillColor of candle for down days
boxBorderColor = border color of the candle box
centerLineColor = the vertical line color at the center of the candle symbol

Regards
Peter Kwan

  Re: Candlestick Graph attributes
Posted by Marcelo Camarate on Mar-27-2006 22:08
Attachments:
Hi Peter,

In reason in my chart to be permitted more of a Candlestick Graph, as well as several Line Graphs, I need to know in which graph the mouse was positioned to show which the corresponding values, through the MouseMoveHotSpot event. Something as shown below.

Thanks,
Marcelo
Values.jpg

  Re: Candlestick Graph attributes
Posted by Peter Kwan on Mar-28-2006 02:29
Hi Marcelo,

There are many methods to identify the type of object the mouse is on. The exact details depend on how your image map is configured. Assuming you are the default image map attributes, I can think of two methods:

1. Check if the "high" attribute exists in the image map. Only a candlestick layer can have the "high", "low", "open", "close" attribute.

or

2. If the hot spot has no name, then assume it is the candlestick layer.

Hope this can help.

Regards
Peter Kwan

  Re: Candlestick Graph attributes
Posted by Soraya on Mar-19-2010 00:37
Marcelo,
You pass the mouse over the point and displays the point value in a label above, right?
You do this with the hotspot, right?
But you use the ImageMap? Why not see the tooltip on your image.
I need something like this. Can you help me answering as you do in your code?
Thank you!
Soraya

  Re: Candlestick Graph attributes
Posted by albruno on May-27-2009 23:59
Peter,

I am able to change the wick color as you describe

i just want to validate
that to change a wick color or border color that i must include the direction of the rise and fall color in the two calls.


as opposed to any method that i am unaware,
that includes just the rise or fall color ---along with box and center color in one call?
(grouped together)


ex:
layer.getDataSet(X).setDataColor(risecolor, centerLineColor, boxBorderColor)
layer.getDataSet(X).setDataColor(fallcolor, centerLineColor, boxBorderColor)

  Re: Candlestick Graph attributes
Posted by albruno on May-28-2009 10:34
Attachments:
should have posted this image for foundation...
how would you aproach this...

i am only interested in changing the wick and box/border color

what is the easiest method?
cd_4.png

  Re: Candlestick Graph attributes
Posted by Peter Kwan on May-29-2009 01:04
Hi Albruno,

A single candlestick layer in ChartDirector can only have 4 colors for the candlesticks

(a) The fill color for "up" candlesticks
(b) The fill color for "down" candlesticks
(c) The border color of the candle body (both up and down candlesticks must use the same border color)
(d) The stick color (both up and down candlesticks must use the same stick color)

In your case, you can have 4 type of candlesticks:

- A completely red filled candlestick
- A hollow green candlestick
- A completely filled grey candlestick
- A hollow grey candlestick

Also, it is not trivial to me how you can determine when to use which type of candle. So it needs to be considered as a special chart using a special coloring method.

To achieve the special color scheme you need, I suggest you way use 3 candlestick layers:

(i) A layer for the red filled candlesticks (border/stick/fill colors are all red)
(ii) A layer for the green hollow candlesticks (border/stick colors = green , fill color = black)
(iii) A layer for the grey filled and hollow candlesticks (border/stick colors = grey. fill color for "up" candlesticks = grey. fill colors for "down" candlesticks = black; you may force a candlestick to be filled as an "up" candlesticks by making sure close >= open - you may swap the open and close price if necessary).

Alternatively, you may simply use 4 layers for the 4 types of candlesticks you are using.

Hope this can help.

Regards
Peter Kwan

  Re: Candlestick Graph attributes
Posted by Matt on Mar-19-2010 00:05
I was able to have the same fill/stick/border color by doing the following in PHP.

$layer = $m->addCandleStick(Transparent, Transparent);
$layer->getDataSet(0)->setDataColor(0xff0000, SameAsMainColor);
$layer->getDataSet(1)->setDataColor(0x00ff00, SameAsMainColor);

However, I was wondering how I can achieve the hollow green effect as illustrated in
above image ( border=green; stick=green; fill=black )

Thanks!
-Matt

  Re: Candlestick Graph attributes
Posted by Peter Kwan on Mar-19-2010 23:32
Hi Matt,

Suppose you want to have two kinds of candles:

(a) Red fill, red border.
(b) Black fill, green border

You would need to use two layers, like:

#red solid fill, red border
$layer = $c->addCandleStick(-1, -1);
$layer->getDataSet(0)->setDataColor(0xff0000, SameAsMainColor);
$layer->getDataSet(1)->setDataColor(Transparent, SameAsMainColor);

#black solid fill, green border
$layer2 = $c->addCandleStick(-1, -1);
$layer2->getDataSet(0)->setDataColor(Transparent, 0x00ff00);
$layer2->getDataSet(1)->setDataColor(0x000000, 0x00ff00);

Hope this can help.

Regards
Peter Kwan

  Re: Candlestick Graph attributes
Posted by Matt on Mar-20-2010 02:45
Super! Two follow-up questions: :)

1. Can I apply the same scheme on the volume bar? Right now, I'm using
addVolIndicator(....). I know it returns XYChart and don't know how to proceed from there.

$m->addVolIndicator($height, 0xff0000, 0x00ff00, 0xffffff);

2. Regarding the candlestick color, I'm wondering if I can add another layer/color? Right
now, it's red/green, I want to use blue color on certain days, for example, open minus
close is over 10. How do I specify that data set considering dataSet(0) for up and
dataSet(1) for down.

$layer3 = $c->addCandleStick(-1, -1);
$layer3->getDataSet(?)->setDataColor(Transparent, 0x0000ff); // blue
$layer3->getDataSet(?)->setDataColor(0x000000, 0x0000ff);  // blue

Thanks a million!

-Matt

  Re: Candlestick Graph attributes
Posted by Peter Kwan on Mar-20-2010 13:29
Hi Matt,

For the candlesticks, if you want to add some special candlesticks to some location, you may use addCandleStickLayer and specify the positions directly. For example, in ChartDirector for PHP Ver 5:

# Add the main chart with 240 pixels in height
$m = $c->addMainChart(240);

# Add an HLOC symbols to the main chart, using green/red for up/down days
$layer = $c->addCandleStick(Transparent, 0xff0000);
$layer->getDataSet(0)->setDataColor(0xff0000, SameAsMainColor);
$layer->getDataSet(1)->setDataColor(Transparent, SameAsMainColor);

#black solid fill, green border
$layer2 = $m->addCandleStickLayer($highData, $lowData, $openData, $closeData, Transparent, 0xffffff, 0x00ff00);

#special blue candlesticks
$layer3 = $m->addCandleStickLayer($blueHighData, $blueLowData, $blueOpenData, $blueCloseData, 0x0000ff, 0x0000ff, 0x0000ff);
#move it in front of the first layer
$layer3->moveFront($layer);

In the above example, $blueHighData, $blueLowData, etc... are the positions you want to put the blue candlesticks. You may use the same data as in your original candlestick layer. If the blue candlesticks only appear on some days, you may use NoValue as the data values on the days that does not have the blue candlestick.

For the volume bars, you may use:

$v = $c->addVolIndicator(........);

The $v is an XYChart object, just like the $m above. You may use XYChart.addBarLayer to add bars with any colors you want in any positions you want (similar to the $layer3 above).

Hope this can help.

Regards
Peter Kwan

  Re: Candlestick Graph attributes
Posted by Matt on Mar-23-2010 08:13
Great! Can you explain in a little details about how to configure volume bar border? I got
an XYChart object by the following statement:

$v = $c->addVolIndicator($height, 0xff0000, 0x00ff00, 0xffffff);

Then, I try to use XYChart.addBarLayer to add bars. Both addBarLayer(data) and
addBarLayer3() require data parameter. How can I get the data from $c?

Without knowing how to get the data set, I used addBarLayer2() as follows and it failed,

$xyLayer = $v->addBarLayer2();
$xyLayer->getDataSet(0)->setDataColor($upColor, SameAsMainColor);
$xyLayer->getDataSet(1)->setDataColor(Transparent, SameAsMainColor);

Fatal error: Call to a member function getDataSet() on a non-object in...

Thanks!

-Matt

  Re: Candlestick Graph attributes
Posted by Peter Kwan on Mar-24-2010 00:27
Hi Matt,

If you want some bars to be specially colored (including using a special fill color or special border color), there are two methods:

(a) Modify the FinanceChart class library.

The FinanceChart class library is open source as "FinanceChart.php" so as to allow people to modify it for their own needs. If you look at the "FinanceChart.php" source code, you will find that the volume bars are actually added in addVolBars2. Near the bottom of the code, you can find 3 data sets, $flatDS, $upDS and $dnDS. You can modify the fill and border color to fit you needs.

(b) You may use the same method as how the "blue" candlestick is achieved in my previous message.

First, create an array that contains the volume data for the bars that you want to color specially. The array element should contain either the volume data value or NoValue, depending on whether the bar needs to be specially colored or not.

Then you may add a bar layer using that array:

$v = $c->addVolIndicator($height, 0xff0000, 0x00ff00, 0xffffff);
$layer = $v->addBarLayer($specialBars, $specialFillColor);
$layer->setBorderColor($specialBorderColor);
$layer->moveFront();

Hope this can help.

Regards
Peter Kwan

  Re: Candlestick Graph attributes
Posted by Matt on Mar-24-2010 09:09
Attachments:
Cool! I try to modify the addVolBars2 as the following, however all the volume bars have
the same border. For red bar, I prefer to have red/darkred color rather than green color.

$tmpArrayMath1 = new ArrayMath($this->m_volData);
$tmpArrayMath1->selectGTZ($closeChange);
$upDS = $barLayer->addDataSet($tmpArrayMath1->result(), $upColor);
$barLayer->setBorderColor($upColor);

$tmpArrayMath1 = new ArrayMath($this->m_volData);
$tmpArrayMath1->selectLTZ($closeChange);
$dnDS = $barLayer->addDataSet($tmpArrayMath1->result(), 0x000000);  // fill black
$barLayer->setBorderColor($downColor);

Any suggestions? BTW, is possible to change the legend color on the up left corner? it's
black now, can I change to red/green?

Thanks a million!

-Matt
vol.tiff
vol.tiff

14.37 Kb

  Re: Candlestick Graph attributes
Posted by Matt on Apr-06-2010 13:54
Attachments:
I realized that the candlesticks are overlapped after adding two candlestick layers (see the
attached image). This doesn't occur to the default candlestick chart. I tried to modify
lib/FinanceChart.php to adjust data gap, however it did not work well for different date
range, e.g. 1 year and 2 years.. Can you suggest how to set data gap properly?


function addCandleStick($upColor, $downColor) {
        $this->addOHLCLabel($upColor, $downColor, true);
        $ret = $this->m_mainChart->addCandleStickLayer($this->m_highData, $this-
>m_lowData,
            $this->m_openData, $this->m_closeData, $upColor, $downColor);
        $ret->setHTMLImageMap("", "", $this->getHLOCToolTipFormat());
        if (count($this->m_highData) - $this->m_extraPoints > 60) {
            $ret->setDataGap(0);
        }

       if (count($this->m_highData) > $this->m_extraPoints) {
            $expectedWidth = ($this->m_totalWidth - $this->m_leftMargin - $this-
>m_rightMargin) / (
                count($this->m_highData) - $this->m_extraPoints);
            if ($expectedWidth <= 5) {
                $ret->setDataWidth($expectedWidth + 1 - $expectedWidth % 2);
            }
        }

        return $ret;
    }

Thanks!
-Matt
overlap.jpg

  Re: Candlestick Graph attributes
Posted by Peter Kwan on Apr-07-2010 01:07
Hi Matt,

Sorry. I seem to have forgotten to respond to your previous enquiry (about the border of the volume bars). For your previous case, instead of setting the border of the entire bar layer, you may set the colors of individual data sets, like:

$tmpArrayMath1 = new ArrayMath($this->m_volData);
$tmpArrayMath1->selectGTZ($closeChange);
$upDS = $barLayer->addDataSet($tmpArrayMath1->result());
$upDS->setDataColr($upColor, $upColor);

$tmpArrayMath1 = new ArrayMath($this->m_volData);
$tmpArrayMath1->selectLTZ($closeChange);
$dnDS = $barLayer->addDataSet($tmpArrayMath1->result());
$dnDS ->setBorderColor(0x000000, $downColor);

Since you have an icon with the text "Vol: 18.07M" in your chart, there must be some code somewhere that adds the legend entry. In the original FinanceChart code, the legend entry should be set using $upDS->setDataName or $dnDS->setDataName or $flatDS->setDataName, depending on which data set contains the last bar. The icon will be filled with the fill color of that data set. If the fill color is black, the icon is black.

If you want the icon to be some other color, you may add an empty data set that uses the color you want, and adds the legend entry using that data set.

$myIconEntry = $barLayer->addDateSet(null, $myIconColor);
$myIconEntry->setDataName($label);

For the width of the candlestick, I am not sure how you currently set the width. If I were to set the gap, I will just use:

$layer->setDataGap(0);

and apply the above to all candlestick layers.

Hope this can help.

Regards
Peter Kwan

  Re: Candlestick Graph attributes
Posted by Alden on Nov-04-2010 19:52
Hi Peter,

I've studied the posts above and tried adding layers to get the desired candlestick colours
(green for up and red for down), but can't seem to solve the following problem: The
borders and sticks are green for both the up/down candlesticks.

My code (in java) is:

    FinanceChart c = new FinanceChart(width);

// green fill, border and stick for up candlesticks
    Layer up_layer = c.addCandleStick(-1, -1);
    up_layer.getDataSet(0).setDataColor(0x8000, 0x8000);
    up_layer.getDataSet(1).setDataColor(-1, 0x8000);

// red fill, border and stick for down candlesticks
     Layer dn_layer = c.addCandleStick(-1, -1);
     dn_layer.getDataSet(0).setDataColor(-1, 0xcc0000);
     dn_layer.getDataSet(1).setDataColor(0xcc0000, 0xcc0000);

How can I solve this so that up days have green body/fill/border/sticks and down days
have red body/fill/border/sticks. Also, the red for the down days appears washed out
(faded) due to green underneath?

Thanks,
Alden

  Re: Candlestick Graph attributes
Posted by Peter Kwan on Nov-05-2010 00:10
Hi Alden,

If you want the up days to have green body/fill/border/sticks and down days to
have red body/fill/border/sticks, you just need to set the border color to Chart.SameAsMainColor. For example:

Layer layer = c.addCandleStick(-1, -1);
layer.getDataSet(0).setDataColor(0x8000, Chart.SameAsMainColor);
layer.getDataSet(1).setDataColor(0xcc0000, Chart.SameAsMainColor);

Hope this can help.

Regards
Peter Kwan

  Re: Candlestick Graph attributes
Posted by Alden on Nov-05-2010 00:23
Brilliant, works like a charm! So simple when you know how :)

Thanks!