Session Start/End Indicator

Indicators coded by community members
Message
Author
bradp
Posts: 1
Joined: Tue Feb 22, 2011 2:16 am

Session Start/End Indicator

#1 Postby bradp » Tue Feb 22, 2011 2:27 am

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.
Attachments
SessionsFT2.zip
(1.7 MiB) Downloaded 908 times

Stonev
Posts: 204
Joined: Thu Jan 28, 2010 2:20 pm

#2 Postby Stonev » Tue Feb 22, 2011 8:16 am

Hello!
Good work, bradp, it is really necessary indicator.
But much more useful to use Session and BreakOut_Box indicators.

Wessel
Posts: 63
Joined: Tue Oct 12, 2010 6:45 pm

#3 Postby Wessel » Tue Feb 22, 2011 2:52 pm

Thanks BradP for sharing the code and the indicator.!!

Much Appreciated.

@Stonev Thanks for the links, do you also share stuff with others as well like BradP does?

Wessel


Return to “Indicators”

Who is online

Users browsing this forum: No registered users and 29 guests