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

Most liked posts in thread: Amibroker FAQ

  1. Trav.

    Trav.

    Posts:
    841
    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.
  2. Trav.

    Trav.

    Posts:
    841
    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.