Page 1 of 1
Same Horizontal Axis for Multiple Series etc etc
Posted: Tue Mar 15, 2005 11:24 pm
by 9236155
I have Series 1 (Candle Series), Series 2 (TVolume) & Series3 (TRSI). I request for ideas/suggestions to do the following:-
1. How can I specify same horizontal axes for all three series ?
2. Also when I plot Series1 & Series 2 together the volume series does not vertically coincide with the price chart (HLC) - what could be the reason for this and how could I correct this ?
3. I am drawing Price Chart using UpColor & DownColor. How can I use the same logic for corresponding volume bars also -eg a green price bar (UpClose) should have green volume bar and a red price bar (DownClose) should have a red volme bar. I am able to get differnet colors for HLC/Candle series but not for Volume series.
I will be extremely grateful for any guidance that you all could give.
Regards,
Satish
Posted: Wed Mar 16, 2005 11:57 am
by narcis
Hi Satish,
1. How can I specify same horizontal axes for all three series ?
It already is the default value. However you can specify the Horizontal axis for a series programatically or in the chart editor at the Series>General tab.
2. Also when I plot Series1 & Series 2 together the volume series does not vertically coincide with the price chart (HLC) - what could be the reason for this and how could I correct this ?
I don't understand what do you exactly mean. Could you please be more specific and send us a small project we can run "as-is" to reproduce the problem here or an image illustrating this problem? You can send any file at [url]news://
www.steema.net/steema.public.attachments[/url] newsgroup.
3. I am drawing Price Chart using UpColor & DownColor. How can I use the same logic for corresponding volume bars also -eg a green price bar (UpClose) should have green volume bar and a red price bar (DownClose) should have a red volme bar. I am able to get differnet colors for HLC/Candle series but not for Volume series.
Yes, you can do something like:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
Series1.FillSampleValues(); //Volume Series
Series2.FillSampleValues(); //Candle Series
Series2.DownCloseColor:=clRed;
Series2.UpCloseColor:=clBlue;
Series1.ColorEachPoint:=true;
for i:=0 to Series2.Count - 1 do
begin
if (Series2.OpenValues[i] < Series2.CloseValues[i]) then
Series1.ValueColor[i]:=Series2.UpCloseColor
else
Series1.ValueColor[i]:=Series2.DownCloseColor;
end;
end;
Posted: Fri Mar 18, 2005 2:06 am
by 9236155
Thanks Narcis. Here is the code stub I am using for raeding stocks data from a random access file. I am sure there is something wrong in reading volume data. Also I am attaching the graphic output to show the lateral shift between HLC price and Volume charts (to my mind they must coincide as they have same X Axis - date)
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, TeEngine, Series, OHLChart, CandleCh, ExtCtrls, TeeProcs, Chart,UMyStocksLib,
StdCtrls,TeeTools, StatChar;
type
TFChartMain = class(TForm)
Chart1: TChart;
Series1: TCandleSeries;
Panel1: TPanel;
Panel2: TPanel;
Button1: TButton;
Button2: TButton;
MyCursor:TCursorTool;
Series2: TLineSeries;
TeeFunction1: TExpMovAveFunction;
Series3: TLineSeries;
TeeFunction2: TExpMovAveFunction;
Series4: TVolumeSeries;
MiddleAxis:TChartAxis;
BottomAxis:TChartAxis;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure qtd2series(symbol:string;days:integer);
procedure readportfolio(portfolioname:string);
procedure cycleforward;
procedure cyclebackward;
procedure Chart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
ValueIndex: Integer; var LabelText: String);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FChartMain: TFChartMain;
portfolio:array of string;
allstocks:TStringList;
firststock,laststock,thisstock,days:integer;
procedure TFChartMain.qtd2series(symbol:string;days:integer);
var tmp,tmp4,cnt,firstrec,lastrec,i:integer;
tmpYear : Word;
tmpMonth : Word;
tmpDay : Word;
begin
fnm2:=datadir+'\'+symbol+'.qtd';
assignfile(f2,fnm2);
if fileexists(fnm2) then reset(f2,fnm2) else exit;
Series1.ParentChart:=chart1;
cnt:=days;
Chart1.Title.Text.Clear;
Chart1.Title.Text.Add(symbol);
if filesize(f2)<days then cnt:=filesize(f2);
// start with last record - latest data
lastrec:=filesize(f2)-1;
firstrec:=lastrec-cnt+1;
if firstrec<0 then firstrec:=0;
// TCandleSeries
Series1.Clear;
Series4.Clear;
{ no dates }
Series1.XValues.DateTime:=False;
for i:=firstrec to lastrec do
begin
seek(f2,i);
read(f2,drec);
// make sure computer Control Panel Regional Settings date format is set to MM/dd/yyyy for correct formatting
//ShortDateFormat:='mm/dd/yyyy';
tmp:=series1.addcandle(i,drec.open,drec.high,drec.low,drec.close);
//stor date as yyyymmdd string
DecodeDate(drec.date, tmpYear, tmpMonth, tmpDay );
Series1.Labels[ Series1.Count-1 ]:= FormatFloat('0000',tmpYear)+
FormatFloat('00',tmpMonth)+
FormatFloat('00',tmpDay);
//tmp4:=series4.Add(drec.volume,Series1.Labels[ Series1.Count-1 ]);
//tmp4:=series4.AddY(drec.volume);
tmp4:=Series4.AddY(drec.volume,Series1.Labels[ Series1.Count-1 ],clBlue);
end;
closefile(f2);
// needed if Series1 fed manually
Series2.CheckDataSource; // MA 1
Series3.CheckDataSource; // MA 2
// Candles and EMAs 1 & 2
Series1.VertAxis:=aLeftAxis;
Series2.VertAxis:=aLeftAxis;
Series3.VertAxis:=aLeftAxis;
// Volume & Volume MA Chart
Series1.GetVertAxis.EndPosition:=75;
Chart1.CustomAxes.Clear;
MiddleAxis := Chart1.CustomAxes.Add as TChartAxis;
MiddleAxis.StartPosition:=75;
MiddleAxis.EndPosition:=100;
MiddleAxis.Axis.Color:=clBlue;
Series4.CustomVertAxis:=MiddleAxis;
end;
====================================
extract from UMyStocksLib of drec structure
const datadir='c:\myportfolio';
maxsize=300; // size of dat array
type
drectype = record
date:TDateTime;
open,high,low,close:single;
volume:Int64;
end;
var
FMyStocksLib: TFMyStocksLib;
f1:textfile;
f2:file of drectype;
fnm1,fnm2,s1,s2,s3,s4,s5:string;
sno,fldnum:integer;
i:integer;
mstr:array[1..7] of string; // array for date,time,OHLC & volume
mdate:Tdatetime;
mopen,mhigh,mlow,mclose:single;
mvolume:longint;
drec:drectype;
dat:array[1..maxsize] of drectype;
allstocks: TStringList;
I will try coloring of volume bars once I am able to get this Xscale alignment right. Ooops - how do I attach the graphical output ? Can I send it by EMail - that will explain everything better.
Thanks for all the excellent suggestions you all are giving !!
Satish
Posted: Sat Mar 19, 2005 8:10 pm
by 9236155
Have been able to figure out the cause, I was using wrong syntax for adding to the volume series - have a perfectly aligned Price-Volume graphs now. Point closed.
Satish