How to automate Amibroker using Alice Blue

For Amibroker Automation, it is fairly easy - All you have to do is to write the Buy order and Sell order in some file once the signal is generated in Amibroker. (edited)

Here is a snippet I copied from the internet for doing the same -

file = "C:\\Users\Dexter\Desktop\Uscripts\al_orders.csv"; // change this to real location of your data file
dt = DateTime();
//
// Initialize variables
Buy = Sell = possize = 0; 
//
fh = fopen( file, "r" );
//
if( fh )
 {
     while( ! feof( fh ) )
     {
         line = fgets( fh );
         // get the ticker symbol from the file
         sym = StrExtract( line, 0 );
         // if ticker matches current symbol
         if ( Name() == sym )
         {
             // extract data from line of text
             trade = StrExtract( line, 1 );
             trade_datetime = StrToDateTime( StrExtract( line, 2 ) );
             price = StrToNum( StrExtract( line, 3 ) );
             shares = StrToNum( StrExtract( line, 4 ) );
             //
             if ( trade == "Buy" )
             {
                 newbuy = dt == trade_datetime;
                 Buy = Buy OR newbuy; // combine previous buy signals with new
                 BuyPrice = IIf( newbuy, price, BuyPrice );
                 possize = IIf( newbuy, shares, possize );
             }
             //
             if ( trade == "Sell" )
             {
                 newsell = dt == trade_datetime;
                 Sell = Sell OR newsell; // combine previous sell signals with new
                 SellPrice = IIf( newsell, price, SellPrice );
             }
         }
     }
     //
     fclose( fh );
 }
 else
 {
     Error( "ERROR: file can not be open" );
 }
//
SetPositionSize( possize, spsShares );
1 Like
Middle Band = 20 day moving average
Upper Band = 20 day moving average + (20 Day standard deviation of price x 2) 
Lower Band = 20 day moving average - (20 Day standard deviation of price x 2)

You can see a worked-out example here - https://colab.research.google.com/drive/1RTir7sg2dkLYnEDLia93udSPY-MI2Fi4

Hi Ji,

How can i do automatic trading from Amibroker to Alice blue, Could you please help me!

1 Like

There is no official bridge of their API. So the easiest solution is to put the Amibroker trade output to a file and make a python with “While True” statement to read the file if exists and destroy after reading.