{*********************************************}
{  TeeChart Pro Charting Library              }
{  Renko Financial Series                     }
{  Copyright (c) 2007-2020 by Marjan Slatinek }
{  All Rights Reserved                        }
{*********************************************}
unit TeeRenkoSeriesEditor;
{$I TeeDefs.inc}

// The Renko chart financial indicator.
//
// The Renko chart is a trend following technique.
// It got its name from a Japanese word "renga" meaning bricks.
// In Renko chart line brick is drawn in the direction of the prior move
// only if prices move by a minimum amount
// which is equivalent to the box size that are always equal in size.
//
// Renko charts are always based on the closing prices.
// Renko bricks are drawn after comparing, that day’s close
// with the previous brick (high or low). A "box size" which determines
// the minimum price change to show is specified.

interface

uses
  {$IFNDEF LINUX}
  Windows, Messages,
  {$ENDIF}
  SysUtils, Classes,

  Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls,

  TeCanvas, TeEngine, TeePenDlg, TeeProcs, TeeRenkoSeries;

type
  TRenkoSeriesEditor = class(TForm)
    PageControl1: TPageControl;
    TabOptions: TTabSheet;
    TabBorder: TTabSheet;
    TabPattern: TTabSheet;
    Label1: TLabel;
    Label2: TLabel;
    CBDraw3D: TCheckBox;
    BUp: TButtonColor;
    BDown: TButtonColor;
    EBoxSize: TEdit;
    TBTransp: TTrackBar;
    LTransp: TLabel;
    procedure CBDraw3DClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure EBoxSizeChange(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure TBTranspChange(Sender: TObject);
  private
    { Private declarations }
    Renko : TRenkoSeries;
  public
    { Public declarations }
  end;

implementation

uses
  Math, TeeProCo, Chart, TeeBrushDlg;

{$IFNDEF LCL}
{$R *.DFM}
{$ELSE}
{$R *.lfm}
{$ENDIF}

{ TRenkoSeriesEditor }
procedure TRenkoSeriesEditor.CBDraw3DClick(Sender: TObject);
begin
  Renko.Draw3D:=CBDraw3D.Checked;
end;

procedure TRenkoSeriesEditor.FormShow(Sender: TObject);
begin
  Renko:=TRenkoSeries(Tag);

  if Assigned(Renko) then
  with Renko do
  begin
    CBDraw3D.Checked:=Draw3D;
    BUp.LinkProperty(Renko,'UpSwingColor');
    BDown.LinkProperty(Renko,'DownSwingColor');

    EBoxSize.Text:=FloatToStr(BoxSize);

    TBTransp.Position:=Transparency;
    LTransp.Caption:=IntToStr(TBTransp.Position);
  end;
end;

procedure TRenkoSeriesEditor.EBoxSizeChange(Sender: TObject);
begin
  Renko.BoxSize:=StrToFloatDef(EBoxSize.Text,Renko.BoxSize);
end;

procedure TRenkoSeriesEditor.PageControl1Change(Sender: TObject);
begin
  if (PageControl1.ActivePage=TabBorder) and (TabBorder.ControlCount=0) then
     TPenDialog.InsertForm(Renko.Pen,TabBorder)
  else
  if (PageControl1.ActivePage=TabPattern) and (TabPattern.ControlCount=0) then
     TBrushDialog.AddDialog(Renko.Brush,TabPattern);
end;

procedure TRenkoSeriesEditor.TBTranspChange(Sender: TObject);
begin
  if Showing then
  begin
    Renko.Transparency:=TBTransp.Position;
    LTransp.Caption:=IntToStr(TBTransp.Position);
  end;
end;

initialization
  RegisterClass(TRenkoSeriesEditor);
end.

