Australian (ASX) Stock Market Forum

Dump it Here

Many thanks Skate, you have been most generous with your time and expertise. So far, I have come up with the following draft code:
//Index Filter for XAO with a 200Day MA on a Daily Chart
Index = Foreign("XAO", "C", True);

IndexMA = MA(Index, 200);

Buy = C >= MA(C, 200) AND Index >= IndexMA;
Sell = C <= MA(C, 200);

//* Note I assume I need to add more code here to get some columns for a print out of where the XAO is crossing the 200Day MA. // Is that right? Am I on the right track?

I appreciate the additional comments you have provided me. It is good to know that Joe Marwood is a local. I will endeavor to look closer at his resources.

Aristotle
 
Remember to run that code with settings set to Daily. I'm also not sure what your system will do since you have buy and sell criteria with greater/less than or equal to. Perhaps just include ">" or "<".

My own way of doing it is similar to yours. Instead, with the index I add:

IndexUP = Index > IndexMA;

Then in the buy conditions write:

Buy = C >= MA(C, 200) AND IndexUP;

If you put in the variable, it will only excute if that variable is true (this is a shorthand of it). you could do,

Buy = C >= MA(C, 200) AND Index == TRUE;

The '==' is a true or false statement, which also means you could put it into your sell statement:

Sell = IndexUP == FALSE;

That would sell as soon as the index starts closing below its 200day MA. I personally use the IndexUP filter to determine my trailing stop, and whether I buy (that is, I don't use it to determine if I sell).

A better buying condition is actually more along the lines of:

Sell = C <= MA(C, 20);

As for columns, use the code: AddColumn, AddColumnText. There are plenty of examples and the AB guide is great for this too.
 
Many thanks Skate, you have been most generous with your time and expertise. So far, I have come up with the following draft code:
//Index Filter for XAO with a 200Day MA on a Daily Chart
Index = Foreign("XAO", "C", True);
IndexMA = MA(Index, 200);
Buy = C >= MA(C, 200) AND Index >= IndexMA;
Sell = C <= MA(C, 200);
//* Note I assume I need to add more code here to get some columns for a print out of where the XAO is crossing the 200Day MA. // Is that right? Am I on the right track? I appreciate the additional comments you have provided me. It is good to know that Joe Marwood is a local. I will endeavor to look closer at his resources.

Amibroker is a blank sheet of paper, where you get to write the story!

176,000 words in the dictionary (I don't think we need them all)
People have tendency to think in terms "more is better" but the truth is in programming less is more & to me less is better. I’m not a believer of adding complexity when it's not needed

Trading is not exact science
For all the advancements in technology the market itself hasn’t changed much. It is still driven by the same two opposing forces, fear & greed. Profiting from the stock market is exceedingly difficult to do consistently over a long period of time because the markets are so irrational & emotional, the market is not logical or reasonable & the last few weeks are evident to that. A market is nothing more than a crowd of people that has absolutely no regard for what any one person may think & most times rational people make irrational decisions thus the massive swings & the recent panic selling, go figure.

AmiBoker's members area
Having a mechanical trading system takes all the emotions out of trading. Learning Amibroker is going to be difficult at first to understand the programming but AmiBroker has a forum full of members willing to help. There is also a members area full of ready made code to play with & I've listed a few to download to get a feel. https://forum.amibroker.com/new

Graham Kavanagh guide for learners
http://www.amibroker.com/members/library/formula.php?id=547
This system is written by Graham Kavanagh - it's a guide for learners on the common components of writing AFL. There are many questions from beginners when they start using AmiBroker so Graham Kavanagh created a sample system that incorporates basic and useful items. The AFL can be used to better understand Chart, Scan, Backtest & Explore features. The system for Buy/Sell is an "example only" that backtests poorly.

Brian Fenske enhancements to Graham Kavanagh learners guide
http://www.amibroker.com/members/library/detail.php?id=547
This system written by Brian Fenske where he remarks that Graham Kavanagh did a nice job of capturing much of the essence of a basic script. But with Brian working with a group of programmers have come up with some enhancements to his formula that makes it useful in the Automatic Analysis (AA) component.

Enjoy playing & learning AmiBroker..

Skate.
 
Last edited:
Buy = C >= MA(C, 200) AND Index >= IndexMA;
Sell = C <= MA(C, 200);

As Warr87 suggested, with the above code, in the rare event that the Close is exactly the same as the 200 MA you'll get both a buy and sell signal at the same time. Better to remove the = from it, or only include = in one of the two.

A better buying condition is actually more along the lines of:

Sell = C <= MA(C, 20);

This is a good example of something that might not be obvious to Aristotle. (In fact I have code purchased long ago from a well-respected professional with a similar issue.) Let's say you used this sell signal with no other modifications:
Buy = C >= MA(C, 200) AND Index >= IndexMA;
Sell = C <= MA(C, 20);

This is what you get below. Orange line is the 200 MA, Green is the 20 MA. Price first crosses the 200 MA, you buy the next day (little green arrow), great. But look at what happens when price closes below the 20 MA. Every bar below the 20 MA is generating Buy and Sell signals at the same time. It's important to review your backtest trades to ensure the system is working as intended. Plot any indicators you use on the chart like in the image below so you can easily see where it should have taken a trade and whether it did.

upload_2020-5-4_19-46-28.png
 
View attachment 103178

Disclaimer
The next graphic displays the hypothetical signals for Monday as the "Index Filter" is still turned off. There is "no way in hell" I would trade a strategy without protection - that would be foolish.

Sample of what to expect
So the system generates a sample of signals I'll use the hypothetical "Action Strategy" remembering that the "Index Filter is still turned off". With the Index turned off the strategy will generate buy signals when the entry conditions are met. Sell signals are not dependant on the Index Filter, meaning a sell signal is generated when the exit conditions are met.

View attachment 103179

There are 4 sell signals
There are 4 exit signals listed but as the "Action Strategy" only holds 2 of them (GOR & AGG) those two would be sold at open on Monday. Both (GOR & AGG) at this stage will be exited as winners.

For transparency
All the signals for the "Action Strategy" will be posted well in advance for transparency.

More to follow..

Skate.

Hi @Skate , JMS have dividend this week
Ex Date: Wednesday May 6, 2020
Record Date: Thursday May 7, 2020

As observation in overseas trading, the price surge higher during and uptill the record date then price drop after that. Just to educate myself does the dividend alters your decision to when to buy/sell/hold? Like for this case JMS, does the above dates changes your position?
Thanks
 
The majority of us system traders don't buy based on dividend. You buy/sell when the signal is given. Any dividends are considering a cherry on top of hopefully a winning trade.
 
The majority of us system traders don't buy based on dividend. You buy/sell when the signal is given. Any dividends are considering a cherry on top of hopefully a winning trade.

@Warr87 If a share bought based on system buy signal given and dividend came in line, Does the sell off that happen (if it happens) after dividend based on experience trigger a sell signal? (Caused by Dividend)
The reason I ask, I have encountered this multiple time overseas and not sure about ASX
 
Hi @Skate , JMS have dividend this week - the price surge higher during and uptill the record date then price drop after that. Just to educate myself does the dividend alters your decision to when to buy/sell/hold? Like for this case JMS, does the above dates changes your position?

@Bazzi that's a good question. Like most traders I have a dividend stripper strategy that operates on the principles you have described.

Let's not over think it
"The Action Strategy" buys into trends - the cause of the trend is of no concern. @Warr87 is correct, "dividends" are not part of the equation.

What overrides a buy signal
There is only one thing that will override a buy signal & that's an announcement of a takeover/scheme of arrangement (A scheme of arrangement is a court-approved agreement between a company & its shareholders)

So there is no confusions
Update: Instead of showing generated buy signals as planned I'll show orders placed in the pre-auction so others can follow along without confusion.
Does the sell off trigger a sell signal (after dividend)?

Dividend distribution
The drop in share price after a distribution of a dividend has no bearing or relationship to the exit strategy being used.

Skate.
 
@Warr87 If a share bought based on system buy signal given and dividend came in line, Does the sell off that happen (if it happens) after dividend based on experience trigger a sell signal? (Caused by Dividend)
The reason I ask, I have encountered this multiple time overseas and not sure about ASX

It could, but I doubt a dividend selloff would cause your stock to lower by that much. My own systems have 30 or 40% trailing stop and I haven't noticed any dropping that far after dividend.

And to clarify, as @Skate has mentioned, there are some strategies that will target dividends.
 
@Skate thank for your eBook, it is very interesting read

@Ante you are most welcome, I'm glad you are finding the eBook an interesting read. You need to read the eBook more than once to condition you "how to think", not "what to think". Having the correct head-space in this game is critical.

All the best..

Skate.
 
@Warr87 If a share bought based on system buy signal given and dividend came in line, Does the sell off that happen (if it happens) after dividend based on experience trigger a sell signal? (Caused by Dividend)
The reason I ask, I have encountered this multiple time overseas and not sure about ASX

I also like dividend paying stocks and in good times have specifically given higher priority to dividend stocks being included in my portfolio. In these leaner times when companies are more likely to cut the dividend than to increase it, it really is a "cherry on top" as Warr87 said.

I think Peter2 used to adjust his systems to allow his stops to be lowered during the share price drop that happens on the ex-dividend date.
 
I think Peter2 used to adjust his systems to allow his stops to be lowered during the share price drop that happens on the ex-dividend date.

Yes, indeed I do because most of my trades are short term and my trailing stop gets tighter as the profits rise. In my medium term trades the exit stops are usually well away from any div drop.

Note: A shorter term trader must be careful to know when the XD dates. Brokers can purge orders on the XD date before the open. If you've placed a limit order in the market to sell or buy it may be wiped.
 
Thanks again Skate.
My discussion with you and other members of ASF on my particular issue ie. Developing an "Index Filter" for my trading strategy in Amibroker has been very fruitful. I can now see what I need to do in the short term. Firstly, I need to up date my Trading Plan with the following statement:

Have a look at my trading charts each day (or at least weekly) and once the value of the index falls below the 200 Day MA it's no longer good to open positions and time to close ones that are open”

This I can do manually or visually. But in time I will further develop the Amibroker version after I have had a good look at the reference above cited by Skate.

Aristotle
Amibroker is a blank sheet of paper, where you get to write the story! etc"
 
As Warr87 suggested, with the above code, in the rare event that the Close is exactly the same as the 200 MA you'll get both a buy and sell signal at the same time. Better to remove the = from it, or only include = in one of the two.



This is a good example of something that might not be obvious to Aristotle. (In fact I have code purchased long ago from a well-respected professional with a similar issue.) Let's say you used this sell signal with no other modifications:
Buy = C >= MA(C, 200) AND Index >= IndexMA;
Sell = C <= MA(C, 20);

This is what you get below. Orange line is the 200 MA, Green is the 20 MA. Price first crosses the 200 MA, you buy the next day (little green arrow), great. But look at what happens when price closes below the 20 MA. Every bar below the 20 MA is generating Buy and Sell signals at the same time. It's important to review your backtest trades to ensure the system is working as intended. Plot any indicators you use on the chart like in the image below so you can easily see where it should have taken a trade and whether it did.

View attachment 103204
Many thanks Lone Wolf
When I first started this journey to set up an "Index Filter" I was unsure as to how it would look like visually. You have given me a chart which clearly shows the "Buy and Sell" signals. Some times I can't see the wood for the trees in this trading game. But now I can see the end result vividly. I will further tinker with my formula, but in the short term I am going to update my Trading Plan as I communicated to Skate above.
Aristotle
 
time to close ones that are open”
Aristotle you could also look at tightening your trail stop instead of closing your positions. ie if you normally have a 30% trail stop then goto a 10% trail stop etc.

also you will find that it is common to have a ribbon on the bottom of the chart visually showing you index filter

Ribbon1=IIf( (indexWeeklyFilter) >= 1 , colorGreen,colorRed);
Plot(1, "Ribbon", Ribbon1, styleOwnScale| styleArea| styleNoLabel,-0.5,100);

upload_2020-5-6_9-16-47.png
 
1. Most Recent Action Strategy Logo.jpg
UPDATE.jpg

"The Action Strategy" index filter has turned "ON" & if it's still on at the end of trade Friday, the strategy will be trading live from then on. There will be nothing hidden with this trading strategy so following along will be easy as all signals will be posted before being placed in the pre-auction.

Why am I trading "The Action Weekly Strategy"
It's a small trading exercise so others can follow my progress & be involved "as much" or "as little" as they like. The strategy has been developed so there is little thinking required as it's just about taking the signals without hesitation as they come along, something most will find difficult to do. It shouldn’t matter how much money you have, how old you are or how much you know about trading, the very act of getting started is much more important than getting it right. No one likes to lose money, but it is an inescapable part of trading. Many people never start trading because they’re worried about losing some or all of their money so don’t let fear or self-doubt keep you from getting started. You can learn as you go by trading small positions & if you make a mistake small loses are bearable. Making small mistakes now will give you the skills & experience to be the best loser you can possible be. With that said, it's critical to make smart trading decisions.

So why is market acting the way it is?
Trying to guess what the market is doing or what’s causing the market to behave in such a way is sometimes futile & can drive you crazy just thinking about it. I could make up a story with the best of them but I've found fear is always the primary driving force but as with all human emotions, it can rise to extreme levels & then suddenly shift. Above all else, traders must accept the fact that we operate with incomplete & uncertain data & every trade has a probability of loss, a hurdle traders have to overcome. How you react to stress will decide whether you’ll be a success or a failure at trading. Even the best traders have plenty of lousy picks along the way.

When trading success depends on two basic things:
(1) Picking good stocks that have a chance of increasing in price, & (2) Effectively managing the stocks after you buy them & "I'm planning to do both".

Skate.
 
Aristotle you could also look at tightening your trail stop instead of closing your positions. ie if you normally have a 30% trail stop then goto a 10% trail stop etc.

also you will find that it is common to have a ribbon on the bottom of the chart visually showing you index filter

Ribbon1=IIf( (indexWeeklyFilter) >= 1 , colorGreen,colorRed);
Plot(1, "Ribbon", Ribbon1, styleOwnScale| styleArea| styleNoLabel,-0.5,100);

View attachment 103236

Thanks a million Trav, that is a brilliant suggestion. It is actually on my current Amibroker Price Chart. Now, I understand how I can best use it with the XAO Index. In the past I have used it for stocks only.
Aristotle
 
Top