bradp
Joined: 22 Feb 2011 Posts: 1
|
Posted: Tue Feb 22, 2011 7:27 am Post subject: Session Start/End Indicator |
|
|
Attached is an indicator that draws a green vertical line for session start and a red vertical line for session end. Hope it is useful for someone.
Here's the code:
library SessionsFT2;
{$mode objfpc}{$H+}
uses
Classes, SysUtils, Graphics, DateUtils, IndicatorInterfaceUnit, TechnicalFunctions;
{$IFDEF WINDOWS}{$R SessionsFT2.rc}{$ENDIF}
const maxBars=1000;
// external parameters
var
startHour: integer = 9;
startMinute: integer = 0;
endHour: integer = 15;
endMinute: integer = 0;
procedure Init; stdcall;
begin
// define properties
IndicatorShortName('Sessions');
SetOutputWindow(ow_ChartWindow);
AddSeparator('Session Start');
RegOption('Start Hour (0-23)', ot_Integer, startHour);
SetOptionRange('Start Hour (0-23)', 0, 23);
RegOption('Start Minute (0-59)', ot_Integer, startMinute);
SetOptionRange('Start Minute (0-59)', 0, 59);
AddSeparator('Session End');
RegOption('End Hour (0-23)', ot_Integer, endHour);
SetOptionRange('End Hour (0-23)', 0, 23);
RegOption('End Minute (0-59)', ot_Integer, endMinute);
SetOptionRange('End Minute (0-59)', 0, 59);
IndicatorBuffers(0);
end;
//---------------------------------------------------------------------------
// Deinitialization procedure (could be omitted)
//---------------------------------------------------------------------------
procedure Done; stdcall;
begin
// see Deinitialization procedure
end;
//---------------------------------------------------------------------------
// On parameters change procedure (could be omitted)
//---------------------------------------------------------------------------
procedure OnParametersChange; stdcall;
begin
// called when parameters of indicator were changed
end;
// this function draws session line
procedure DrawLine(index: integer; color: integer); stdcall;
var formattedDateTime : string;
begin
DateTimeToString(formattedDateTime, 'c', Time(index));
ObjectCreate(formattedDateTime, obj_TrendLine, 0, Time(index), 20000, Time(index), 0);
ObjectSet(formattedDateTime, OBJPROP_WIDTH, 1);
ObjectSet(formattedDateTime, OBJPROP_STYLE, integer(psDot));
if color = 1 then
begin
ObjectSet(formattedDateTime, OBJPROP_COLOR, clGreen);
end
else
begin
ObjectSet(formattedDateTime, OBJPROP_COLOR, clRed);
end;
end;
//---------------------------------------------------------------------------
// Calculation of single bar
//---------------------------------------------------------------------------
procedure Calculate(index: integer); stdcall;
var iHour: integer;
var iMinute: integer;
begin
// Time(index) identifies current bar open time
iHour := HourOf(Time(index));
iMinute := MinuteOf(Time(index));
if (index < maxBars) then
begin
if (iHour = startHour) and (iMinute = startMinute) then
DrawLine(index, 1);
if (iHour = endHour) and (iMinute = endMinute) then
DrawLine(index, 2);
end;
end;
exports
// these procedures should be declared as external
Init, Done, OnParametersChange, Calculate, DrawLine;
end.
| Description: |
|
 Download |
| Filename: |
SessionsFT2.zip |
| Filesize: |
1.7 MB |
| Downloaded: |
407 Time(s) |
|
|