Price Levels
The following code is an example of how to create horizontal lines at different price levels.
//
// Sample script for Optuma tool scripting
// This tool creates horizontal lines at 45, 50 and 60 price points
// It also create horizontal lines at the highest high and the lowest low
//
// This section is where variable are defined that need to be used in both the Init and Process procedures
var
Lines : TPriceLevels;
bCreateLines : Boolean;
// DefineTool is where the settings for the Tool are defined
// This procedure is called once when the tool is loaded
// Normally this procedure does not need to be changed
procedure DefineTool(Tool : TTool);
begin
Tool.Name := 'Price Levels';
Tool.MouseClicks := 2;
Tool.Hint := '';
Tool.ToolType := ttDrawing;
end;
// Init is called to initialise the tool
// This procedure is called once when the tool is added to a chart
procedure Init(Tool : TTool);
var
Level : TPriceLevel;
begin
Lines := Tool.AddPriceLevels();
// Lines.Extend := true; // uncomment this line to have the lines fully extend
Level := Lines.AddLevel(50);
Level.Color := clgreen;
Lines.AddLevel(45);
Level := Lines.AddLevel(60);
Level.Color := clBlue;
Level.Style := dash;
bCreateLines := True;
end;
// Process is called to calculate and drawn the tool on screen
// This procedure is called when new data is received or loaded and
// when a selection point is moved by the user
procedure Process(Tool : TTool; ProcessStart : Integer; ProcessEnd : Integer; DataIn : TDataList);
var
i : Integer;
rHighest, rLowest : Boolean;
begin
if bCreateLines then
begin
Lines.ClearLevels;
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
bCreateLines := False;
end;
end;