• Australian (ASX) Stock Market Forum

Hello and welcome to Aussie Stock Forums!

To gain full access you must register. Registration is free and takes only a few seconds to complete.

Already a member? Log in here.

Amibroker FAQ

Discussion in 'Software and Data' started by RichKid, Jul 15, 2005.

  1. debtfree

    debtfree

    Posts:
    554
    Likes Received:
    682
    Joined:
    Aug 21, 2008
    Don't know if this is any help but a quick google I located this https://www.marketcalls.in/amibroker/profit-table-afl-code-yearly-max-drawdown.html
    It might lead you along the path you wanted, hope it helps.

    Edit: Sorry @Roller_1 after re-reading I misunderstood what you were after. Sorry mate
     
    Last edited: May 29, 2020
    Trav. and Roller_1 like this.
  2. Roller_1

    Roller_1

    Posts:
    304
    Likes Received:
    71
    Joined:
    Sep 13, 2013
    Thanks, i thought i might've been able to manipulate the standard table but the solution obviously isn't so straight fwd.
     
  3. Roller_1

    Roller_1

    Posts:
    304
    Likes Received:
    71
    Joined:
    Sep 13, 2013
  4. Trav.

    Trav.

    Posts:
    842
    Likes Received:
    1,118
    Joined:
    Nov 27, 2017
    @Roller_1 well there goes my Friday night....googling some more AmiBroker stuff.

    Yes I lead an exciting life :laugh::laugh::laugh:
     
    Roller_1 likes this.
  5. Roller_1

    Roller_1

    Posts:
    304
    Likes Received:
    71
    Joined:
    Sep 13, 2013
    Haha don't worry i've been there, easy to waste hours tinkering #iso

    The idea come from another group i'm in but he uses excel to create a pivot table. Would be good to have it straight away
     
    Trav. likes this.
  6. Trav.

    Trav.

    Posts:
    842
    Likes Received:
    1,118
    Joined:
    Nov 27, 2017
    @debtfree I was checking out that link which led me to the profit table AFL file.

    That's pretty interesting and definitely opens up some options when wanting to customise. Good find mate!
     
    debtfree likes this.
  7. debtfree

    debtfree

    Posts:
    554
    Likes Received:
    682
    Joined:
    Aug 21, 2008
  8. Trav.

    Trav.

    Posts:
    842
    Likes Received:
    1,118
    Joined:
    Nov 27, 2017
    The way I understand the back test report feature is that the file '3. Profit Table' is called and that generates the table in HTML.

    Now for someone smarter than me they could manipulate the existing file to use any calculation (like the one below from your original post) to populate the table.

    /////////////////////////////////////////////////
    // CAR% calculation
    /////////////////////////////////////////////////
    YearCount = MonthCount / 12;
    turnover = EQ[ BarCount - 1 ] / EQ[ startbar ];
    CAR = ( -1 + turnover ^ ( 1 / YearCount ) ) * 100;

    So the existing file (report) uses equity to start with then calculates the change monthly / yearly etc.

    upload_2020-5-29_16-56-25.png

    Build another section of code below the existing, replace equity with required data then wah-lah magic all done .. :roflmao::roflmao::roflmao: easy -peasy
     
    rnr and debtfree like this.
  9. wasp

    wasp

    Posts:
    10
    Likes Received:
    5
    Joined:
    Jan 11, 2020
    Hi CNH, did you ever have any luck with this?
     
  10. Trav.

    Trav.

    Posts:
    842
    Likes Received:
    1,118
    Joined:
    Nov 27, 2017
    I might just jump in here as I knocked up a trail stop system this arvo based on the above post from @wasp and thought that it would be a good talking point for all of us AmiBroker users.

    so basically the below comprises of the following

    - Index Filter using $XAO
    - $XAO (Grey) plotted against $XAO Moving Average (10 period) (Pink)
    - Test is Close > MA == Healthy
    - Ribbon on bottom Green for Healthy ** note scaling appears to be out for some reason​

    - Price Chart / System
    - Standard Chart from AmiBroker
    - EMA (20) (Aqua) Cross from snippet library
    - Trail Stop
    - Based on AmiBroker standard Trailing Stop Loop with a couple of minor mod's
    - 2 x stop levels Standard 30% (Yellow) and Index Filter 10% (Red) switched via the Index Filter
    - Position Parameters
    - Standard AmiBroker Equal % Allocation added
    - Exploration
    - As per below used to help verify code

    upload_2020-5-30_14-55-36.png
    ** DO NOT TRADE THIS - FOR EDUCATIONAL PURPOSES ONLY **

    upload_2020-5-30_14-42-37.png

    Code:
    SetForeign("$xao"); // Replaces current stock code with XAO
    
    IndexFilter = Close > MA(Close,10);  // Basic moving average test
    Plot( Close, "$XAO", colorGrey40, styleLine | styleOwnScale ); // Plot XAO close price
    Plot( MA(Close,10), "$XAO MA", colorPink, styleLine | styleOwnScale ); // Plot XAO Moving Average
    IndexFilterHealthy = IIf( IndexFilter == 1 , colorGreen, Null );
        Plot( 1, "Index Healthy", IndexFilterHealthy, styleOwnScale| styleArea| styleNoLabel,-.5, 100);
    
    RestorePriceArrays();
    
    maxpos = 10; // maximum number of open positions
    SetOption("InitialEquity", 100000 ); // set initial equity = 100K
    SetOption( "MaxOpenPositions", maxpos );
    SetPositionSize( 100 / maxpos, spsPercentOfEquity );
    
    
    // Standard buy / sell system
    
    period = 20; // number of averaging periods
    m = EMA( Close, period ); // exponential moving average
    
    Buy = Sell = 0;
    Short = Cover = 0;
    
    Buy = Cross( Close, m ); // buy when close crosses ABOVE moving average
    
    // Trailing Stop loop
    
    TrailStopPercent =  1 - 30/100; // Normal Trail Stop set @ 30 % nice and loose
    IndexStopPercent =  1 - 10/100;  // Index Trail Stop set @ 10 % now tighter due to index filter mood change
    
    StopLevel = IIf( IndexFilter == 0, IndexStopPercent, TrailStopPercent); // Selects which value to use in trailing stop
    
    trailARRAY = Null;
    trailstop = 0;
    TrailStopSell = 0;
    
    for( i = 1; i < BarCount; i++ )
    {
       if( trailstop == 0 AND Buy[ i ] )
       {
          trailstop = High[ i ] * StopLevel [ i ] ;
       }
       else Buy[ i ] = 0;
    
       if( trailstop > 0 AND Close[ i ] < trailstop)
       {
          TrailStopSell[ i ] = 1;
          SellPrice[ i ] = trailstop;
          trailstop = 0;
        }
           
       if( trailstop > 0 AND TrailStopSell [i] == 0)
       {  
          trailstop = Max( High[ i ] * StopLevel [ i ], trailstop );
          trailARRAY[ i ] = trailstop;
       }
    }
    
    Sell = TrailStopSell OR Cross( m, Close ); // sell when closes crosses BELOW moving average
    
    Buy = ExRem(Buy,Sell);
    Sell = ExRem(Sell,Buy);
    
    // plots price chart and trail stop
    
    Plot( C, "Price", colorDefault, styleBar );
    Plot( m, "MA 20", colorAqua, styleLine );
    
    InTrade = Flip(Buy,Sell); // used to turn off trail stop plot
    Plot( IIf(InTrade, trailARRAY, Null),"trailing stop level", IIf( IndexFilter == 0, colorRed, colorYellow ), styleLine, Null, Null, 0, -1, 1);
    
    // Plots buy and sell signals
    
    PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
    PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
    PlotShapes(IIf(Buy, shapeupArrow, shapeNone),colorWhite, 0,L, Offset=-45);
    
    PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, L, Offset=-60);
    PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,L, Offset=-70);
    PlotShapes(IIf(Sell, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-65);
    
    
    Filter = Buy;
    
    AddColumn(Close,"Close",1.2); // current bar close
    AddColumn(High,"High",1.2); // Current bar high
    AddColumn(trailARRAY,"TS Value",1.2); // Based on % of High ( high select )
    AddColumn(100*(1-StopLevel),"Stop %",1.2); // displays which % value we are using depending on index filter
    AddColumn(IndexFilter, "Index Filter Active",1,
        IIf( IndexFilter, colorGreen, colorRed),
        IIf( IndexFilter, colorGreen, colorRed), 80);
    
    
     
    Qtrader, Rsthree, CNHTractor and 7 others like this.
  11. wasp

    wasp

    Posts:
    10
    Likes Received:
    5
    Joined:
    Jan 11, 2020
    Nice, thanks for sharing. That's really impressive.
    I can't figure out how to have a trailing stop stay at 10% after the market turns up again (which is what the WTT does).
     
    qldfrog likes this.
  12. Trav.

    Trav.

    Posts:
    842
    Likes Received:
    1,118
    Joined:
    Nov 27, 2017
    This part of the code should lock in the high value so when the market turns up the SP has to increase past the previous high level.

    trailstop = Max( High[ i ] * StopLevel [ i ], trailstop );

    upload_2020-5-30_16-30-25.png

    As can be seen below the trailing stop array doesn't move down with the SP.....basically holds last value

    upload_2020-5-30_16-28-25.png

     
    wasp, Lone Wolf, qldfrog and 4 others like this.
  13. CNHTractor

    CNHTractor

    Posts:
    78
    Likes Received:
    53
    Joined:
    Oct 6, 2011
    Hi, no I did not get to an answer on this Trailing Stop. I did get an index filter to work as a caution working with a second filter.

    Will be interested in looking at @trav's code this week.
     
    wasp likes this.
  14. Lone Wolf

    Lone Wolf

    Posts:
    436
    Likes Received:
    146
    Joined:
    Dec 4, 2008
    The issue with the ribbon not aligning with a cross of the MA and xao looks like it's due to using the "styleOwnScale" in the plot function. If you change it to "styleLeftAxis" it seems to work as they are now both aligned to the same reference point. I haven't used styleLeftAxis before.

    Code:
    Plot( Close, "$XAO", colorGrey40, styleLine | styleLeftAxisScale ); // Plot XAO close price
    Plot( MA(Close,10), "$XAO MA", colorPink, styleLine | styleLeftAxisScale ); // Plot XAO Moving Average
     
    wasp, qldfrog and Trav. like this.
  15. Trav.

    Trav.

    Posts:
    842
    Likes Received:
    1,118
    Joined:
    Nov 27, 2017
    @Lone Wolf awesome stuff mate, works great and thanks for finding a fix.

    updated version of the AFL attached with fix for aligning foreign plots , Date on X axis, ATH in chart title and another column in the exploration called "Signal" to display buy / sell signal.

    Enjoy
     

    Attached Files:

    Qtrader, wasp, Lone Wolf and 3 others like this.
  16. Trav.

    Trav.

    Posts:
    842
    Likes Received:
    1,118
    Joined:
    Nov 27, 2017
    As you know that there are many free systems out there that generate good results but end of the day they are only as good as the person using them.

    I have overridden a sell signal many times as I thought that I knew best but turns out my emotions are my weakness and I need to follow the system rules

    Some sample code attached which is profitable in a weekly mode on the XAO but would you be brave enough to follow it.

    Please don't blindly follow others as you need to understand what the system is doing or you might as well not buy AmiBroker and just pay someone to manage your account.

     

    Attached Files:

    rnr, yc1, wasp and 8 others like this.
  17. wasp

    wasp

    Posts:
    10
    Likes Received:
    5
    Joined:
    Jan 11, 2020
    I have a system that generated a buy signal last week for z1p based on a breakout (signal came out after it's price spiked). I am not trading this system, but if I was I would have been hesitant to place a "buy" order after such a huge spike. Does anyone have a simple code or rule that identifies price spikes like this?
     
  18. Trav.

    Trav.

    Posts:
    842
    Likes Received:
    1,118
    Joined:
    Nov 27, 2017
    @wasp maye look at GapUp to detect spike

    upload_2020-6-7_9-29-9.png

    or by some code like this

    GapUp = ( L > 1.10*Ref(H, -1) ); // today's Low 10% above yesterday's high
     
    rnr, qldfrog, wasp and 1 other person like this.
  19. wasp

    wasp

    Posts:
    10
    Likes Received:
    5
    Joined:
    Jan 11, 2020
    Thanks @Trav. , legend.
     
    rnr and Skate like this.
  20. qldfrog

    qldfrog

    Posts:
    5,090
    Likes Received:
    3,929
    Joined:
    Jun 8, 2008
    Must be the weather, but today i am in a mood to thank greatly some of the people here,less famous than our Superstars..we all know them
    And @Trav. @rnr deserve an accolade in term of AB help
    Thanks guys and especially here, thanks Trav.
     
    Qtrader, Newt, rnr and 3 others like this.
Loading...

Share This Page