Tool Drawing Items

Author: Optuma Team Last updated: Mar 2, 2021 20:11

This page describes all drawing items that can be added to your custom tool.

Plots

Plots are drawing items that have a value for every bar in the chart, like a moving average.

function AddPlot(sFormula : String = '') : TPlot;

To add a Plot you first need a TPlot variable

var
  Plot1 : TPlot

Then to add the plot to the tool call the Tool.AddPlot method

procedure Init(Tool : TTool);
begin
    Plot1 := Tool.AddPlot();
    ...
end;

To set properties for the Plot access the properties via the Plot Variable

procedure Init(Tool : TTool);
begin
   Plot1 := Tool.AddPlot();
   Plot1.Color := clBlue;
   Plot1.PlotStyle := Shaded;// possible values are (Line, Dot, Histogram, Step, Shaded)
   Plot1.FillColor := clBlue;
   Plot1.Caption := 'MyPLot'; // this the caption of the plot style property in the properties panel
   Plot1.ShowInPropertiesPanel := True; // Whether the plot style is shown in the properties panel
end;

To initialise the data in the plot add a script to the Tool.AddPlot call

procedure Init(Tool : TTool);
begin
    Plot1 := Tool.AddPlot('MA(BARS=200');
    ...
end;

This will populate Plot1 with the 200 period moving average of the source data.

A plot can be initialised with any Optuma function - see list of function here.

If a plot is initialised with no script, then it is populated with zeros.

Selection Points

Selection points are the small round circles on a tool that can be used to move or resize a tool.

To access the selection points for a tool use the MP property of the tool.

Tool.MP[0].Date; // this is the date of the first selection point that is created when clicking to apply a tool
Tool.MP[0].Price; // this is the price of the first selection point that is created when clicking to apply a tool

Lines

Lines are drawing items that draw a line from start point to end point.

function AddLine() : TLine;

To add a Line you first need a TLine variable

var
  Line1 : TPlot

Then to add the line to the tool call the Tool.AddLine method

procedure Init(Tool : TTool);
begin
    Line1 := Tool.AddLine();
    ...
end;

To set properties for the Line access the properties via the Line1 Variable

procedure Init(Tool : TTool);
begin
   Plot1 := Tool.AddPlot();
   Line1.Color := clRed;  // Type of TColor = (clBlack, clMaroon, clGreen, clOlive, clNavy, clPurple, clTeal, clGray, clSilver, clRed, clLime, clYellow, clBlue, clFuchsia , clAqua, clLtGray, clDkGray, clWhite )
   Line1.Width := 1;
   Line1.Style := Solid; // Types of TLineStyle =  (Solid, DotDot, Dash, DashDot, LongDash, LongDashDot, LongDashDotDot);
   Line1.Visible := True;
   Line1.Transparency := 50; // Measured in Percent i.e. 50% transparency
   Line1.Extend := False; // Indicates whether line is extended to the edge of the chart.
   Line1.ExtendRight:= False; // Indicates whether line is extended right to the edge of the chart.
   Line1.ExtendLeft:= False; // Indicates whether line is extended left to the edge of the chart.
   Line1.Caption := 'My Line'; // The name of the line shown in the properties panel
   Line1.ShowInPropertiesPanel := True; // Whether the line is shown in the properties panel
end;

To dynamically set line positions use the Line Selection Points. This example sets the points of the Line equal to the selection points created when clicking to chart twice to add the tool.

procedure Process(Tool : TTool; ProcessStart : Integer; ProcessEnd : Integer; DataIn : TDataList);
begin
    Line1.P1.Date := Tool.MP[0].Date;
    Line1.P1.Price := Tool.MP[0].Price;
    Line1.P2.Date := Tool.MP[1].Date;
    Line1.P2.Price := Tool.MP[1].Price;
end;

Horizontal Lines

Horizontal Lines are drawn at a specified price point.

function AddHLine(rPrice : Double) : TLine;

To add a Horizontal Line you first need a TLine variable

var
  HL: TLine;

Then to add the horizontal line to the tool at the $50 price point call the Tool.AddHLine method

procedure Init(Tool : TTool);
begin
    HL := Tool.AddHLine(50);
    ...
end;

To set properties for the Line access the properties via the HL Variable

procedure Init(Tool : TTool);
begin
   HL := Tool.AddHLine(50);
   Line1.Color := clRed;
   Line1.Width := 1;
   Line1.Style := Solid;
   Line1.Visible := True;
   Line1.Transparency := 50;
   Line1.Extend := True;
   Line1.Caption := 'My Line'; // The name of the line shown in the properties panel
   Line1.ShowInPropertiesPanel := True; // Whether the line is shown in the properties panel
end;
procedure Init(Tool : TTool);
begin
   HL := Tool.AddHLine(50);
   Line1.Color := clRed;
   Line1.Width := 1;
   Line1.Style := Solid;
   Line1.Visible := True;
   Line1.Transparency := 50;
   Line1.Extend := True;
   Line1.Caption := 'My Line'; // The name of the line shown in the properties panel
   Line1.ShowInPropertiesPanel := True; // Whether the line is shown in the properties panel
end;

To dynamically set horizontal line positions use the Line Selection Points. This example sets the horizontal line to the Close price of the latest bar.

procedure Process(Tool : TTool; ProcessStart : Integer; ProcessEnd : Integer; DataIn : TDataList);
begin
   HL.P1.Price := DataIn.Bar[0].Close;
   HL.P2.Price := DataIn.Bar[0].Close;
end;

Vertical Lines

Vertical Lines are drawn at a specified date.

function AddVLine(dtDate : TDateTime) : TLine;

To add a vertical Line you first need a TLine variable

var
  VL: TLine;

Then to add the vertical line to the tool at a date (5 Jan 2012) call the Tool.AddVLine method

procedure Init(Tool : TTool);
begin
    VL := Tool.AddVLine(EncodeDate(2012, 1, 5));
    ...
end;

To set properties for the vertical Line access the properties via the VL Variable

procedure Init(Tool : TTool);
begin
   VL := Tool.AddVLine(EncodeDate(2012, 1, 5));
   Line1.Color := clRed;
   Line1.Width := 1;
   Line1.Style := Solid;
   Line1.Visible := True;
   Line1.Transparency := 50;
   Line1.Extend := True;
   Line1.Caption := 'My Line'; // The name of the line shown in the properties panel
   Line1.ShowInPropertiesPanel := True; // Whether the line is shown in the properties panel
end;

To dynamically set vertical line positions use the Line Selection Points. This example sets the vertical line to the date of the latest bar.

procedure Process(Tool : TTool; ProcessStart : Integer; ProcessEnd : Integer; DataIn : TDataList);
begin
   VL.P1.Date := DataIn.Bar[ProcessEnd].Date;
   VL.P2.Date := DataIn.Bar[ProcessEnd].Date;

   // You could also set it via the index
   VL.P1.Idx := ProcessEnd;
   VL.P2.Idx := ProcessEnd;
end;

Rectangles

Rectangles are drawing items that draw a rectangle from top left start point to bottom right end point.

function AddRectangle() : TRectangle;

To add a rectangle you first need a TRectangle variable

var
  Rect1 : TRectangle;

Then to add the rectangle to the tool call the Tool.AddRectangle method

procedure Init(Tool : TTool);
begin
   Rect1  := Tool.AddRectangle();
   ...
end;

To set properties for the rectangle access the properties via the Rect1 Variable

procedure Init(Tool : TTool);
begin
    Rect1  := Tool.AddRectangle();
    Rect1.FillColor := clBlue;
    Rect1.FillTransparency := 50;
end;

To dynamically set rectangle positions use the rectangle Selection Points. This example set the rectangle to the tool creation selection points.

procedure Process(Tool : TTool; ProcessStart : Integer; ProcessEnd : Integer; DataIn : TDataList);
begin
   Rect1.P1.Date := Tool.MP[0].Date;
   Rect1.P1.Price := Tool.MP[0].Price;
   Rect1.P2.Date := Tool.MP[1].Date;
   Rect1.P2.Price := Tool.MP[1].Price;
end;

Symbols

Symbols are drawing items that draw a list of symbol images at various date, price points.

 function AddSymbols() : TSymbols;

To add a symbol you first need a TSymbols variable

var
  Symbols : TSymbols;

Then to add the symbol list to the tool call the Tool.AddSymbols method

procedure Init(Tool : TTool);
begin
   Symbols := Tool.AddSymbols();
   ...
end;

To add symbols for the symbols variable, call AddSymbol on the Symbols variable.

procedure Init(Tool : TTool);
begin
   Symbols := Tool.AddSymbols();
   Symbols.AddSymbol(1, date(), 51); // image id, date = todays date, price = $50
   Symbols.AddSymbol(5, date(), 55);
   Symbols.AddSymbol(3, now(), 60);

   //You can also add symbols by index
   Symbols.AddSymbolByIndex(1, ProcessEnd, 50); // added at the end of the data datalist at $50
end;

To add symbols during the process we need to remember that process can be called many times, so need to use a boolean variable to only create the lines the first process. This example will draw a symbol on every bar when the close is greater than the close.

var
    bCreateLines : Boolean;

...

procedure Init(Tool : TTool);
begin
   Symbols := Tool.AddSymbols();
   bCreateSymbols  := True;
end;

procedure Process(Tool : TTool; ProcessStart : Integer; ProcessEnd : Integer; DataIn : TDataList);
var
   i : Integer;
begin
   if bCreateSymbols then
   begin
      for i := ProcessStart to ProcessEnd do
      begin
         if DataIn.Row[i].Close > DataIn.Row[i].Open then
         begin
            Symbols.AddSymbolByIndex(1, i, DataIn.Bar[i].High);
         end;
      end;
   end;
   bCreateSymbols  := False;
end;

2D Symbols

2D Symbols are drawing items that draw a list of winding symbols at various date, price points.

function Add2DSymbols() : T2DSymbols;

To add a symbol you first need a T2DSymbols variable

var
  Symbols : T2DSymbols;

Then to add the symbol list to the tool call the Tool.Add2DSymbols method

procedure Init(Tool : TTool);
begin
   Symbols := Tool.Add2DSymbols();
   ...
end;

To add symbols for the symbols variable, call AddSymbol on the Symbols variable.

procedure Init(Tool : TTool);
begin
   Symbols := Tool.AddSymbols();
   Symbols.AddSymbol(1, date(), 51); // image id, date = todays date, price = $50
   Symbols.AddSymbol(5, date(), 55);
   Symbols.AddSymbol(3, now(), 60);

   //You can also add symbols by index
   Symbols.AddSymbolByIndex(1, ProcessEnd, 50); // added at the end of the data datalist at $50
end;

Events

Events are drawing items that draw a list of vertical time lines at various dates. They can also show regions from a start date to an end date.

function AddEvents() : TEvents;

To add a list of Events you first need a TSymbols variable

var
  Events : TEvents;

Then to add an event list to the tool call the Tool.AddEvents method.

procedure Init(Tool : TTool);
begin
   Events := Tool.AddEvents();
   ...
end;

To add events for the Events variable, call AddEvent on the Events variable.

procedure Init(Tool : TTool);
begin
   Events := Tool.AddEvents();
   Events.Extend := true;
   Events.FillTransparency := 40; // this is the transparency of the Region. 0=Invisible, 100=Opaque

   Events.AddEvent(Date()-1, clRed); // will add a red vertical line yesterday
   Events.AddEvent(Date()-30, clRed); // will add a red vertical line 30 days ago
   Events.AddEvent(Date()-60, clBlue);// will add a red vertical line 60 days ago

   Events.AddRegion(Now()-45, Now()-10, clred); // will add a region 45 days ago to 10 days ago
end;

To add events during the process we need to remember that process can be called many times, so need to use a boolean variable to only create the lines the first process. This example will draw a event on every bar when the close is greater than the close.

var
    bCreateEvents : Boolean;

...

procedure Init(Tool : TTool);
begin
   Events := Tool.AddEvents();
   bCreateEvents  := True;
end;
procedure Process(Tool : TTool; ProcessStart : Integer; ProcessEnd : Integer; DataIn : TDataList);
var
   i : Integer;
begin
   if bCreateEvents then
   begin
      for i := ProcessStart to ProcessEnd do
      begin
         if DataIn.Row[i].Close > DataIn.Row[i].Open then
         begin
            Events.AddEvent(DataIn.Bar[i].Date, clRed);
         end;
      end;
   end;
   bCreateEvents := False;
end;

Price Levels

Price Levels are drawing items that draw a list of horizontal lines at various prices.

 function AddPriceLevels() : TPriceLevels;

To add a list of Price Levels you first need a TPriceLevels variable

var
  Lines : TPriceLevels;

Then to add an levels list to the tool call the Tool.AddPriceLevels method.

procedure Init(Tool : TTool);
begin
   Lines := Tool.AddPriceLevels();
   ...
end;

To add levels for the Lines variable, call AddLevel on the Events variable.

procedure Init(Tool : TTool);
var
   Level : TPriceLevel;
begin
   Lines := Tool.AddPriceLevels();
   Lines.Extend := true;
   Level := Lines.AddLevel(50); // adds line at $50
   Level.Color := clgreen;
   Lines.AddLevel(45);          // Adds line at $45
   Level := Lines.AddLevel(60); // Add line at $60
   Level.Color := clBlue;
   Level.Style := dash;
end;

To add lines during the process we need to remember that process can be called many times, so need to use a boolean variable to only create the lines the first process. This example will draw a horizontal line on the highest high and the lowest low.

var
    Lines : TPriceLevels;
    bCreateLines: Boolean;

...

procedure Init(Tool : TTool);
var
   Level : TPriceLevel;
begin
   Lines := Tool.AddPriceLevels();
   Lines.Extend := true;
   Level.Color := clBlue;
   Level.Style := dash;
end;

procedure Process(Tool : TTool; ProcessStart : Integer; ProcessEnd : Integer; DataIn : TDataList);
var
   i : Integer;
   rHighest, rLowest : Boolean;
begin
   if bCreateLines then
   begin
     rHighest := 0;
     rLowest := 1E10;
     for i := ProcessStart to ProcessEnd do
     begin
         if DataIn.Row[i].High > rHighest then
             rHighest := DataIn.Row[i].High;

         if DataIn.Row[i].Low < rLowest then
             rLowest :=  DataIn.Row[i].Low;
     end;
     Lines.AddLevel(rHighest); // adds a line at highest high
     Lines.AddLevel(rLowest); // adds line at lowest low
   end;
 end;

Text

Text drawing items will draw text on the chart at a date and price.

function AddText(sText : String; dtDate : TDateTime; rPrice : Double) : TText;

To add a text object you first need a TText variable

var
   Text1 : TText;

Then to add the text to the tool call the Tool.AddText method

procedure Init(Tool : TTool);
begin
    Text1 := Tool.AddText('Hello There', now(), 50);
    ...
end;

To set properties for the text use the Text1 Variable

procedure Init(Tool : TTool);
begin
   Text1 := Tool.AddText('Hello There', now(), 50);
   Text1.FontColor := clRed;
end;

To dynamically set text positions use the Text Date and Price properties . This example set the text to the tool creation selection points.

procedure Process(Tool : TTool; ProcessStart : Integer; ProcessEnd : Integer; DataIn : TDataList);
begin
   Text1.Date := Tool.MP[0].Date;
   Text1.Price :=  Tool.MP[0].Price;
end;

Discussion