Australian (ASX) Stock Market Forum

Amibroker FAQ

I am just in the throes of working through Nick Radge's Weekend Trend Trader

I am the point of setting my trailing stops:

1. Since buy, if index filter continues true, Stop loss at 70% of high, until
2. Index filter has become not true, change stop loss of 90% of high since buy, until
3. Index filter returns true, then 70% of high subject to this stop loss being above stop loss in Condition 2

I have created some rudimentary rules, but these I know are way off. I would welcome some guidance on writing the AFL to implement the above trailing stop


Code:
SetForeign( "XAO" );


 Filter1 = C> MA( C, 10 );
 Filter3 =  Ref(MA( C, 10 ),-1)> Filter1;
 
RestorePriceArrays();


Filter = Filter1;


_SECTION_BEGIN("Buy_sell");
Hh = Ref(HHV(H,20),-1);


Buy = Iif(Filter,Cross(C,Hh),0);

//Trailing Stops:

//		1. Since buy, if index filter continues true, Stop loss at 70% of high, until
//		2. Index filter has become not true, change stop loss of 90% of high since buy, until
//		3. Index filter returns true, then 70% of high subject to this stop loss being above stop loss in Condition  2
 

Stop1 = IIf(Filter1,C<= Hh*.7,0);    		//stop condition1
Stop2 = IIf(Filter3, C<= Hh*.9,0);   		//stop condition2 
Stop3 = IIf(Ref(filter3,-1), C<= Hh*.9,0);  //stop condition3 


Sell = C<Stop1 OR C<Stop2 OR C<Stop3;

_SECTION_END();
 
I've recently purchased a license to Amibroker and have a Norgate Premium data subscription. I'd like to incorporate some fundamental data to filter scans based on PE/PEG ratios, EPS, Market cap, ROE etc. I only trade ASX equities.

I'd be interested in knowing if anyone else is doing this, where they obtain their data from, and how they incorporate into scans and back testing. Thanks!
 
Well done for using quality data in quality software.

I have got Amibroker but haven't got around to re-writing my scans from Metastock.

I use Lincoln Indicator's StockDoctor software and using their filters for Strong and Satisfactory stocks I narrow the market down to a scan list of currently 456 stocks.

I know nothing about funnymentals, that is what they specialise in and I take their word for it that they are removing the chaff.
So far it is working well.

Just my :2twocents
 
Thanks for the reply. I've seen StockDoctor and it looks like a very good product. But at 4x what I'm paying for my yearly data is's pretty steep if I'm just using it as a data feed to screen on a few fundamentals.

I'll keep exploring options.
 
Hi All,
Well, AB tells me that I've "left a file open". Since I've got many locations in the code where I've opened and closed files (I work a lot from historical lists), is there a means of determining which file? The open and close function calls are always contained in the same bracing (I never leave a file open while calling a procedure, etc.).
TIA,
RutheezKey
 
The troubleshooting aspect of my previous post remains valid. However, I did find the cause of my file remaining open. I'm mentioning it here, since I've not experienced this before. While the file was open, I attempted to save an extracted string as a static-variable. Problem was, I used "StaticVarSet" instead of "StaticVarSetText". Typically, I'll get an error message indicating that the function expects a different type (or something like that). In this case, I did not get that message, only the one telling me that a file was left open.

Always learning something!
 
i just recently purchased amibroker and got a subscription to premium data. i've been playing around with it for a few days and am impressed with the product.

one thing i'm still trying to understand is how to deal with ordinary dividends. running the backtest amibroker does not seem to account for stocks paying a dividend. is there something i'm not doing right? how are others dealing with this in their backtests?
 
i just recently purchased amibroker and got a subscription to premium data. i've been playing around with it for a few days and am impressed with the product.

one thing i'm still trying to understand is how to deal with ordinary dividends. running the backtest amibroker does not seem to account for stocks paying a dividend. is there something i'm not doing right? how are others dealing with this in their backtests?

Your data supplier should offer dividend adjusted price
 
one thing i'm still trying to understand is how to deal with ordinary dividends. running the backtest amibroker does not seem to account for stocks paying a dividend. is there something i'm not doing right? how are others dealing with this in their backtests?
I think you want to calculate the cash value by multiplying the share holding at ex-date and the cash dividend. I.e. 10000 shares x 20 cent dividend if the stock held at ex-date. another consideration is the franking credits if held for the 45 day post ex-date. I'm sure this could be done but you would need accurate financial data and a good AFL programmer.

Code:
Dividend = GetFnData("DividendPerShare"); 
DividendExDate = GetFnData("ExDividendDate");
DividendPayDate = GetFnData("DividendPayDate");
 
premium data does not adjust the price for ordinary dividends.
I have never seen a different share price than the one quoted by the stock exchange. Is there an alternative share price to the exchange quotes?
 
I have never seen a different share price than the one quoted by the stock exchange. Is there an alternative share price to the exchange quotes?

I'm just looking for a way for the backtester to give me a result that includes dividend returns. As it stands in the backtest if I buy CBA before its ex-date and then sell after its ex-date then the dividend is totally lost. If the prices are adjusted for ordinary dividends then I could run the backtester as is and the results would be fine.
 
If the prices are adjusted for ordinary dividends then I could run the backtester as is and the results would be fine.
I don't know what this means. When a stock goes ex-div, the share price usually adjusts down and this is the price the stock exchange quotes.
 
I don't know what this means. When a stock goes ex-div, the share price usually adjusts down and this is the price the stock exchange quotes.

Maybe an example would be more clear. CBA went ex-dividend on 17/2/15 and the dividend was $1.98. The closing price on 16/2 was $93.47 and on 17/2 it was $90.00. Now if I buy on the 16th and sell on the 17th in AmiBroker it indicates I lost $3.47 per share. To adjust for ordinary dividends (ignoring franking) on 16/2 the close price should be $93.47 - $1.98 = $91.49. If I have these prices running through the backtest then I would get a more accurate indication of my total return.
 
Maybe an example would be more clear. CBA went ex-dividend on 17/2/15 and the dividend was $1.98. The closing price on 16/2 was $93.47 and on 17/2 it was $90.00. Now if I buy on the 16th and sell on the 17th in AmiBroker it indicates I lost $3.47 per share. To adjust for ordinary dividends (ignoring franking) on 16/2 the close price should be $93.47 - $1.98 = $91.49. If I have these prices running through the backtest then I would get a more accurate indication of my total return.
I know of no data supplier that does this. If you find one let me know as I am always willing to learn.
 
yahoo does this. check out the adj close column when CBA goes ex dividend. yahoo is not that reliable with dividends however.

https://au.finance.yahoo.com/q/hp?a=11&b=12&c=1980&d=03&e=8&f=2015&g=d&s=CBA.AX,+&ql=1
Okay thanks. The theoretical price is only true for the close on the 16th. so for any other buy price prior what would be the buy price? Buy Price - Dividend = Dividend Adjusted Buy Price
or Sell Price + Dividend = Sell Price is a better solution

E.G.
CBA

Buy Date = 2 Feb. 2015
Buy Qty. = 100 shares
Buy Open Price (Adjusted for announced div.) $89.30 - $1.98 = $87.32

Sell Date = 17 Feb. 2015
Sell Open Price = $90.37
Profit = ($3.05 x 100) - 40 (brokerage in/out)
Profit = $265

OR

Buy Date = 2 Feb. 2015
Buy Qty. = 100 shares
Buy Open Price = $89.30

Sell Date = 17 Feb. 2015
Sell Open Price = $90.37 + $1.98 = $92.35
Profit = ($3.05 x 100) - 40 (brokerage in/out)
Profit = $265

AdjustedDivvySellPrice = SellPrice + GetFnData("DividendPerShare");
 
Okay thanks. The theoretical price is only true for the close on the 16th.
Correction. Dividend adjusted price is for close price back to last divvy date on 19th August 2014. This can't be true because the dividend amount would not be known that far back.
 
Correction. Dividend adjusted price is for close price back to last divvy date on 19th August 2014. This can't be true because the dividend amount would not be known that far back.

you can see how yahoo do it on the aug 2014 dividend. they accumulate the dividends of feb 2015 + aug 2014 and subtract it off the actual close to derive the adjusted price. this creates other problems as you can see the adjusted price starts drifting away from the actual price.

https://au.finance.yahoo.com/q/hp?s=CBA.AX&a=11&b=12&c=1980&d=03&e=8&f=2015&g=d&z=66&y=132
 
Top