0

I want to implement an afl code to find Daily Loss Limit in intraday trading. I will use the code for backtesting around 200 days. I have the following code but it is with mistakes.

// identify new day
dn = DateNum();
newDay = dn != Ref( dn,-1);

// Daily Loss Limit
dll = Optimize("dll", 0, 5, 10000, 5 );

EquityCount = 10000;

for( i = 0; i < BarCount; i++ )
{  
// signals
Buy  =  ....;
Sell =  ....;

diff = (Equity(1) - Ref(Equity(1), -1));
EquityCount = EquityCount + diff;

// allow only dll
Buy = Buy AND EquityCount > dll;
}

Any help will be appreciated. Thanks.

1 Answers1

-1

First your code is completely wrong. Secondly Equity() function is single security function. It is obsolete.

Use custom backtest interface of AmiBroker instead. See AmiBroker help.

fxshrat
  • 89
  • 5
  • "First your code is completely wrong". If you're going to make such a sweeping statement, it would be helpful to elaborate on it. – ADyson Mar 25 '17 at 23:34
  • The AmiBroker manual already explains it in detail! For example "Understanding how AFL works" & "Common Coding mistakes in AFL ". Buy and Sell variables are arrays & Equity and Ref functions are array functions. So in order to access elements of arrays you have to apply subscripts. – fxshrat Mar 26 '17 at 00:05
  • Ok, so the manual explains it, but a) you didn't mention that as a reference source, and b) the purpose of SO is also to build up a repository of knowledge. Provide a link to the source, and also a summary saved here so that future readers will understand - links can often go stale. See http://stackoverflow.com/help/referencing and http://stackoverflow.com/help/how-to-answer – ADyson Mar 26 '17 at 18:44