[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] There are some AB users using Delphi to automated AB ?



PureBytes Links

Trading Reference Links

Hi Daniel,

Thanks for your code.
I will try it.

Tintin92



----- Original Message ----- 
From: "Daniel Ervi" <daniel@xxxxxxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Monday, November 08, 2004 6:02 PM
Subject: RE: [amibroker] There are some AB users using Delphi to automated
AB ?



Hi Guys,

The easiest (and fastest, in terms of code) way of automating AmiBroker is
to import the type-library, which will allow Delphi to use early binding.
You can use late binding, put there is a performance penalty for doing so,
and I find it harder to find bugs as you can't use the Delphi IDE's
type-checking features. Once you import the type library, it can be saved in
your Delphi environment (dclusr.dpk) and then can be used later by simply
adding "broker_tlb" to your uses clause.

An example is included below. Once the uses clause has broker_tlb, you can
then define a variable of type TApplication, which is an instance of
Amibroker. By declaring a variable of the type, and the instantiating the
object, you will be prompted with all the available methods and properties
by the code-completion features built in to Delphi. This can be a huge
time-saver, which is why I say use the TLB.

Try the example and let me know if it make sense. Both early and late
binding are shown. I uploaded the example to the Amibroker group at
http://finance.groups.yahoo.com/group/amibroker/files/, under the name
ABAutomation.zip.

Daniel
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComObj, Broker_TLB, StdCtrls, Buttons, OleServer;

type
  TForm1 = class(TForm)
    btnEarlyBinding: TButton;
    btnLateBinding: TBitBtn;
    procedure btnEarlyBindingClick(Sender: TObject);
    procedure btnLateBindingClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btnEarlyBindingClick(Sender: TObject);
var
  AFLFolder: string;
  AB, AA: OleVariant;
begin

  AFLFolder := 'C:\\Program Files\\AmiBroker\\AFL\\';

  AB := CreateOLEObject('Broker.Application');
  AA := AB.Analysis;

  AA.ClearFilters;
  AA.ApplyTo := 0;
  AA.RangeMode := 0;

  if AA.LoadFormula(AFLFolder + 'VolatilitySystem.afl') then begin
    AA.Backtest;
    AA.Report('C:\\report_export.htm');
  end;

  AB.Quit;

end;

procedure TForm1.btnLateBindingClick(Sender: TObject);
var
  AFLFolder: string;
  AB: TApplication;
  AA: Analysis;
  BacktestType: OleVariant;
begin
  AFLFolder := 'C:\\Program Files\\AmiBroker\\AFL\\';

  AB := TApplication.Create(nil);
  AA := AB.Analysis as Analysis;

  AA.ClearFilters;
  AA.ApplyTo := 0;
  AA.RangeMode := 0;

  BacktestType := 0;  // Use Portfolio backtester
  if AA.LoadFormula(AFLFolder + 'VolatilitySystem.afl') then begin
    AA.Backtest(BacktestType);
    AA.Report('C:\\report_export.htm');
  end;

  AB.Quit;
end;

end.




------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/