AFL function exrem seemingly doesn't work

This is in reference to amibroker's AFL scripting language.

I have this in my code:

Buy = Cross(rs,0);
Sell = BarsSince( Buy ) >= 5;

buy = exrem ( buy, sell );
sell = exrem ( sell, buy );

rs is a simple array. The code seems pretty straight forward to me and I have no idea why it's not doing what I want it to do. I want it to sell 5 bars after the actual buy occurs. It does not do this. It sells 5 bars after the buy *signal*, regardless of the fact that the trade is still in play.

I was under the impression that the exrem function solved this issue. But this does not appear to be the case.

How can I rewrite this to have it sell 5 bars after the actual buy occurs? And not 5 bars after a buy signal while the trade is in play?

Thanks.
 
That doesn't seem to be working either. Thanks though.

Could it be some setting that's forcing this behaviour?
 
Needless to say that exrem does work fine.
Below there is an AFL example by Tomasz showing how it is internally coded.

Code:
/*
ExRem is *very* simple function. It just matches Buy with corresponding Sell
and removes extra signals between. It is NOT necessary for backtesting because
backtester takes care of it by itself, see http://www.amibroker.com/guide/h_portfolio.html

Here is how ExRem is internally coded (note that this is AFL equivalent,
internal function is written in C++ )

Best regards,
Tomasz Janeczko
amibroker.com
*/

function ExRemAFL( BuyTable, SellTable )
{
	up = False;
	result = False;

	for( i = 0; i < BarCount; i++ )
	{
		result[ i ] = False;

		if( !up && BuyTable[ i ] )
		{
			up = True;
			result[ i ] = True; // generate True (1) impulse on buy
		}

		if( up && SellTable[ i ] )
		{
			up = False; // reset the flag on first matching sell
		}
	}

	return result;
}
 
How can i backtest for a bracket order in the case below:

SL and target defined. But both occur in the very next candle (same candle) and Backtest is giving result as per close of the candle not as per actual price to determine whether SL or Target triggered first.
 
This is in reference to amibroker's AFL scripting language.

I have this in my code:

Buy = Cross(rs,0);
Sell = BarsSince( Buy ) >= 5;

buy = exrem ( buy, sell );
sell = exrem ( sell, buy );

rs is a simple array. The code seems pretty straight forward to me and I have no idea why it's not doing what I want it to do. I want it to sell 5 bars after the actual buy occurs. It does not do this. It sells 5 bars after the buy *signal*, regardless of the fact that the trade is still in play.

I was under the impression that the exrem function solved this issue. But this does not appear to be the case.

How can I rewrite this to have it sell 5 bars after the actual buy occurs? And not 5 bars after a buy signal while the trade is in play?

Thanks.


how long did it take u to learn the coding afl language, i currently pay someone to code things and iam wondering if i should learn it
 
Back
Top