|
Post by bobpit on May 22, 2015 15:57:08 GMT
It is a classic problem/algorithm. I am trying to find something in AFL but I can't. What I really want to do is implement the Ramer–Douglas–Peucker algorithm (description and pseudocode here: en.m.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm ). It I could not find code for the entire algorithm, but I am hoping to find for the shortestDistanceToSegment(..).
|
|
|
Post by bobpit on May 24, 2015 12:10:56 GMT
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on May 24, 2015 13:19:44 GMT
Of course AFL supports recursive formulas.
|
|
|
Post by bobpit on May 24, 2015 20:02:17 GMT
".... recursion (having a function call itself from within itself) is NOT supported as for now." www.amibroker.com/guide/a_userfunctions.htmlMaybe we are talking about different things? Couple of days ago I tried recursion and it did not work. Could you send me a very small afl code that uses recursion?
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on May 24, 2015 20:27:25 GMT
Recursion is achieved via loop or in some cases AMA, AMA2, Valuewhen, Cum
Loop example
_Z = 0; // initialize
for ( i = 1; i < BarCount; i++ ) { prev = _Z[ i - 1 ]; // PREV is previous value of _Z. _Z[ i ] = 0.4 * A[ i ] + 0.6 * prev; }
AMA2 example doing same as upper loop.
_Z = AMA2( _A, 0.4, 0.6 );
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on May 24, 2015 20:39:27 GMT
Another recursive ( self-referencing) loop example
x = 0; for ( i = 1; i < BarCount; i++ ) { x[ i ] = IIf ( C[ i ] > x[ i - 1 ], C[ i ], x[ i - 1 ] ); }
That can be replaced by simple array function
x = Highest( C );
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on May 24, 2015 20:44:58 GMT
The link in reply #3 says
AFAIU it means something like this
function myfunc( per ) { array = myfunc( 10 ); return array*C; }
No?
|
|
|
Post by bobpit on May 24, 2015 20:48:03 GMT
Yes, it seems we are talking about different things. In your example I have not seen "a function call itself from within itself". This is the classic recursion example, the factorial (in C, taken from www.programiz.com/c-programming/examples/factorial-recursion ): int factorial(int n) { if(n!=1) return n*factorial(n-1); } This is the one I failed to do in AFL. You say it is possible to do it in AFL?
|
|
|
Post by bobpit on May 24, 2015 20:49:56 GMT
function myfunc( per ) { array = myfunc( 10 ); return array*C; } No? YES! and the above code cannot run in AFL.
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on May 24, 2015 20:59:55 GMT
Yes, it seems we are talking about different things. In your example I have not seen "a function call itself from within itself". This is the classic recursion example, the factorial (in C, taken from www.programiz.com/c-programming/examples/factorial-recursion ): int factorial(int n) { if(n!=1) return n*factorial(n-1); } This is the one I failed to do in AFL. You say it is possible to do it in AFL? Of course you can do factorial in AFL function factorial( f ) { result = f; for ( i = f - 1;i >= 1;i-- ) result *= i; return result; }
|
|