📄 candlech.pas
字号:
else
Pen.Style:=psClear; // 7.0
tmpR.Left:=tmpX-tmpLeftWidth;
tmpR.Right:=tmpX+tmpRightWidth;
Cube(tmpR,StartZ,EndZ,Pointer.Dark3D);
TryDrawGradient(tmpR);
CheckHighLowPen;
{ Draw Candle Vertical Line from Top to High }
if FCandleStyle=csCandleStick then
VertLine3D(tmpX,tmpR.Top,yHigh,MiddleZ);
end
else
begin
{ Draw Candle Vertical Line from High to Low }
if FCandleStyle=csCandleStick then
if View3D then
VertLine3D(tmpX,yLow,yHigh,MiddleZ)
else
DoVertLine(tmpX,yLow,yHigh);
{ remember that Y coordinates are inverted }
{ prevent zero height rectangles 5.02 }
{ in previous releases, an horizontal line was displayed instead
of the small candle rectangle }
if yOpen=yClose then Dec(yClose);
{ draw the candle }
Brush.Color:=tmpColor;
if Self.Pen.Visible then
if yOpen=yClose then AssignVisiblePenColor(Self.Pen,tmpColor)
else AssignVisiblePen(Self.Pen)
else
Pen.Style:=psClear; // 7.0
if View3D then
begin
tmpR:=TeeRect(tmpX-tmpLeftWidth,yOpen,tmpX+tmpRightWidth,yClose);
TryDrawGradient(tmpR);
RectangleWithZ(tmpR,MiddleZ);
end
else
begin
if not Self.Pen.Visible then
if yOpen<yClose then Dec(yOpen) else Dec(yClose);
tmpR:=TeeRect(tmpX-tmpLeftWidth,yOpen,tmpX+tmpRightWidth+1,yClose);
TryDrawGradient(tmpR);
Rectangle(tmpR);
end;
end;
end
else
if FCandleStyle=csLine then // Line
begin
P:=TeePoint(tmpX,YClose);
tmpFirst:=FirstDisplayedIndex;
if (ValueIndex<>tmpFirst) and (not IsNull(ValueIndex)) then
begin
AssignVisiblePenColor(Self.Pen,tmpColor);
BackMode:=cbmTransparent;
if View3D then LineWithZ(OldP,P,MiddleZ)
else Line(OldP,P);
end;
OldP:=P;
end
else
begin // Draw Candle bar
AssignVisiblePenColor(Self.Pen,tmpColor);
BackMode:=cbmTransparent;
// Draw Candle Vertical Line from High to Low
if View3D then
begin
VertLine3D(tmpX,yLow,yHigh,MiddleZ);
if ShowOpenTick then HorizLine3D(tmpX,tmpX-tmpLeftWidth-1,yOpen,MiddleZ);
if ShowCloseTick then HorizLine3D(tmpX,tmpX+tmpRightWidth+1,yClose,MiddleZ);
end
else
begin // 5.02
DoVertLine(tmpX,yLow,yHigh);
if ShowOpenTick then DoHorizLine(tmpX,tmpX-tmpLeftWidth-1,yOpen);
if ShowCloseTick then DoHorizLine(tmpX,tmpX+tmpRightWidth+1,yClose);
end;
end;
end;
end;
Procedure TCandleSeries.SetUpColor(const Value:TColor);
Begin
FUpClose.StartColor:=Value;
end;
Procedure TCandleSeries.SetDownColor(const Value:TColor);
Begin
FDownClose.StartColor:=Value;
end;
Procedure TCandleSeries.SetCandleWidth(Value:Integer);
Begin
SetIntegerProperty(FCandleWidth,Value);
end;
Procedure TCandleSeries.SetCandleStyle(Value:TCandleStyle);
Begin
if FCandleStyle<>Value then
begin
FCandleStyle:=Value;
Pointer.Visible:=CandleStyle<>csLine;
Repaint;
end;
end;
class Function TCandleSeries.GetEditorClass:String;
Begin
result:='TCandleEditor'; // Do not localize
End;
Procedure TCandleSeries.GalleryChanged3D(Is3D:Boolean);
begin
inherited;
if Assigned(ParentChart) then
begin
DownCloseColor:=ParentChart.GetDefaultColor(0);
UpCloseColor:=ParentChart.GetDefaultColor(4);
end;
end;
Procedure TCandleSeries.PrepareForGallery(IsEnabled:Boolean);
Begin
inherited;
FillSampleValues(4);
ColorEachPoint:=IsEnabled;
if not IsEnabled then
begin
UpCloseColor:=clSilver;
DownCloseColor:=clDkGray;
Pointer.Pen.Color:=clGray;
end;
Pointer.Pen.Width:=2;
CandleWidth:=12;
end;
Procedure TCandleSeries.Assign(Source:TPersistent);
begin
if Source is TCandleSeries then
With TCandleSeries(Source) do
begin
Self.FCandleWidth :=FCandleWidth;
Self.FCandleStyle :=FCandleStyle;
Self.FColorStyle :=FColorStyle;
Self.UpCloseGradient:=FUpClose;
Self.DownCloseGradient:=FDownClose;
Self.HighLowPen :=FHighLowPen;
Self.FShowOpenTick :=FShowOpenTick;
Self.FShowCloseTick :=FShowCloseTick;
end;
inherited;
end;
Function TCandleSeries.GetDraw3D:Boolean;
begin
result:=Pointer.Draw3D;
end;
procedure TCandleSeries.SetDraw3D(Value:Boolean);
begin
Pointer.Draw3D:=Value;
end;
Function TCandleSeries.GetDark3D:Boolean;
begin
result:=Pointer.Dark3D;
end;
procedure TCandleSeries.SetDark3D(Value:Boolean);
begin
Pointer.Dark3D:=Value;
end;
Function TCandleSeries.GetPen:TChartPen;
begin
result:=Pointer.Pen;
end;
procedure TCandleSeries.SetCandlePen(Value:TChartPen);
begin
Pointer.Pen.Assign(Value);
end;
Function TCandleSeries.AddCandle( Const ADate:TDateTime;
Const AOpen,AHigh,ALow,AClose:Double):Integer;
begin
result:=AddOHLC(ADate,AOpen,AHigh,ALow,AClose);
end;
class procedure TCandleSeries.CreateSubGallery(
AddSubChart: TChartSubGalleryProc);
begin
inherited;
AddSubChart(TeeMsg_CandleBar);
AddSubChart(TeeMsg_CandleNoOpen);
AddSubChart(TeeMsg_CandleNoClose);
AddSubChart(TeeMsg_NoBorder);
AddSubChart(TeeMsg_Line);
end;
class procedure TCandleSeries.SetSubGallery(ASeries: TChartSeries;
Index: Integer);
begin
with TCandleSeries(ASeries) do
begin
GalleryChanged3D(ParentChart.View3D);
Case Index of
1: CandleStyle:=csCandleBar;
2: begin Pen.Show; CandleStyle:=csCandleBar; ShowOpenTick:=False; end;
3: begin Pen.Show; CandleStyle:=csCandleBar; ShowCloseTick:=False; end;
4: begin CandleStyle:=csCandleStick; Pen.Hide; end;
5: begin CandleStyle:=csLine; end;
else
inherited;
end;
end;
end;
function TCandleSeries.ClickedCandle(ValueIndex:Integer; const P:TPoint):Boolean;
var tmpItem : TCandleItem;
tmpTop : Integer;
tmpBottom : Integer;
tmpFirst : Integer;
tmpTo : TPoint;
begin
result:=False;
CalcItem(ValueIndex,tmpItem);
With tmpItem do
Begin
if (FCandleStyle=csCandleStick) or (FCandleStyle=csOpenClose) then
begin
if ParentChart.View3D and Pointer.Draw3D then
begin
tmpTop:=yClose;
tmpBottom:=yOpen;
if tmpTop>tmpBottom then SwapInteger(tmpTop,tmpBottom);
if (FCandleStyle=csCandleStick) and
(
PointInLine(P,tmpX,tmpBottom,tmpX,yLow) or
PointInLine(P,tmpX,tmpTop,tmpX,yHigh)
) then
begin
result:=True;
exit;
end;
if PointInRect(TeeRect(tmpX-tmpLeftWidth,tmpTop,tmpX+tmpRightWidth,tmpBottom),P) then
result:=True;
end
else
begin
if (FCandleStyle=csCandleStick) and
PointInLine(P,tmpX,yLow,tmpX,yHigh) then
begin
result:=True;
exit;
end;
if yOpen=yClose then Dec(yClose);
if ParentChart.View3D then
begin
if PointInRect(TeeRect(tmpX-tmpLeftWidth,yOpen,tmpX+tmpRightWidth,yClose),P) then
result:=True;
end
else
begin
if not Self.Pen.Visible then
if yOpen<yClose then Dec(yOpen) else Dec(yClose);
if PointInRect(TeeRect(tmpX-tmpLeftWidth,yOpen,tmpX+tmpRightWidth+1,yClose),P) then
result:=True;
end;
end;
end
else
if CandleStyle=csLine then
begin
tmpFirst:=FirstDisplayedIndex;
tmpTo:=TeePoint(tmpX,YClose);
if ValueIndex<>tmpFirst then result:=PointInLine(P,OldP,tmpTo);
OldP:=tmpTo;
end
else
if PointInLine(P,tmpX,yLow,tmpX,yHigh) or
(ShowOpenTick and PointInLine(P,tmpX,yOpen,tmpX-tmpLeftWidth-1,yOpen)) or
(ShowCloseTick and PointInLine(P,tmpX,yClose,tmpX+tmpRightWidth+1,yClose)) then
result:=True;
end;
end;
function TCandleSeries.Clicked(x, y: Integer): Integer;
var t : Integer;
P : TPoint;
begin
result:=TeeNoPointClicked;
if (FirstValueIndex>-1) and (LastValueIndex>-1) then
begin
if Assigned(ParentChart) then
ParentChart.Canvas.Calculate2DPosition(X,Y,StartZ);
P:=TeePoint(x,y);
for t:=FirstValueIndex to LastValueIndex do
if ClickedCandle(t,P) then
begin
result:=t;
break;
end;
end;
end;
function TCandleSeries.LegendItemColor(LegendIndex: Integer): TColor;
begin
result:=CalculateColor(LegendIndex);
end;
function TCandleSeries.MaxYValue: Double;
begin
if CandleStyle=csLine then result:=CloseValues.MaxValue
else result:=inherited MaxYValue;
end;
function TCandleSeries.MinYValue: Double;
begin
if CandleStyle=csLine then result:=CloseValues.MinValue
else result:=inherited MinYValue;
end;
procedure TCandleSeries.SetHighLowPen(const Value: TChartPen);
begin
FHighLowPen.Assign(Value);
end;
procedure TCandleSeries.SetColorStyle(const Value: TCandleColorStyle);
begin
if FColorStyle<>Value then
begin
FColorStyle:=Value;
Repaint;
end;
end;
function TCandleSeries.GetDownColor: TColor;
begin
result:=FDownClose.StartColor;
end;
function TCandleSeries.GetUpColor:TColor;
begin
result:=FUpClose.StartColor;
end;
procedure TCandleSeries.SetDownGradient(const Value: TTeeGradient);
begin
FDownClose.Assign(Value);
end;
procedure TCandleSeries.SetUpGradient(const Value: TTeeGradient);
begin
FUpClose.Assign(Value);
end;
{ TVolumeSeries }
Constructor TVolumeSeries.Create(AOwner: TComponent);
begin
inherited;
DrawArea:=False;
DrawBetweenPoints:=False;
IMandatoryPen:=True;
ClickableLine:=False;
Pointer.Hide;
FUseYOrigin:=False;
end;
Function TVolumeSeries.GetVolumeValues:TChartValueList;
Begin
result:=YValues;
end;
Procedure TVolumeSeries.SetSeriesColor(AColor:TColor);
begin
inherited;
LinePen.Color:=AColor;
end;
Procedure TVolumeSeries.SetVolumeValues(Value:TChartValueList);
Begin
SetYValues(Value);
end;
Procedure TVolumeSeries.PrepareCanvas(Forced:Boolean; AColor:TColor);
begin
if Forced or (AColor<>IColor) then
begin
ParentChart.Canvas.AssignVisiblePenColor(LinePen,AColor);
ParentChart.Canvas.BackMode:=cbmTransparent;
IColor:=AColor;
end;
end;
procedure TVolumeSeries.DrawValue(ValueIndex:Integer);
Begin
PrepareCanvas(ValueIndex=FirstDisplayedIndex, ValueColor[ValueIndex]);
{ moves to x,y coordinates and draws a vertical bar to top or bottom,
depending on the vertical Axis.Inverted property }
with ParentChart do
if View3D then
Canvas.VertLine3D(CalcXPos(ValueIndex),CalcYPos(ValueIndex),OriginPosition,MiddleZ)
else
Canvas.DoVertLine(CalcXPos(ValueIndex),OriginPosition,CalcYPos(ValueIndex)); { 5.02 }
end;
function TVolumeSeries.OriginPosition:Integer; // 7.05
begin
if UseYOrigin then
result:=CalcYPosValue(YOrigin) { 5.02 }
else
With GetVertAxis do
if Inverted then result:=IStartPos
else result:=IEndPos;
end;
Function TVolumeSeries.NumSampleValues:Integer;
Begin
result:=40;
end;
Procedure TVolumeSeries.AddSampleValues(NumValues:Integer; OnlyMandatory:Boolean=False);
Var t : Integer;
s : TSeriesRandomBounds;
begin
s:=RandomBounds(NumValues);
with s do
for t:=1 to NumValues do
Begin
AddXY(tmpX,RandomValue(Round(DifY) div 15));
tmpX:=tmpX+StepX;
end;
end;
Procedure TVolumeSeries.PrepareForGallery(IsEnabled:Boolean);
begin
inherited;
FillSampleValues(26);
Pointer.InflateMargins:=True;
end;
class Function TVolumeSeries.GetEditorClass:String;
Begin
result:='TVolumeSeriesEditor'; // Do not localize
End;
class procedure TVolumeSeries.CreateSubGallery(
AddSubChart: TChartSubGalleryProc);
begin
inherited;
AddSubChart(TeeMsg_Dotted);
AddSubChart(TeeMsg_Colors);
AddSubChart(TeeMsg_Origin); { 5.02 }
end;
class procedure TVolumeSeries.SetSubGallery(ASeries: TChartSeries;
Index: Integer);
begin
With TVolumeSeries(ASeries) do
Case Index of
1: Pen.SmallDots:=True;
2: ColorEachPoint:=True;
3: UseYOrigin:=True;
else inherited
end;
end;
procedure TVolumeSeries.DrawLegendShape(ValueIndex: Integer; { 5.01 }
const Rect: TRect);
begin
with Rect do
ParentChart.Canvas.DoHorizLine(Left,Right,(Top+Bottom) div 2);
end;
procedure TVolumeSeries.Assign(Source: TPersistent);
begin
if Source is TVolumeSeries then
with TVolumeSeries(Source) do
begin
Self.FUseYOrigin:= UseYOrigin;
Self.FOrigin := YOrigin;
end;
inherited;
end;
procedure TVolumeSeries.SetOrigin(const Value: Double);
begin
SetDoubleProperty(FOrigin,Value);
end;
procedure TVolumeSeries.SetUseOrigin(const Value: Boolean);
begin
SetBooleanProperty(FUseYOrigin,Value);
end;
procedure TVolumeSeries.PrepareLegendCanvas(ValueIndex: Integer;
var BackColor: TColor; var BrushStyle: TBrushStyle);
begin
PrepareCanvas(True,SeriesColor);
end;
function TVolumeSeries.Clicked(x, y: Integer): Integer; // 7.05
var t : Integer;
P : TPoint;
tmpX : Integer;
tmpOrigin : Integer;
begin
if (FirstValueIndex>-1) and (LastValueIndex>-1) then // AX 7.06
begin
P.X:=x;
P.Y:=y;
tmpOrigin:=OriginPosition;
for t:=FirstValueIndex to LastValueIndex do
begin
tmpX:=CalcXPos(t);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -