About‎ > ‎

Driving AmiBroker Analysis from .NET console application

.NET code

using System;
using AmiBroker.Automation;

namespace AmiBroker.Automation.Samples
{
    class Program
    {
        static void Main(string[] args)
        {
            // start AmiBroker
            AmiBroker.Automation.Application app = new AmiBroker.Automation.Application();

            // make AB's window visible
            app.Visible = true;

            // get the analyzis object
            Analysis analyzis = app.Analysis;

            // scan the "Example.afl" for the last year for the current stock
            analyzis.LoadFormula(@"C:\Program Files (x86)\AmiBroker\Formulas\Systems\Example.afl");
            analyzis.RangeFromDate = DateTime.Now.AddYears(-1);
            analyzis.RangeToDate = DateTime.Now;
            analyzis.ApplyTo = ApplyTo.CurrentStock;
            analyzis.Scan();

            // export the result
            analyzis.Export(@"C:\Program Files (x86)\AmiBroker\Formulas\Systems\Example.csv");

            // quit AB
            app.Quit();
        }
    }
}