AFL function exrem seemingly doesn't work

Discussion in 'App Development' started by hedron, Oct 17, 2014.

  1. hedron

    hedron

    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.
     
    systematictrader likes this.
  2. SetBacktestMode(backtestRegular );
     
  3. hedron

    hedron

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

    Could it be some setting that's forcing this behaviour?
     
  4. ST.M

    ST.M

    Last edited: Oct 17, 2014
    hedron likes this.
  5. ST.M

    ST.M

    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;
    }
     
  6. hedron

    hedron

    Last edited: Oct 18, 2014
  7. hedron

    hedron

    Is there a place where I could view the source of other functions?
     
  8. suraj

    suraj

    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.
     

  9. 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