I'm looking for some reassurance from people that have been using AFL for a while. I'm finding it difficult to get simple pieces of code to execute correctly and the User's Guide is providing examples that make no sense. Perhaps it is the use of arrays that is throwing me off. For example: 1. if( Status( "redrawaction" ) ==1 ) -- from page 1068 of guide 2. if( Status( âfirstbarinrange" ) ==1 ) According to the User's Guide, Status("statuscode") returns an array and both "redrawaction" and "firstbarinrange" are valid status codes. The syntax checker says the first example is okay and the second is not. I can understand why an array is not acceptable in an IF statement. What I don't understand is why the first example is okay. This is but one of many confusing aspects of AmiBroker. I ran a back test and it said that my short positions produced losses. Yet, when I look at the entry and exit prices they are clearly profitable. Essentially, AB reversed the entry and exit prices in it's profit calculations. I really would like AmiBroker to work and I fully admit that I probably am making mistakes as a newbie. But some reassurance that this can all be resolved if I just stick with it would be appreciated. And perhaps some words of wisdom on how to adjust to the AFL paradigm. For background I have coded in over two dozen languages and haven't had this much problem understanding what is going on since I was learning Assembler (one of my first languages). Normally, I can just grab a user guide and start coding. It should be noted that AmiBroker Support has been very responsive. However, their explanations often leave me still not knowing the answer to my question. And yes I did ask about the example above, but their answer made no sense to me. They said the first example doesn't return an array and the second one does, which happens to be contrary to what the User Guide says.
I've been using AFL for some years now and it is a pretty good system. The array processing takes some getting used to BUT once you get to mid level status, you'd be hard pressed to find something that comes close to speed and robustness. I tried it, left it, tried out ninja/then C++ in Sierracharts but portfolio level backtesting is really where it shines. What other platform can u simulate complex stuff such as pnl of option positions thru the use of its custom backtester? My suggestion to you is to read the tutorials, slap on the sample codes and learn slowly as you try to advance your knowlege. Build you list of questions and between support@amibroker.com , you should do ok. If you want to turbocharge your learning curve, go to Elance.com, hire a programmer and bang out your question list with consultant faster . I hired somone from india at $50/hour and while rate is a little high for my taste, I've saved weeks learning from him.
I'm using AB for many years and it works perfectly fine. The problems come from your coding mistakes because of being a newbie. It's as simple as that. As for why you can not use arrays is if(...) it is clearly mentioned in the coding mistakes examples of the AmiBroker's help Status can return array and number depending on the statuscode Status( "redrawaction" ) does not return array Status( âfirstbarinrange" ) returns array Anyway AFL is very easy. Problem of newbies is that they think too complicated.
Here is Iif() function in comparison to if and from AFL reference: <!-- PAGE BREAK --><table border="0" width="100%"> <tbody> <tr> <td valign="top"> IIf - immediate IF function </td> <td align="right" valign="top"> Trading system toolbox </td></tr></tbody></table> <table border="0" cellpadding="4" cellspacing="4" width="100%"> <tbody> <tr> <td valign="top" width="13%">SYNTAX </td> <td valign="top" width="87%">IIf( EXPRESSION, TRUE_PART, FALSE_PART ) </td></tr> <tr> <td valign="top">RETURNS</td> <td valign="top">ARRAY </td></tr> <tr> <td valign="top">FUNCTION </td> <td valign="top">"Immediate-IF" - a conditional function that returns the value of the second parameter (TRUE_PART) if the conditional expression defined by the first parameter (EXPRESSION) is true; otherwise, the value of third parameter is returned (FALSE_PART). Please note that IIF is a function - so the result of evaluation is returned by that function and should be assigned to some variable. IIf always evaluates both TRUE_PART and FALSE_PART, even though it returns only one of them. Because of this, you should watch for undesirable side effects. The following example shows one common error made with IIF function: IIF( condition, result = 7, result = 9 ); // THIS IS WRONG Correct usage is: result = IIF( condition, 7, 9 ); /* 7 or 9 is *returned* and assigned to a variable depending on condition */ When working on arrays, Iif function evaluates all bars, condition is checked on each bar and returned value for given bar is choosen appropriately on bar by bar basis. The following code shows how array operation of Iif is implemented internally. Take a look also at Understanding AFL chapter of the manual. . . . </td></tr></tbody></table>
Here are two other code examples Code: <code>[COLOR=#0000ff][B]SetBarsRequired[/B][/COLOR]( [B]sbrall[/B] ); [COLOR=#0000ff][B]RequestTimedRefresh[/B][/COLOR]( [COLOR=#800080]1[/COLOR] ); [COLOR=#0000ff][B]GetPerformanceCounter[/B][/COLOR]( [COLOR=#800080]1[/COLOR] ); [COLOR=#008000]// iterate from first to last bar of array [/COLOR][COLOR=#800040][B]for[/B][/COLOR]( i = [COLOR=#800080]0[/COLOR]; i < [B]BarCount[/B]; i++ ) { [COLOR=#800040][B]if[/B][/COLOR]( [B]Close[/B][ i ] > [B]Open[/B][ i ] ) [COLOR=#008000]// CORRECT [/COLOR] Color[ i ] = [B]colorGreen[/B]; [COLOR=#800040][B]else[/B][/COLOR] Color[ i ] = [B]colorRed[/B]; } [COLOR=#0000ff][B]Plot[/B][/COLOR]( [B]Close[/B], [COLOR=#800080]"Colored Price - iterating from 0 to Barcount-1"[/COLOR], Color, [B]styleBar[/B] ); performance = [COLOR=#0000ff][B]GetPerformanceCounter[/B][/COLOR](); [COLOR=#0000ff][B]GfxSetBkMode[/B][/COLOR]( [COLOR=#800080]0[/COLOR] ); [COLOR=#0000ff][B]GfxSetTextColor[/B][/COLOR]( [B]colorWhite[/B] ); [COLOR=#0000ff][B]GfxSelectFont[/B][/COLOR] ( [COLOR=#800080]"lucida console"[/COLOR] , [COLOR=#800080]9[/COLOR] ); [COLOR=#0000ff][B]GfxTextOut[/B][/COLOR] ( [COLOR=#800080]"execution: "[/COLOR] + [COLOR=#0000ff][B]NumToStr[/B][/COLOR]( performance, [COLOR=#800080]1.4[/COLOR] ) + [COLOR=#800080]" ms"[/COLOR], [COLOR=#800080]5[/COLOR] , [COLOR=#0000ff][B]Status[/B][/COLOR] ( [COLOR=#800080]"pxchartheight"[/COLOR]) - [COLOR=#800080]20[/COLOR] );</code> Code: <code>[COLOR=#0000ff][B]SetBarsRequired[/B][/COLOR]( [B]sbrall[/B] ); [COLOR=#0000ff][B]RequestTimedRefresh[/B][/COLOR]( [COLOR=#800080]1[/COLOR] ); [COLOR=#0000ff][B]GetPerformanceCounter[/B][/COLOR]( [COLOR=#800080]1[/COLOR] ); bi = [COLOR=#0000ff][B]BarIndex[/B][/COLOR](); [COLOR=#008000]// array [/COLOR] [COLOR=#008000]// converting array to single number [/COLOR]startvalue = [COLOR=#0000ff][B]FirstVisibleValue[/B][/COLOR]( bi ); [COLOR=#008000]// not an array as it points to single value of barindex array [/COLOR]endvalue = [COLOR=#0000ff][B]LastVisibleValue[/B][/COLOR]( bi ); [COLOR=#008000]// same here, not an array [/COLOR] [COLOR=#800040][B]for[/B][/COLOR]( i = startvalue; i <= endvalue; i++ ) { [COLOR=#800040][B]if[/B][/COLOR]( [B]Close[/B][ i ] > [B]Open[/B][ i ] ) [COLOR=#008000]// CORRECT [/COLOR] Color[ i ] = [B]colorGreen[/B]; [COLOR=#800040][B]else[/B][/COLOR] Color[ i ] = [B]colorRed[/B]; } [COLOR=#0000ff][B]Plot[/B][/COLOR]( [B]Close[/B], [COLOR=#800080]"Colored Price - iterating from FVV to LVV of chart"[/COLOR], Color, [B]styleBar[/B] ); performance = [COLOR=#0000ff][B]GetPerformanceCounter[/B][/COLOR](); [COLOR=#0000ff][B]GfxSetBkMode[/B][/COLOR]( [COLOR=#800080]0[/COLOR] ); [COLOR=#0000ff][B]GfxSetTextColor[/B][/COLOR]( [B]colorWhite[/B] ); [COLOR=#0000ff][B]GfxSelectFont[/B][/COLOR] ( [COLOR=#800080]"lucida console"[/COLOR] , [COLOR=#800080]9[/COLOR] ); [COLOR=#0000ff][B]GfxTextOut[/B][/COLOR] ( [COLOR=#800080]"execution: "[/COLOR] + [COLOR=#0000ff][B]NumToStr[/B][/COLOR]( performance, [COLOR=#800080]1.4[/COLOR] ) + [COLOR=#800080]" ms"[/COLOR], [COLOR=#800080]5[/COLOR] , [COLOR=#0000ff][B]Status[/B][/COLOR] ( [COLOR=#800080]"pxchartheight"[/COLOR]) - [COLOR=#800080]20[/COLOR] ) ;</code> <code></code> Both plot the same but the second one iterates from first visible value of array to last visible value of array. If you turn off QuickAFL via SetBarsRequired( sbrall ); as done in both codes then you will see that the second one executes faster then. If turning on QuickAFL then both execute at similar times.
Per AmiBroker 5.70 Userâs Guide: Status - get run-time AFL status information SYNTAX status( ââstatuscodeââ ) RETURNS ARRAY FUNCTION Returns run-time status of the analysis engine. I think my problem is that I believed the User's Guide when it said that Status() returns an ARRAY. As I said, "I can understand why an array is not acceptable in an IF statement. What I don't understand is why the first example is okay." Why is one ARRAY okay and another is not?
There is no such thing as "one array is OK and another one is not". You can not use any array within if(...) statement except by accessing array elements for example the way seen in the previous posts. As for status() function, not every status code returns array. Just the following bar related status codes return array "barinrange" "barvisible" "firstbarinrange" "lastbarinrange" "firstvisiblebar" "lastvisiblebar" "firstvisiblebarindex" "lastvisiblebarindex" "firstbarintest" "lastbarintest" pretty obvious actually. All others return non array. "axisminy" for example can not return array since it is related to price axis and to one extreme value of price axis. Just make a suggestion/complain to AB's support if you think there is an info missing in the help.
I purchased AmiBroker at the end of the trial period. This is not simple-to-use software. It will take a great deal of time to learn, though basic functionality has already been accomplished. However, I am satisfied it is the best option available for my purposes. Good luck in your trading.
I'm currently taking a look at Amibroker. I am also working with NinjaTrader as well. I want to be able to back test systems, and forward paper trade live. The license feel on NT turns me off, as well as the cost for data feeds. I am not sure if Amibroker is much better on data fees. Any advice would be appreciated.