Forex Tester Forum (Professional Training Software for Traders) Forum Index Forex Tester Forum (Professional Training Software for Traders)

Back to main site   Risk disclosure
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Session Start/End Indicator

 
Post new topic   Reply to topic    Forex Tester Forum (Professional Training Software for Traders) Forum Index -> Indicators
View previous topic :: View next topic  
Author Message
bradp



Joined: 22 Feb 2011
Posts: 1

PostPosted: Tue Feb 22, 2011 7:27 am    Post subject: Session Start/End Indicator Reply with quote

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.



SessionsFT2.zip
 Description:

Download
 Filename:  SessionsFT2.zip
 Filesize:  1.7 MB
 Downloaded:  407 Time(s)

Back to top
View user's profile Send private message
Stonev



Joined: 28 Jan 2010
Posts: 102

PostPosted: Tue Feb 22, 2011 1:16 pm    Post subject: Reply with quote

Hello!
Good work, bradp, it is really necessary indicator.
But much more useful to use Session and BreakOut_Box indicators.
Back to top
View user's profile Send private message Send e-mail
Wessel



Joined: 12 Oct 2010
Posts: 57

PostPosted: Tue Feb 22, 2011 7:52 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Forex Tester Forum (Professional Training Software for Traders) Forum Index -> Indicators All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group