Can not get "ReplaceStr" proc address

Examples step by step how to make your own automated strategy or user indicator
Message
Author
SquareMeal
Posts: 40
Joined: Wed Sep 15, 2010 6:52 am

Can not get "ReplaceStr" proc address

#1 Postby SquareMeal » Sat Oct 16, 2010 10:38 pm

I'm trying to install a custom Indicator and it won't install. This is a version of the RSI source code with some additional calculations to apply a Fisher Transform plus exponential, zero-lag smoothing to the result.

I once had a similar problem installing a strategy and found I needed to add a couple of lines to the Exports. I tried the same approach with this Indicator but have not been able to get it to work.

I am not sure of the best way to post my code for you to look at -- so I will post it in here as text. If you prefer a different method, please let me know. Thank you.

Code: Select all

//---------------------------------------------------------------------------
// Relative Strength Index indicator + Smoothed Inverse Fisher Transform
//---------------------------------------------------------------------------
library OMI;

uses
  SysUtils, classes, graphics, windows, IndicatorInterfaceUnit;

var
  // External variables
  period: integer;
  ApplyToPrice: integer;

  OMI: double;
  OMIalpha: double;
  P, Q, R, S, T: double;

  // Buffers
  _RSI, AvGain, AvLoss: TIndexBuffer;


//---------------------------------------------------------------------------
// Initialize indicator
//---------------------------------------------------------------------------
procedure Init; stdcall;
begin
  // define properties
  IndicatorShortName('OMI');
  SetOutputWindow(ow_SeparateWindow);
  SetFixedMinMaxValues(0, 100);
  AddLevel(12, psDot, 1, cl_GridColor);
  AddLevel(88, psDot, 1, cl_GridColor);
  SetEmptyValue(105);

  // register options
  AddSeparator('Common');

  RegOption('Period', ot_Integer, period);
  SetOptionRange('Period', 1, MaxInt);
  period := 4;

  RegOption('Apply to price', ot_EnumType, ApplyToPrice);
  AddOptionValue('Apply to price', 'Close');
  AddOptionValue('Apply to price', 'Open');
  AddOptionValue('Apply to price', 'High');
  AddOptionValue('Apply to price', 'Low');
  AddOptionValue('Apply to price', '(High + Low)/2');
  AddOptionValue('Apply to price', '(High + Low + Close)/3');
  AddOptionValue('Apply to price', '(High + Low + Close + Close)/4');
  ApplyToPrice := 0;

  RegOption('OMI alpha', ot_Double, OMIalpha);
  SetOptionDigits('OMIalpha', 2);
  OMIalpha := 0.35;

// create buffers
  _RSI := CreateIndexBuffer;
  AvGain := CreateIndexBuffer;
  AvLoss := CreateIndexBuffer;

  IndicatorBuffers(1);
  SetIndexBuffer(0, _RSI);
  SetIndexStyle(0, ds_Line, psSolid, 1, RGB($1E, $90, $FF));
  SetIndexLabel(0, 'RSI');
end;

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

end;

//---------------------------------------------------------------------------
// Calculate requested bar
//---------------------------------------------------------------------------
procedure Calculate(index: integer); stdcall;
var
  i: integer;
  diff, gain, loss: double;

  function GetPrice(index: integer): double;
  begin
    case ApplyToPrice of
      0:   result := Close(index);
      1:   result := Open(index);
      2:   result := High(index);
      3:   result := Low(index);
      4:   result := (High(index) + Low(index))/2;
      5:   result := (High(index) + Low(index) + Close(index))/3;
      6:   result := (High(index) + Low(index) + Close(index)*2)/4;
      else result := 0;
    end;
  end;

begin
  if Bars - index <= period then
    exit;

  if Bars - index = period + 1 then
    begin
      gain := 0;
      loss := 0;
      for i:=index to index + period - 1 do
        begin
            diff := GetPrice(i) - GetPrice(i + 1);
          if diff > 0 then
            gain := gain + diff
          else
            loss := loss - diff;
        end;
      AvGain[index] := gain/period;
      AvLoss[index] := loss/period;
    end
  else
    begin
      gain := 0;
      loss := 0;
      diff := GetPrice(index) - GetPrice(index + 1);
      if diff > 0 then
        gain := diff
      else
        loss := -diff;
      gain := (AvGain[index + 1]*(period - 1) + gain)/period;
      loss := (AvLoss[index + 1]*(period - 1) + loss)/period;
      AvGain[index] := gain;
      AvLoss[index] := loss;
      if loss = 0 then
        _RSI[index] := 100
      else
        _RSI[index] := 100 - 100/(1 + gain/loss);

      P := 0.1 * (_RSI[index] - 50);
      Q := (P * OMIalpha) + (Q * (1 - OMIalpha));
      R := (Q * OMIalpha) + (R * (1 - OMIalpha));
      S := Q - R;
      T := Q + S;
      OMI := ((exp(2*T)-1)/(exp(2*T)+1)+1)*50;
      _RSI[index] := OMI;
    end;

end;

exports

Init, Done, Calculate;

end.
[/code]
creativity + willful purpose

User avatar
Terranin
Site Admin
Posts: 833
Joined: Sat Oct 21, 2006 4:39 pm

#2 Postby Terranin » Sun Oct 17, 2010 9:56 am

What tool do you use to compile your code?
Hasta la vista
Mike

SquareMeal
Posts: 40
Joined: Wed Sep 15, 2010 6:52 am

#3 Postby SquareMeal » Sun Oct 17, 2010 12:12 pm

I compile with Lazarus Version 0.9.26.2 beta dated 2010-09-18 with FPC Version 2.2.2 SVN Revision 18980, i386-win32-win32/win64.

I copied the text of the source code to my clipboard, started a new project (library), and pasted the code in. After a "Save As" under a different name it now works!

Any idea what the problem was? If not, don't worry about it... I don't want you to spend time on something that is no longer a problem.

Thanks.
creativity + willful purpose

SquareMeal
Posts: 40
Joined: Wed Sep 15, 2010 6:52 am

best solution

#4 Postby SquareMeal » Sat Oct 30, 2010 8:08 am

The best solution for Lazarus users when working with source code for strategies and indicators:

Don't do "Save" ... do "Save All"

Don't do "Build" ... do "Build All"

Don't cut and paste code to start a new project.
Do "Project / Save Project As" and give it a new name.

These steps will insure easy compiling and installing into FT2.
creativity + willful purpose

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

#5 Postby FT Support » Sat Oct 30, 2010 4:33 pm

Hello SquareMeal,

Thank you for these comments, they are useful.
Check our other product here:
http://www.forexcopier.com

hjabu
Posts: 30
Joined: Fri Aug 21, 2009 9:30 am
Contact:

Cannot get "Init proc address"

#6 Postby hjabu » Wed Apr 20, 2011 11:52 am

I have suceed compile my dpr to dll , as install to my Ft a message appear,

Cannot get "Init proc address"

please explain to me What does it mean, or is there any code should I input again.

I ,m using delphi xe , it was much succes using delphi insteat lazarus...

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

#7 Postby FT Support » Thu Apr 21, 2011 3:15 am

Hello,

you need to have "Init" function in the "exports" section of your code, example is shown below:

Code: Select all

exports

Init, Done, Calculate;
Check our other product here:
http://www.forexcopier.com


Return to “Programming lessons”

Who is online

Users browsing this forum: No registered users and 23 guests