- Desktop
- Tools
- PASCAL Programming
- Time Events Example
Time Events Example
The following code is an example of how to create a tool based on Time Events.
//// Sample script for Optuma tool scripting// Creates three vertical lines yesterday, 30 days ago and 60 days ago// It also creates a vertical line for every bar that has the Close greater than the Open// It also adds a region between 45 days ago and 10 days ago//
// This section is where variable are defined that need to be used in both the Init and Process proceduresvar Events : TEvents; Event : TEvent; bCreateEvents : 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 changedprocedure DefineTool(Tool : TTool);begin Tool.Name := 'Time Events'; Tool.MouseClicks := 1; Tool.Hint := ''; Tool.ToolType := ttDataList;end;
// Init is called to initialise the tool// This procedure is called once when the tool is added to a chartprocedure Init(Tool : TTool);begin Events := Tool.AddEvents(); Events.Extend := true; Events.AddRegion(Now()-45, Now()-10, clBlue); // This creates a region between 45 days ago and 10 days ago Events.FillTransparency := 40;
Event := Events.AddEvent(Now()-1, clRed); Event := Events.AddEvent(Now()-30, clRed); Event := Events.AddEvent(Now()-60, clBlue);
bCreateEvents := 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 userprocedure Process(Tool : TTool; ProcessStart : Integer; ProcessEnd : Integer; DataIn : TDataList);var i : Integer;begin if bCreateEvents then // this is so the lines are drawn only the first time begin for i := ProcessStart to ProcessEnd do begin if DataIn.Row[i].Close > DataIn.Row[i].Open then begin Events.AddEvent(DataIn.Row[i].Date, clRed); end; end; end; bCreateEvents := False;end;Forum Discussion
Your privacy choices
We use cookies and similar technologies to make the site work, see how it's used, and improve it. Analytics and advertising cookies only run with your consent — see our Privacy Policy for details.