Australian (ASX) Stock Market Forum

Post the code that is failing. Just copy it and paste it into the reply.

The membership of the forum is very helpful and supportive, but we cannot help if we cannot see the code.

Best, Howard
 
Help! I am trying to plot an indicator that flags every third Friday (or the closest previous trading day) in a month. I have gotten so far but have identified that in some months (see list below) the indicator isn't picking the closest day to the third Friday of the month. Any help appreciated.

Problem months:
April 2014
March 2008
April 2003
April 2000
April 1997
April 1992
April 1984
April 1981

The problem is to do with Easter it seems.

Code:
TimeDayNum = Day();
TimeDayName = DayOfWeek();
TimeDaysToFriday = ( 5 - TimeDayName + 7 ) % 7;
TimeFridayCount = floor( ( TimeDayNum + TimeDaysToFriday + 6 ) / 7 );
TimeThirdFridayDate = TimeDayNum + TimeDaysToFriday + ( 3 - TimeFridayCount ) * 7;
TimeThirdFriday = TimeDayNum == TimeThirdFridayDate;

Plot( TimeThirdFriday, "TimeThirdFriday", colorGreen );
 
Help! I am trying to plot an indicator that flags every third Friday (or the closest previous trading day) in a month. I have gotten so far but have identified that in some months (see list below) the indicator isn't picking the closest day to the third Friday of the month. Any help appreciated.

Problem months:
April 2014
March 2008
April 2003
April 2000
April 1997
April 1992
April 1984
April 1981

The problem is to do with Easter it seems.

Code:
TimeDayNum = Day();
TimeDayName = DayOfWeek();
TimeDaysToFriday = ( 5 - TimeDayName + 7 ) % 7;
TimeFridayCount = floor( ( TimeDayNum + TimeDaysToFriday + 6 ) / 7 );
TimeThirdFridayDate = TimeDayNum + TimeDaysToFriday + ( 3 - TimeFridayCount ) * 7;
TimeThirdFriday = TimeDayNum == TimeThirdFridayDate;

Plot( TimeThirdFriday, "TimeThirdFriday", colorGreen );

You get no output because in those cases element for Friday does not exists.
Why?
Because it is Good Friday -> Holiday

IF you want to have output nevertheless you would have to make a function that auto jumps to date of one bar before if element does not exist for a specific date.
 
I made the solution (for every third Monday). I just took the 'cross' of the two arrays to achieve an impulse signal at the desired (previous) bar as you suggested Trash. Thanks!

Code:
TimeDayNum = Day();
TimeDayName = DayOfWeek();
TimeDaysToFriday = ( 5 - TimeDayName + 7 ) % 7;
TimeFridayCount = floor( ( TimeDayNum + TimeDaysToFriday + 6 ) / 7 );
TimeThirdFridayDate = TimeDayNum + TimeDaysToFriday + ( 3 - TimeFridayCount ) * 7;
TimeThirdMonday = Cross( TimeDayNum, TimeThirdFridayDate );

Plot( TimeThirdMonday, "TimeDayNum", colorRed );
 
Last edited:
I tested your code and it does not seem correct. Sometimes it picks the third Monday and sometimes the fourth Monday of the month. Try an Exploration and you will see.

I have coded a solution for identifying the last trading day of the third week which is what I believe you were looking for. It can probably be done more elegantly but it does seem to work for all months in past many years except ... Sept 2001. Market closed for rest of week after only trading on the Monday. Of course it would be easy enough to add code to cover that exception but no point to that really.
//////////////////////////////////////////////////////////////////////////////////////
// Attempting to identify the last trading day of each week of each month
TradingDayThisMonth = BarsSince( Day() < Ref( Day(), -1 ) ) + 1;
dow = DayOfWeek();

Eow = dow > Ref( dow, 1 ); // last trading Day of week

End1stWeek = Eow AND TradingDayThisMonth <= 5;
End2ndWeek = Eow AND BarsSince( End1stWeek ) <= 5 AND BarsSince( End1stWeek ) > 1;
End3rdWeek = Eow AND BarsSince( End2ndWeek ) <= 5 AND BarsSince( End2ndWeek ) > 1;

/// Explore to see the results ///
Filter = 1;
AddColumn( Close, "Close" );
AddColumn( IIf( dow == 1, 'M', IIf( dow == 2, 'T', iif( dow == 3, 'W', IIf( dow == 4, 'R', 'F' ) ) ) ), "Day", formatChar );
AddColumn( DayOfWeek(), "D.O.W.", 1.0 );
AddColumn( TradingDayThisMonth, "TradingDayThisMonth", 1.0 );
AddColumn( End1stWeek, "End1stWeek", 1.0, IIf( End1stWeek, colorWhite, colorDefault ), IIf( End1stWeek, colorDarkBlue, colorDefault ) );
AddColumn( End2ndWeek, "End2ndWeek", 1.0, IIf( End2ndWeek, colorWhite, colorDefault ), IIf( End2ndWeek, colorDarkRed, colorDefault ) );
AddColumn( End3rdWeek, "End3rdWeek", 1.0, IIf( End3rdWeek, colorWhite, colorDefault ), IIf( End3rdWeek, colorDarkYellow, colorDefault ) );

Plot( End3rdWeek, "End3rdWeek", colordarkBlue, styleHistogram | styleThick | styleOwnScale );

upload_2017-2-28_18-35-5.png
 
My intention is to pick the third Friday and trade on the Monday. I have checked my code, it seems fine to me. Your code is picking the fourth Monday in January and April some years for me.
 
My intention is to pick the third Friday and trade on the Monday. I have checked my code, it seems fine to me. Your code is picking the fourth Monday in January and April some years for me.

Wow, our computers must be working differently. I looked over my exploration and found no problems in any April or January in the past 20 years?

Mistakes in my code I found occurred,
July 2005 (first Friday was July 1st, and then 4th of July holiday was a Monday and ruined my count)

Sept 2006 (first Friday was Sept 1st, and then Labor Day Monday Sept 4th ruined my count)

July 2011 (first Friday was July 1st, and then 4th of July holiday was a Monday and ruined my count)

July 2016 (first Friday was July 1st, and then 4th of July holiday was a Monday and ruined my count)


Your code (if attempting to identify the first trading day after the end of the third Friday) was frequently wrong. Not sure why we get different results but best of luck.
 
Isn't that strange. I bet the discrepancies with your code over my check were on Australian holidays assuming you are checking against a US index symbol. I am checking against the Australian All Ordinaries index (XAO). I checked all the way back to 1985. Perhaps that's where it's coming unstuck for each of us?
 
The different market holiday dates could be the reason, good pick up. I have no need to find the answer but it was eating away at me as it seems like such an easy question. So one more attempt below, seems to work perfectly for North American trading dates as it was matched against the SP500 via Norgate data symbol $SPX. Good luck with Aussie market dates!

//////////////////////////////////////////////////////////////
// Attempting to identify the last trading day of first three weeks of each month

dow = DayOfWeek();
Eow = dow > Ref( dow, 1 ); // last trading Day of week
CurrentMonth = Month();

End1stWeek = Eow AND( ValueWhen( Eow, Month(), 2 ) != CurrentMonth );
End2ndWeek = Eow AND( ValueWhen( Eow, Month(), 2 ) == CurrentMonth ) AND( ValueWhen( Eow, Month(), 3 ) != CurrentMonth ) ;
End3rdWeek = Eow AND( ValueWhen( Eow, Month(), 2 ) == CurrentMonth ) AND( ValueWhen( Eow, Month(), 3 ) == CurrentMonth ) And( ValueWhen( Eow, Month(), 4 ) != CurrentMonth ) ;

Filter = 1;
AddColumn( Close, "Close" );
AddColumn( Eow, "Eow", 1.0, colorBlack, IIf( Eow, colorYellow, colorDefault ) );
AddColumn( IIf( dow == 1, 'M', IIf( dow == 2, 'T', iif( dow == 3, 'W', IIf( dow == 4, 'R', 'F' ) ) ) ), "Day", formatChar );
AddColumn( DayOfWeek(), "D.O.W.", 1.0 );
AddColumn( End1stWeek, "End1stWeek", 1.0, IIf( End1stWeek, colorWhite, colorDefault ), IIf( End1stWeek, colorDarkBlue, colorDefault ) );
AddColumn( End2ndWeek, "End2ndWeek", 1.0, IIf( End2ndWeek, colorWhite, colorDefault ), IIf( End2ndWeek, colorDarkRed, colorDefault ) );
AddColumn( End3rdWeek, "End3rdWeek", 1.0, IIf( End3rdWeek, colorWhite, colorDefault ), IIf( End3rdWeek, colorDarkYellow, colorDefault ) );


Plot( End3rdWeek, "End3rdWeek", colorBlue, styleHistogram | styleThick | styleOwnScale );

upload_2017-3-2_17-57-22.png
 
Your latest code looks good to me. However it it a week late in some cases on the ASX and this is due to Australian holidays in January (Australia Day) and April (Easter).

Thanks alot for your effort and replies. I feel your code is more elegant than mine and I will look further into making your format work for me.

For the record, I use Norgate PremiumData too and I am checking against XAO.
 
Hello all,

Am new to the site and enjoying what it has to offer
New To Amibroker and working on coding my first system

Trying the following and I am getting stuck, any help would be appreciated

Trying to code the following Buy Signal on a weekly system but getting stuck

When 3 day RSI is below 50, select 10 stocks with the highest ROC %

Some help would be appreciated

Thanks Community
 
Code:
Buy = RSI(3) < 50;

PositionScore = ROC(20); // 20 week ROC
SetOption("MaxOpenPositions", 10);
 
Hello
Still working on coding my first system. Results are starting to look promising although more checks needed

Annual Return on backtesting 15% with a 14% drawdown

Looking at excluding top 99 stocks (large Cap) by Market Cap

Some help how I would do that as running into a brick wall

Thanks all
 
Hello
Still working on coding my first system. Results are starting to look promising although more checks needed

Annual Return on backtesting 15% with a 14% drawdown

Looking at excluding top 99 stocks (large Cap) by Market Cap

Some help how I would do that as running into a brick wall

Thanks all

Are you running Premium Data ?
One of their advantages is the number of lists they produce.

I find that the All Ords (around 500 stocks) is a good list to work with, gets rid of the chaff but still gives you a broad selection of prices and sectors.
.
Allords.jpg
 
Are you running Premium Data ?
One of their advantages is the number of lists they produce.

I find that the All Ords (around 500 stocks) is a good list to work with, gets rid of the chaff but still gives you a broad selection of prices and sectors.
.
View attachment 70825
Thanks Boggo will work which list is best to work with
Trying to exclude the big boys of town
Working on the med to small- within the Asx 300
 
Premium Data has a S&P ASX Small Ordinaries watch list which might give you what you want.
 
Quick question. Why do you want to exclude the top 100? Is it due to lack of profit potential/volatility or something?

If this is the case I see it as an overly simplistic approach. Try leaving the top 100 in and using an appropriate filter instead of cutting out a big block of potential trade candidates. However I do agree that in general sticking to the ASX500 is sound. A significant number outside of the ASX500 is untradable with any sort of decent size. With that said, a thought that I had recently was that if I could filter for market cap. inside AmiBroker using code I would look closely at adopting that approach and dumping S&P lists all together.

I will mention that I run multiple systems that trade short term and they all select trades from S&P lists. I found that in general the majority (but certainly not all) of ASX100 candidates exhibit very different characteristics to those outside that universe when tested using my systems. I put this down to volatility and the market participants that trade in this end of the pool. However my systems that trade the ASX300 or ASX500 never exclude the ASX100 or ASX200 for example. There are some great trades to be had there with good volatility and profit potential.

So what I am trying to highlight is that in my experience filtering from the top down (eg ASX200, ASX500) works well, but filtering from the bottom up (eg ASX300 excluding ASX100) isn't the best thing to do. All it does is limit you opportunity.

Something to try out.
 
Last edited:
Quick question. Why do you want to exclude the top 100? Is it due to lack of profit potential/volatility or something?

If this is the case I see it as an overly simplistic approach. Try leaving the top 100 in and using an appropriate filter instead of cutting out a big block of potential trade candidates. However I do agree that in general sticking to the ASX500 is sound. A significant number outside of the ASX500 is untradable with any sort of decent size. With that said, a thought that I had recently was that if I could filter for market cap. inside AmiBroker using code I would look closely at adopting that approach and dumping S&P lists all together.

I will mention that I run multiple systems that trade short term and they all select trades from S&P lists. I found that in general the majority (but certainly not all) of ASX100 candidates exhibit very different characteristics to those outside that universe when tested using my systems. I put this down to volatility and the market participants that trade in this end of the pool. However my systems that trade the ASX300 or ASX500 never exclude the ASX100 or ASX200 for example. There are some great trades to be had there with good volatility and profit potential.

So what I am trying to highlight is that in my experience filtering from the top down (eg ASX200, ASX500) works well, but filtering from the bottom up (eg ASX300 excluding ASX100) isn't the best thing to do. All it does is limit you opportunity.

Something to try out.

Thanks RB
Thought it would be worth testing (just an idea I had), excluding the ASX100 would the volatility help or hinder.
But definitely will take your thoughts on-board and test both ways
 
Top