⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 teekagiseries.pas

📁 BCB第三方组件
💻 PAS
📖 第 1 页 / 共 2 页
字号:

    if i < Count then
    begin
      if Draw then
      begin
        // define pen style
        tmpUpPen:=CloseValues.Value[i] > BasePrice;
        if tmpUpPen then
           ParentChart.Canvas.AssignVisiblePen(FUpSwing)
        else
           ParentChart.Canvas.AssignVisiblePen(FDownSwing);

        // initial vertical line
        DrawVertLine(result,BasePrice,CloseValues[i]);
      end;

      Inc(result);

      Histpoints[0]:=CloseValues[i];
      Histpoints[1]:=BasePrice;
      sStart:=BasePrice;

      // Process the rest of the points
      for j:= i + 1 to Count-1 do
      begin
        if Reversal(CloseValues[j],histpoints) then // Reversal ?
        begin
          if Draw then
          begin
            // Draw horizontal inflection line using the same pen style
            DrawHorizLine(histpoints[0], result - 1, result);

            // check if value exceeds previous segment
            up:= CloseValues.Value[j]>histpoints[0];

            if up and (CloseValues.Value[j] > sstart) then
            begin
              DrawVertLine(result, histpoints[0], sstart);

              // if required, draw buy symbol
              if FBuySymbol.Visible and (not tmpUpPen) then
              begin
                FBuySymbol.PrepareCanvas(ParentChart.Canvas,FBuySymbol.Color);
                FBuySymbol.Draw(CalcXPosValue(result),
                                CalcYPosValue(sstart),
                                Fbuysymbol.Color, Fbuysymbol.Style);
              end;

              // Change pen style
              ParentChart.Canvas.AssignVisiblePen(FUpSwing);
              tmpUpPen:=True;
              DrawVertLine(result, sstart, CloseValues[j]);
            end
            else
            if (not Up) and (CloseValues.Value[j] < sStart) then
            begin
              DrawVertLine(result, Histpoints[0], sStart);

              // if required, draw sell symbol
              if sellsymbol.Visible and tmpUpPen then
              begin
                FSellSymbol.PrepareCanvas(ParentChart.Canvas, FSellSymbol.Color);
                FSellSymbol.Draw(CalcXPosValue(result),
                                 CalcYPosValue(sStart),
                                 FSellSymbol.Color, FSellSymbol.Style);
              end;

              // Change pen style
              ParentChart.Canvas.AssignVisiblePen(FDownSwing);
              tmpUpPen:=False;
              DrawVertLine(result, sStart, CloseValues[j]);
            end
            else
              DrawVertLine(result, Histpoints[0], CloseValues[j]);
          end;

          // increase segment number
          Inc(result);

          // update last two values
          Histpoints[1] := Histpoints[0];
          Histpoints[0] := CloseValues[j];

          // update segment start point (min or max)
          sStart := CloseValues[j];
        end
        else
        if (CloseValues[j]-Histpoints[0])*(Histpoints[0]-Histpoints[1])>0 then
        // add vertical line only if trend continues in the same direction
        begin
          if Draw then
             DrawVertLine(result-1, histpoints[0], CloseValues[j]);

          // update last two values
          Histpoints[1] := Histpoints[0];
          Histpoints[0] := CloseValues[j];
        end;
      end;
    end;
  end;
end;

procedure TKagiSeries.DrawVertLine(const x,FromValue,ToValue:Double);
begin
  ParentChart.Canvas.VertLine3D(CalcXPosValue(x),CalcYPosValue(FromValue),
                                CalcYPosValue(ToValue), MiddleZ);
end;

procedure TKagiSeries.DrawHorizLine(const y,FromValue,ToValue:Double);
begin
  ParentChart.Canvas.HorizLine3D(CalcXPosValue(FromValue),CalcXPosValue(ToValue),
                                 CalcYPosValue(y),MiddleZ);
end;

procedure TKagiSeries.DrawAllValues;
begin
  inherited;
  CalcSegments(True);
end;

function TKagiSeries.MaxXValue:Double;
begin
  result:=CalcSegments(False)-1;
end;

procedure TKagiSeries.SetParentChart(const Value:TCustomAxisPanel);
begin
  inherited;

  if Assigned(FSellSymbol) then
     FSellSymbol.ParentChart:=Value;

  if Assigned(FBuySymbol) then
     FBuySymbol.ParentChart:=Value;
end;

function TKagiSeries.NumSampleValues:Integer;
begin
  result:=10;
end;

procedure TKagiSeries.PrepareForGallery(IsEnabled:Boolean);
begin
  inherited;

  FillSampleValues(16);
  
  if not IsEnabled then
  begin
    BuySymbol.Color := clSilver;
    BuySymbol.Pen.Color := clGray;
    SellSymbol.Color := clSilver;
    SellSymbol.Pen.Color := clGray;
  end;
end;

// Reversal ammount (percentage or absolute value)
// Defines the reversal amount.
procedure TKagiSeries.SetReversalAmount(const Value:Double);
begin
  SetDoubleProperty(FReversalAmount, Value);
end;

// If false, reversal amount is treated as percentage, otherwise as absolute value.
// Defines if reversal amount is treated as absolute or relative value.
procedure TKagiSeries.SetAbsoluteReversal(const Value:Boolean);
begin
  SetBooleanProperty(FAbsReversal, Value);
end;

// Controls the appearance of upswing lines.
// Pen used to draw "upswing" lines.
procedure TKagiSeries.SetUpSwing(const Value:TChartPen);
begin
  FUpSwing.Assign(Value);
end;

// Controls the appearance of downswing lines.
// Pen used to draw "downswing" lines.
procedure TKagiSeries.SetDownSwing(const Value:TChartPen);
begin
  FDownSwing.Assign(Value);
end;

// Trading close values.
// Gets and sets all Stock market closing values.
function TKagiSeries.GetCloseValues:TChartValueList;
begin
  result:=YValues;
end;

// The base price i.e. first closing value.
function TKagiSeries.BasePrice:Double;
begin
  if Count>0 then result:=CloseValues[0]
             else result:=0;
end;

function TKagiSeries.CountLegendItems:Integer;
begin
  result:=2;
end;

function TKagiSeries.LegendItemColor(LegendIndex:Integer):TColor;
begin
  if LegendIndex=0 then result:=UpSwing.Color
                   else result:=DownSwing.Color;
end;

function TKagiSeries.LegendString( LegendIndex:Integer;
                                    LegendTextStyle:TLegendTextStyle ):String;
begin
  if LegendIndex=0 then result:=TeeMsg_Up
                   else result:=TeeMsg_Down;
end;

procedure TKagiSeries.SetBuySymbol(const Value: TSeriesPointer);
begin
  FBuySymbol.Assign(Value);
end;

procedure TKagiSeries.SetSellSymbol(const Value: TSeriesPointer);
begin
  FSellSymbol.Assign(Value);
end;

class function TKagiSeries.GetEditorClass: String;
begin
  result:='TKagiSeriesEditor';
end;

{ TKagiSeriesEditor }
procedure TKagiSeriesEditor.FormShow(Sender: TObject);

  procedure AddEditor(ATab:TTabSheet; ASymbol:TSeriesPointer);
  var tmp : TSeriesPointerEditor;
  begin
    tmp:=TSeriesPointerEditor.Create(Self);
    tmp.Align:=alClient;
    TeeTranslateControl(tmp);
    AddFormTo(tmp,ATab,ASymbol);
  end;

begin
  Kagi:=TKagiSeries(Tag);

  if Assigned(Kagi) then
  with Kagi do
  begin
    BUp.LinkPen(UpSwing);
    BDown.LinkPen(DownSwing);

    AddEditor(TabBuy,BuySymbol);
    AddEditor(TabSell,SellSymbol);
  end;
end;

initialization
  RegisterTeeSeries( TKagiSeries, {$IFNDEF CLR}@{$ENDIF}TeeMsg_GalleryKagi,
                                  {$IFNDEF CLR}@{$ENDIF}TeeMsg_GalleryFinancial, 1 );

  RegisterClass(TKagiSeriesEditor);
finalization
  UnRegisterTeeSeries([TKagiSeries]);
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -