Amibroker AFL code for AFL-Excel Integration:
Script:
//——————————————————————————
//
// Formula Name: AFL-Excel Integration
// For more scripts, visit: www.marketsecrets.in
//——————————————————————————
//
// This example show how to control Excel directly from the AFL script via
// OLE-Automation interface.
//
//——————————————————————————
Buy = Cover =
Cross(C,MA(C,5));
Sell = Short =
Cross(MA(C,5),C);
PositionSize = IIf(Buy,BuyPrice,ShortPrice);
E = Equity(1);
Papier = Name();
EnableScript(“vbscript”);
<%
E = AFL(“E”)
Papier = AFL(“Papier”)
Set Excel = CreateObject(“Excel.Application”)
Excel.WorkBooks.Add
Set Sheet = Excel.WorkBooks(1).WorkSheets(1)
Sheet.Cells(1,1) = Papier
Sheet.Cells(1,2) = “Equity”
Sheet.Cells(1,3) = “DrawDown”
‘ do DrawDownu
MaxE = E(0)
For i = 0 to UBound(E)
Y = i+2
Sheet.Cells(Y,2).Value = E(i)
If E(i) > MaxE then
MaxE = E(i)
End If
Drawdown = 0 – ((MaxE – E(i))/MaxE * 100)
Sheet.Cells(Y,3).Value = Drawdown
Next
Sheet.Activate
Sheet.Columns(2).Select
‘…Equity…
Excel.Charts.Add
Set EquityCharts = Excel.Charts(1)
EquityCharts.Name = Papier + ” Equity”
EquityCharts.Type = 1
EquityCharts.HasLegend = 0
EquityCharts.HasTitle = 0
Sheet.Activate
Sheet.Columns(3).Select
Excel.Charts.Add
Set EquityCharts = Excel.Charts(2)
EquityCharts.Name = Papier + ” DrawDown”
EquityCharts.Type = 1
EquityCharts.HasLegend = 0
EquityCharts.HasTitle = 0
Excel.Visible = 1
%>