Indicator .dll file size when complied by Lazarus

How to create strategies and indicators
Message
Author
Ajent
Posts: 3
Joined: Mon Jun 14, 2010 12:32 am

Indicator .dll file size when complied by Lazarus

#1 Postby Ajent » Wed Jun 16, 2010 11:51 pm

Hi,

I wanted to modify the pivot indicator supplied with Forex Tester 2. I found the source code to the new pivot indicator on the forum and modified it. I then complied it using lazarus (following the same steps in the video instructions) and the indicator installed and worked fine but it is 6MB in size while all the supplied indicator .dll files are around 100KB.

Is there a way to compile the indicator so that it is smaller? Having a smaller file size would make it much easier to share with other people.

I've included the code below in case that helps at all.

Thanks!
Adrian

Code: Select all


//---------------------------------------------------------------------------
// Pivot Points
//---------------------------------------------------------------------------
library AJPivotPoints;

uses
  SysUtils,
  classes,
  graphics,
  math, DateUtils,
  IndicatorInterfaceUnit,
  TechnicalFunctions in 'TechnicalFunctions.pas';

var
  Continuous: boolean = false;
  PivotType: integer = 0;

  // index buffers
  PP, R3, S3: TIndexBuffer;


//---------------------------------------------------------------------------
// Initialization
//---------------------------------------------------------------------------
procedure Init; stdcall;
begin
  // define parameters
  IndicatorShortName('Pivot Points 2');
  SetOutputWindow(ow_ChartWindow);

  RegOption('Pivot Type', ot_EnumType, PivotType);
  AddOptionValue('Pivot Type', 'Daily');
  AddOptionValue('Pivot Type', 'Weekly');
  AddOptionValue('Pivot Type', 'Monthly');
  AddOptionValue('Pivot Type', 'Yearly');
  PivotType := 0;

  RegOption('Continuous', ot_Boolean, Continuous);

  // create index buffers
  PP := CreateIndexBuffer;
  R3 := CreateIndexBuffer;
  S3 := CreateIndexBuffer;

  IndicatorBuffers(3);

  SetIndexBuffer(0, R3);
  SetIndexStyle(0, ds_Line, psDot, 1, clRed);
  SetIndexLabel(0, 'R3');

  SetIndexBuffer(1, PP);
  SetIndexStyle(1, ds_Line, psDot, 1, clYellow);
  SetIndexLabel(1, 'PP');

  SetIndexBuffer(2, S3);
  SetIndexStyle(2, ds_Line, psDot, 1, clRed);
  SetIndexLabel(2, 'S3');
end;

//---------------------------------------------------------------------------
// Deinitialization
//---------------------------------------------------------------------------
procedure Done; stdcall;
begin
  //
end;

//---------------------------------------------------------------------------
// Calculate bar
//---------------------------------------------------------------------------
procedure Calculate(index: integer); stdcall;
var
  tm, tm1: TDateTime;
  day, week, day1, week1, month, month1, year, year1, i: integer;
  h, l, c, _pp: double;
  NewPeriod: boolean;

  procedure SetValues(index: integer; value: double);
  begin
    PP[index] := value;
    R3[index] := value;
    S3[index] := value;
  end;

  function WeekDay(tm: TDateTime): boolean;
  var
    day: integer;
  begin
    day := DayOfWeek(tm);
    result := (day <> 1) and (day <> 7);
  end;

begin
  if index = Bars - 1 then
    begin
      SetValues(index, 0);
      exit;
    end;

  tm := Time(index);
  tm1 := Time(index + 1);
  day := trunc(tm);
  day1 := trunc(tm1);
  week := WeekOf(day);
  week1 := WeekOf(day1);
  month := MonthOf(day);
  month1 := MonthOf(day1);
  year := YearOf(day);
  year1 := YearOf(day1);

  case PivotType of
    0:   NewPeriod := day <> day1;
    1:   NewPeriod := week <> week1;
    2:   NewPeriod := month <> month1;
    else NewPeriod := year <> year1;
  end;

  if not(NewPeriod) then
    begin
      // the same period
      PP[index] := PP[index + 1];
      R3[index] := R3[index + 1];
      S3[index] := S3[index + 1];
      exit;
    end;

  // calculate pivots
  i := index + 1;
  _pp := PP[i];

  if not(Continuous) then
    SetValues(index + 1, 0);

  h := High(i);
  l := Low(i);
  c := Close(i);
  inc(i);

  while (PP[i] = _pp) and (i < Bars) do
    begin
      h := Max(High(i), h);
      l := Min(Low(i), l);
      inc(i);
    end;

  _pp := (h + l + c)/3;
  PP[index] := _pp;
  R3[index] := h + 2*(_pp - l);
  S3[index] := l - 2*(h - _pp);

end;

exports

Init, Done, Calculate;

begin

end.

Ajent
Posts: 3
Joined: Mon Jun 14, 2010 12:32 am

#2 Postby Ajent » Thu Jun 17, 2010 7:30 pm

Since posting I started testing using the indicator. It works fine in edit mode and with displayed data when in Testing mode but it calculates incorrectly when applied to data as forex tester steps through. To correct it I have to remove and add the indicator again. Have I made an error in the code (it is just a cut-down version of the provided pivot point indicator) or is this somehow related to how the indicator was compiled?

Any assistance would be appreciated!

Thanks,
Adrian

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#3 Postby FT Support » Fri Jun 18, 2010 1:34 am

Hello Adrian,

Most likely this is an error in code. If you wish i can compile your code in Delphi but i think it will not help.
Check our other product here:
http://www.forexcopier.com

Ajent
Posts: 3
Joined: Mon Jun 14, 2010 12:32 am

#4 Postby Ajent » Fri Jun 18, 2010 1:41 am

It may be a problem with my code but I've discovered the same happens when attempting to use the new pivot indicator (as supplied with v2) in v1 - the indicator displays incorrectly during testing until I disconnect and select File Menu -> Rebuild All. I have tried it with v2 and it works correctly...I'm guessing this means I need to upgrade.


Return to “FT API”

Who is online

Users browsing this forum: No registered users and 17 guests