Using a Dummy Buffer

Indicators coded by community members
Message
Author
Gadi
Posts: 1
Joined: Sat May 02, 2020 6:35 am

Using a Dummy Buffer

#1 Postby Gadi » Sat Jun 20, 2020 9:51 am

hi Guys,
I have programed the attched file. it works fine. does what i meant it to do.
The only problem i have is that it must use a buffer even it does not do any calculation with it.
And of course it shows styles which are also not used.

Thanks

//---------------------------------------------------------------------------
library SRLines;

uses
// IndicatorInterfaceUnit, Math, windows,
SysUtils, graphics, IndicatorInterfaceUnit, TechnicalFunctions, Math, windows;


var
// Buffers
DummyBuffer: TIndexBuffer;
Depth, Nbar, BarsOnChart, SuppColor, ResColor, DeleteAfter:integer;

{$I commonfunctions}
//---------------------------------------------------------------------------
// Initialize indicator
//---------------------------------------------------------------------------
procedure Init; stdcall;

begin

// define properties
IndicatorShortName('SRLines');
SetOutputWindow(ow_ChartWindow);

//--------------------------------------------------------------//
// Parameters //
//----------------------- ------------------------------------//
AddSeparator('Common');

RegOption('Depth', ot_integer, Depth);
Depth:=30;

RegOption('Number of Bars', ot_integer, Nbar);
Nbar:=240;

RegOption('Delete support & resistance lines after:', ot_integer, DeleteAfter);
DeleteAfter:=480;

BarsOnChart:=240;

RegOption('Support', ot_color, SuppColor);
SuppColor:=rgb(0,128,0);
RegOption('Resistance', ot_color, ResColor);
ResColor:=rgb(255,0,0);

// create Indexbuffers
DummyBuffer := CreateIndexBuffer;
IndicatorBuffers(1);
SetIndexBuffer(0, DummyBuffer);
SetIndexStyle(0, ds_None, psSolid, 1, rgb(255,255,255));

end;

//---------------------------------------------------------------------------
procedure OnParamsChange; stdcall;
begin

end;

//---------------------------------------------------------------------------
// Deinitialize indicator
//---------------------------------------------------------------------------
procedure Done; stdcall;
begin

end;

//---------------------------------------------------------------------------
// Draw Trend Line
//---------------------------------------------------------------------------
procedure DrawTrendLine(prefix:string; xi:TDateTime; yi:double; xf:TDateTime; yf:double; color:integer); stdcall;
begin
ObjectCreate(prefix,obj_TrendLine,0,xi,yi,xf,yf);
ObjectSet(prefix, OBJPROP_STYLE, 0);
ObjectSet(prefix, OBJPROP_COLOR, color);
ObjectSet(prefix, OBJPROP_WIDTH, 1);
end;

//---------------------------------------------------------------------------
// Extend Trend Line
//---------------------------------------------------------------------------
procedure ExtendTrendLine(xf:TDateTime); stdcall;

var

i:integer;

begin
for i:=0 to ObjectsTotal - 1 do
begin
if ObjectType(ObjectName(i))=obj_TrendLine then
ObjectSet(ObjectName(i),OBJPROP_TIME2,xf);
end;
end;


//---------------------------------------------------------------------------
// Delete Trend Lines
//---------------------------------------------------------------------------
procedure DeleteTrendLines; stdcall;

var

i,bs:integer;
ObjDateTimeStart: TDateTime;

begin
for i:=0 to ObjectsTotal - 1 do
begin
if ObjectType(ObjectName(i))=obj_TrendLine then
begin
ObjDateTimeStart:=ObjectGet(ObjectName(i), OBJPROP_TIME1);
bs:=iBarShift(Symbol, TimeFrame, ObjDateTimeStart, false);
if bs>DeleteAfter then ObjectDelete(ObjectName(i));
end;
end;

end;


//---------------------------------------------------------------------------
// New Bar
//---------------------------------------------------------------------------
function IsNewBar:boolean;

begin
if Bars=BarsOnChart then
Result:=False
else
begin
BarsOnChart:=Bars;
Result:=True
end;
end;

//---------------------------------------------------------------------------
// Calculate requested bar
//---------------------------------------------------------------------------
procedure Calculate(index: integer); stdcall;

var
i,pos:integer;
LLV, ForwardLLV, HHV, ForwardHHV:boolean;
begin

if Bars<NBar+Depth then exit;

pos:=index+Depth;

LLV := true;
ForwardLLv := true;
HHV := true;
ForwardHHV := true;

if IsNewBar then
begin
ExtendTrendLine(Time(0));
DeleteTrendLines;
end;

for i:=1 to Depth do
begin
if (low(pos+i) < low(pos)) then ForwardLLV := false;
if (low(pos-i) < low(pos)) then LLV := false;
if (high(pos+i) > high(pos)) then ForwardHHV := false;
if (high(pos-i) > high(pos)) then HHV := false;
end;

if ( LLV and ForwardLLV ) then
DrawTrendLine('S'+DateTimeToStr(Time(pos)),Time(pos),Low(pos),Time(1),low(pos),SuppColor);

if ( HHV and ForwardHHV ) then
DrawTrendLine('R'+DateTimeToStr(Time(pos)),Time(pos),High(pos),Time(1),High(pos),ResColor);


end;

exports

Init, OnParamsChange, Done, Calculate;

end.
Attachments
screen_00002.jpg
screen_00002.jpg (165.69 KiB) Viewed 15175 times

agenda.me
Posts: 10
Joined: Thu May 07, 2020 11:55 pm

Re: Using a Dummy Buffer

#2 Postby agenda.me » Thu Aug 18, 2022 7:17 am

share the dll please


Return to “Indicators”

Who is online

Users browsing this forum: No registered users and 0 guests