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

    trash

    Posts:
    412
    Likes Received:
    17
    Joined:
    Mar 31, 2012
    Yes, that's correct.

    Yes, that's correct too.
    FYI, I have posted it in database management thread few days back (for cases where some symbol(s) and their information(s) would get lost for some reason).
    http://amibrokerforum.proboards.com/thread/220/database-management
     
  2. fxtraders

    fxtraders

    Posts:
    33
    Likes Received:
    0
    Joined:
    May 15, 2016
    Question 1: It seems like User defined function don't return range of numbers as it does return without using function ..

    Code:
    SetBarsRequired( -2, -2 );
    Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
     
    
    function tf_ma(e,d)
    {
    global i;
    for (i=e; i<d; i++)
    {
      tf = i * in1Minute;
      TimeframeSet(tf);
        meme =MA(C, 15);
       TimeframeRestore();
    }
     m = TimeFrameExpand(meme,tf,expandPoint);
     for( b = 0; b < BarCount; b++ ) {
          //PlotText(" " , b, L[ b ], colorRed, colorDefault, -12 );
          if(m[b])  PlotText(" "+(i), b, L[b]-1-(i), colorCustom1);
       }
     return m;
    }
     tf_ma(1,3); // calling the function
    
    Question 2:


    If you want to overlay Daily Timeframe Chart on Weekly Chart .. (Lower timeframe on higher timeframe )

    1. Open Weekly timeframe

    2. code:
    Code:
    _SECTION_BEGIN("Formula");
    ddo = TimeFrameGetPrice( "O", inDaily, 0, expandPoint );
    dh = TimeFrameGetPrice( "H", inDaily, 0, expandPoint );
    dl = TimeFrameGetPrice( "L", inDaily, 0, expandPoint );
    dc = TimeFrameGetPrice( "C", inDaily, 0, expandPoint );
    
    PlotOHLC( ddo, dh, dl, dc, "Daily Close", colorWhite, styleCandle );
    Plot( Close, "Daily Close", colorBlue );
    _SECTION_END();
    
    It doesn't work .. (Lower to Higher timeframe doesn't work )
    Vice versa as usual Higher to lower (weekly on daily timeframe) does work ..

    Lower to Higher timeframe ?? No ..

    Happy New Year ??
     
  3. chipotle

    chipotle

    Posts:
    43
    Likes Received:
    0
    Joined:
    Jan 27, 2013
    Hi all and a happy new year.

    I am having real trouble with writing this. Can anybody help please?

    I am looking to identify days where the volume is greater than any DOWN DAY's volume over the past 5 days.

    The part in bold is what i can't figure out ie so that we are ignoring and previous UP day volume in the past 5 days.

    This is as far as I can get but obviously it is not what I want as is taking into account all days no matter if they were up days or down days.

    V>ref(HHV(V,5),-1);

    Thanks for any help.
     
  4. chipotle

    chipotle

    Posts:
    43
    Likes Received:
    0
    Joined:
    Jan 27, 2013
    Thanks again Gringotts. That's pretty darn good. Is there any way to do this without the ROC formula as that seems to filter out some days where the rise in price isn't that great?
     
  5. Gringotts Bank

    Gringotts Bank

    Posts:
    6,175
    Likes Received:
    604
    Joined:
    Jun 30, 2007
    Hoping someone can help me with multi-timeframe backtesting. I've read the AB tutorial many times and always got hung up. Time I got this sorted.

    So could someone please post a code for something like the following, including what A/A time frame settings to use:

    "if yesterday's daily close observed a stochastic cross, then today, buy MA cross on 5 minute time frame".

    TIA
     
  6. James Woods

    James Woods

    Posts:
    14
    Likes Received:
    0
    Joined:
    Aug 17, 2016
    Hi All,

    I'm looking to find out a little bit more information about this function. Like most I currently use Norgate for Australian & U.S. equity data however I've also starting building databases for other exchanges as well importing through the Import Wizard. I have the dates that specific equities joined and left the index i.e. FTSE100. I'm trying to figure out if it is possible to use the IsIndexConstituent function with this information or if there is a different function that would work equally as well.

    At the moment I am building quarterly watch lists which contain the equities included for the quarterly re balance. This almost works perfectly except for when a intra-quarter addition/removal happens due to M&A hence why I am looking to be able to utilize something similar to the IsIndexConstituent function.

    Any help is greatly appreciated!

    Many thanks,

    James
     
  7. Gringotts Bank

    Gringotts Bank

    Posts:
    6,175
    Likes Received:
    604
    Joined:
    Jun 30, 2007
    Thanks for the reply. I figured it out eventually.
     
  8. colydog

    colydog

    Posts:
    2
    Likes Received:
    0
    Joined:
    Jan 23, 2017
    Hi all

    new to the forum and AFL!

    i can mange the basics ok but stuggle on the custom back test

    what i am trying to do is:
    I use Norgate premium data,

    what I am trying to do is rank the 10 industry groups based on ROC. I plan to use ETF tickers for this.

    Once ranked i then want to buy the weakest 2 stocks based on ROC in the top 3 industry groups

    is it possible to do this multi level ranking?

    Thanks!!!
     
  9. James Woods

    James Woods

    Posts:
    14
    Likes Received:
    0
    Joined:
    Aug 17, 2016
    Hi All,


    I’m starting to do some futures testing and looks for some help on position sizing. Is anyone able to point me to where I can find different position sizing methods for futures?


    Specifically looking to be able to base the position size on risk parity i.e. calculate the number of contracts to buy = (0.001 x equity)/(ATR50 * PointValue).


    The logic behind this is that multiplying the average true range by the point value of the specific futures contract results in how much profit/loss to expect from a normal days movements. Setting the risk factor to 0.001 meaning I’m willing to get an impact of 0.1% on my portfolio, and therefore need to multiply the risk factor with the portfolio equity to arrive at the daily impact in dollars. Then dividing this by the expected average impact of each contract fives the number of contracts to buy.


    My understanding is that the calculation should look like this, however I’m having difficulty with the equity part of the equation. Does anyone know how to pull in the current equity portfolio value?


    Riskfactor = Param("Risk Factor",0.01,0.005,1,0.005);

    Risk = (Riskfactor*Equity())/(Ref(ATR(50),-1) * PointValue);

    PositionSize = Risk * MarginDeposit;

    Any help is greatly appreciated.

    Thanks,

    James
     
  10. James Woods

    James Woods

    Posts:
    14
    Likes Received:
    0
    Joined:
    Aug 17, 2016
    I should add I've tried Foreign("~~~EQUITY","C"); but does not seem to work correctly.
     
  11. colydog

    colydog

    Posts:
    2
    Likes Received:
    0
    Joined:
    Jan 23, 2017

    i think use SETOPTION UsePrevBarEquityForPosSizing

    for risk can use:
    Risk = 2;
    PstSize = Risk * buylimitprice / StopAmount;
    SetPositionSize( pstsize, spspercentofequity );
     
  12. Wysiwyg

    Wysiwyg Everyone wants money

    Posts:
    8,424
    Likes Received:
    260
    Joined:
    Aug 8, 2006
  13. James Woods

    James Woods

    Posts:
    14
    Likes Received:
    0
    Joined:
    Aug 17, 2016
    Hi Wysiwyg,

    Thanks for that, originally I thought this would not work correctly given I was looking for it to have no great impact than 0.2% of my total equity per day. However after manually calculating the position size based off the number of contracts and matching it against this it works perfectly.

    Thanks for the help,

    James
     
  14. rb250660

    rb250660

    Posts:
    258
    Likes Received:
    41
    Joined:
    Jan 13, 2013
    Hi guys,

    I am writing a strategy that uses daily bars but trades only once a week. I can't change the time frame to weekly because I need daily bars for certain reasons.

    I need a code snippet that returns a true condition if it is the first trading day of the week. Can anyone help me out? I've tried a few things and gotten close but nothing I am prepared to rely on for live trading.

    Cheers
    rb
     
  15. rb250660

    rb250660

    Posts:
    258
    Likes Received:
    41
    Joined:
    Jan 13, 2013
    Further to my previous post I also need to do the same thing but for the last day of the week.
     
  16. Wysiwyg

    Wysiwyg Everyone wants money

    Posts:
    8,424
    Likes Received:
    260
    Joined:
    Aug 8, 2006
    If you look in the functions list there is whet you need. Dayofweek == 1 etc.
     
  17. rb250660

    rb250660

    Posts:
    258
    Likes Received:
    41
    Joined:
    Jan 13, 2013
    Yep. Answered my own question I think. The following finds the first trading day of the week.

    DayOfWeek() < Ref( DayOfWeek(), -1 );
     
  18. trash

    trash

    Posts:
    412
    Likes Received:
    17
    Joined:
    Mar 31, 2012
    Here is another tip.
    If you have multiple calls of the same array function then store it to a variable. That way it is called just one time.
    This is especially recommended if your code(s) become multiple hundreds or thousands of lines long.
    I have seen dozens of AFLs were functions (having same settings) are called hundreds of times over and over again. That's ridiculous.

    So using your upper basic example do like so, for example

    Code:
    dow = DayOfWeek();
    
    startofweek = dow  < Ref( dow, -1 );
    It's like learning to drive bicycle the first time, either you start driving wrong or correctly and safely removing bad habits right from the start.
     
  19. ozcabman

    ozcabman

    Posts:
    3
    Likes Received:
    0
    Joined:
    Mar 6, 2017
    Hi,

    I am new to Amibroker and programming so any help with this (hopefully basic) problem is appreciated.

    I have coded a basic 20 period breakout system but have the following problem:

    When I look on the backtest report it appears that not all relevant trades are included. For example, the backtest report shows one trade for IMI.L over a 12 year period. However when I look on the chart for IMI there are at least 6 trades.

    I don't think the problem is a result of the system being fully invested and therefore the missing trades are not included. I've specified a maximum of 20 position but the system never gets to a point where there are 20 positions.

    Again, thanks for any help. I need to move on from a few time consuming problems now.

    Here is the code at the moment. Apologies for the amateurish nature of code but it is a reflection of my inexperience.

    Code:
    SetOption("MaxOpenPositions", 20);
    SetPositionSize(5, spsPercentOfEquity);
    
    Index = Foreign ("^FTSE", "C", True);
    IndexMa = Index >= MA(Index, 10);
    
    HighestValue = HHV(C, 20);
    LowestValue= LLV(C, 20);
    
    // ATR Stop Length //
    stopLength = (7 * ATR(10));
    
    // Buys and sells //
    Buy = C >= HighestValue AND IndexMA;
    Sell = C = 0;
    
    // Stop loss //
    ApplyStop (stopTypeTrailing, stopModePoint, stopLength, 2, True, 1);
    
    // Plotting stop loss //
    Equity(1, 0); // evaluate stops, all quotes
    
    inTrade = Flip (Buy, Sell); // True when buy / False when sell
    
    SetOption ("EveryBarNullCheck", True); // checks for null bars
    
    stopline = IIf (inTrade, HighestSince (Buy, H - stopLength), Null);
    
    Plot(stopline, "Trailing Stop Line", colorRed, styleLine, 0, 0, 0, 0);
    
    
    Plot(HighestValue, "High", colorGreen, styleLine, 0, 0, 0, 0);
    
    ribbonColor = IIf (IndexMA , colorGreen, colorRed); // color the ribbon. If IndexMA is true, colorGreen, if not true, Red
    Plot (3, "", ribbonColor, styleArea|styleOwnScale, 0, 100); // plot the ribbon
     
  20. trash

    trash

    Posts:
    412
    Likes Received:
    17
    Joined:
    Mar 31, 2012
    Check you initial equity setting. It could be too low since you have set 5% of equity as position size.
    Also check "Limit trade size as % of entry bar volume" in backtest settings' Portfolio tab.

    BTW why do you set price to zero in this line?
    Sell = C = 0;

    Just use
    Sell = 0;