// This file demonstrates how to use ExcelLink with Tradestation
// Import this code as strategy or indicator
// http://www.fx1.net - 2009
//
// This example outputs 100 rows from current symbol to excel

// function importing from addon
external: "excellink.dll", int, "ExcelStart",LPSTR,int;         
external: "excellink.dll", LPSTR, "ExcelVersion";       
external: "excellink.dll", int, "ExcelPutString",int,int,int,LPSTR;     
external: "excellink.dll", int, "ExcelPutValue",int,int,int,double;     
external: "excellink.dll", double, "ExcelGetValue",int,int,int;
external: "excellink.dll", LPSTR, "ExcelGetString",int,int,int;       
external: "excellink.dll", int, "ExcelFormatCellColor",int,int,int,int, int; 
external: "excellink.dll", int, "ExcelFormatCellFontSize",int,int,int,int;      
external: "excellink.dll", int, "ExcelFormatCellFont",int,int,int,int;  
external: "excellink.dll", int, "ExcelSaveFile",LPSTR;  
external: "excellink.dll", int, "ExcelSheetRename",int,LPSTR;
external: "excellink.dll", int, "ExcelPutCalc",int,int,int,LPSTR;
external: "excellink.dll", LPSTR,"ExcelCell",int,int;
external: "excellink.dll", int, "ExcelUnixTime";
 

Inputs: Filename("c:\temp\c1.xls"); 
Vars: Row(3),Col(2),Tab(1),ret(-1),Amount(0),i(0);

If BarNumber=1 then  
begin 
                // start excel minimized(flag 1) for speed reasons
                ret=ExcelStart(Filename,1);     

                if ret=0 then
                begin
                ExcelPutString(1,1,1,"Symbol : "+GetSymbolName+ " Version:"+
                ExcelVersion());            
                ExcelFormatCellFontSize(1,1,1,12); 
                ExcelFormatCellColor(1,1,1,White,Red);

                // captions
                ExcelPutString(Tab,Row,Col,"Date"); Col=Col+1;
                ExcelPutString(Tab,Row,Col,"Time"); Col=Col+1;
                ExcelPutString(Tab,Row,Col,"Open"); Col=Col+1;
                ExcelPutString(Tab,Row,Col,"Close"); Col=Col+1;
                ExcelPutString(Tab,Row,Col,"High"); Col=Col+1;
                ExcelPutString(Tab,Row,Col,"Low"); Col=Col+1;
                ExcelPutString(Tab,Row,Col,"Unixtime"); Col=Col+1;
                ExcelPutString(Tab,Row,Col,"Range"); Col=Col+1;
                ExcelPutString(Tab,Row,Col,"UnixTime"); Col=Col+1;
                // Bold and underline captions
                For i=2 to 20 begin ExcelFormatCellFont(Tab,Row,i,5); end;
                Row=Row+1; Col=2;
                end;

end;

If LastBarOnChart=false and Amount<100 and ret=0 then
begin
                ExcelPutValue(Tab,Row,Col,Date); Col=Col+1;     
                ExcelPutValue(Tab,Row,Col,time); Col=Col+1;     
                ExcelPutValue(Tab,Row,Col,Open); Col=Col+1;     
                ExcelPutValue(Tab,Row,Col,Close); Col=Col+1;    
                ExcelPutValue(Tab,Row,Col,High); Col=Col+1;     
                ExcelPutValue(Tab,Row,Col,Low); Col=Col+1;      
                ExcelPutValue(Tab,Row,Col,ExcelUnixTime() ); Col=Col+1;
                ExcelPutCalc(Tab,Row,Col,"="+ExcelCell(Row,Col-3)+"-"+ExcelCell(
                Row,Col-2));Col=Col+1;
                ExcelPutValue(Tab,Row,Col,ExcelUnixTime() ); Col=Col+1;
                Row=Row+1; Col=2;Amount=Amount+1; 
end;  
// save our work at last bar to save filename
if LastBarOnChart and ret=0 then Begin  ExcelSaveFile(Filename); End;