Australian (ASX) Stock Market Forum

Dump it Here

Amibroker and Norgate data.jpg

Amibroker & Norgate Data
This is a match made in heaven. I'll be using Amibroker to code the "Weekend Trend Trader Strategy" & using Norgate as the data supplier. Amibroke & Norgate data are both programs that are needed to develop a trading strategy as one program without the other is less than useless. I have both WTT strategies coded & I will do the necessary background work to upload the strategy construction hopefully in one procedure.

Skate.
 
WTT 2 graph-line-trend-analytics-magnifying-glass-ss-1920.jpg

This sets the baseline for the WTT comparisons
I apologize for the sizing as it was difficult to get them to co-operate (sizing wise).

Backtest Results
Backtest period = 1st January 2020 to 30th June 2020
Portfolio size = $300k
Positions = 20


Combined Capture.jpg

To view the original backtests (original size)
CNHTractor - https://www.aussiestockforums.com/posts/1087655/ (to view the original size of the backtest results)
Saqeeb - https://www.aussiestockforums.com/posts/1087587/ (to view the original size of the backtest results)
Skate - my backtest is below as it might be easier to read

My Backtest Capture.JPG

The baseline has now been set
I'll will explain how I code a strategy from start to finish. I started to learn strategy construction by creating a storyboard & joining all the pieces together. It was easy for me to follow & I'm hoping it will be easy for you if you are just starting out. Seasoned coders are well past the beginners stage but never-the-less it might hold some interest.

Just to be clear
I don't trade a "WTT Strategy" & I don't trade basic (AFL) codes. In saying this - the end result should develop into a tradable code or a code you can play around with as I intend to upload both strategies when completed.

Skate.
 
Last edited:
WTT cover.png
This is the procedure I will follow to explain the "WTT Strategy" construction

The procedure is the same for any strategy construction & when finished you can use the strategy as a template to formulate other strategies you can dream up.

Strategy construction
* Amibroker formula language is simply lines of code & each line of code is closed when the instruction has been completed with a semicolon.
* A semicolon or semi-colon (";") ;) completes "finishes off" the line of code
* Once one line of code has been complete you start another
* Amibroker read from the top to the bottom & left to right just as we read a book (The order of instructions are important)
* It's similar to when you give verbal instruction, they follow one another after the other - with a breath in between
* To make the code human-readable we can make comments along the way.
* The code or line of instructions need to be clear & concise but when we make a comment for ourselves we uncommented that line out
* Uncommenting a line so it's not a readable line of code (instructions) we use two forward slashes (//) so the program is not confused
* Blank line are not actionable, we just use them to separate groups of instructions - Amibroker takes no notice of blank lines
* Amibroker is array driven program.
* What this means is that one word can represent one line of code or simply a command

Example of an array
[Drink] is an array so when I say [Drink] it really means ="would you be kind enough to go to the fridge & bring me a cold beer please & can you do it quickly"

So when I want a cold drink (beer)
Instead of saying "would you be kind enough to go to the fridge & bring me a cold beer please & can you do it quickly" I would just say "DRINK"

Remember "Father Ted" the TV show
Father Jack a foul-mouthed, rage-filled alcoholic - DRINK ! (Father Jack didn't have to say another word, they knew what he wanted them to do)
Father Ted 2 (TV) images.jpg

Skate.
 
Last edited:
Hi All,
Great to see folks posting simulation results of the systems they're trading or investigating. Sorry if this has been recently covered but thought this might be a good time to remind folks (particularly those new to system trading) of the importance of treating a single run simulation with some caution. Here is my point:- the first pic below shows a standard simulation output from Amibroker. Look at the Net Profit % figure, not too bad hey. Well this Net Profit % is not really reflective of the overall system behavior and it is a complete outlier. To get a better feel for the Net Profit % performance of this system I ran a simple Monte Carlo analysis (100 different runs) and you can see from the second pic that the majority of the Monte sims delivered much less than half of the Net Profit % that the single run did. So, if you really want to understand how your systems perform then make sure you do some rigorous Monte Carlo simulations. Personally, I use TradeSim but it is easy to do in Amibroker by adding the mtRandom() to your buy conditions and then doing an optimization on a dummy parameter to give you say 100, 500, 1000 or more runs. Your Amibroker optimization window can then be dumped into a CSV and cut and diced in excel using the Data Analysis plugin.
Cheers All, MA.

Backtest.PNG

monteresults.PNG
 
Last edited:
WTT cover.png

The procedure to code the WTT Strategy will be in 12 easy steps to follow
To keep the strategy construction simple I will outline the steps in order. In the next few posts, I'll upload screen captures so others are not tempted to do a "cut & paste". Don't worry I will upload the completed strategy after the construction has been completed.

The order of construction
1. First, we will set out our strategy "options" the "options" are management options & they are a part of Amibroker (features)
2. We will then add an "Index Filter" - this ultimately decides when we will trade & also our trailing stop levels
3. Next, we will add all our other filters
4. Then we will add our Buy condition
5. Add a sell conditions
6. Add a two-stage trailing stop
7. Add "Position Sizing"
8. Add "Filters for the Exploration Analysis"
9. Add Buy & Sell coding for use in trading the pre-auction
10. Add an Exploration code
11. Add columns to report & sort the Exploration Analysis results
12. Code chart signals & plots them with an Index Ribbon

After the construction phase is completed
I will upload a few backtests & then explain how we can squeeze a little more out of the strategy by adding or changing a few settings (parameters) & then compare the results.

I will start fresh tomorrow
Too much information in one go tends to be information overload but at least you have the mud map of what I'm planning to post tomorrow.

Skate.
 
I like the way you are heading Skate. :xyxthumbs You must have read my mind. :confused:
I am trying to get taxes sorted, and some other office work, and then I seem to be free for a while.
Hoping to be able to follow on in a few days, or on the weekend.
Cheers
 
Hi MA

Interested in your valuable post re monte carlo testing. In Amibroker monte carlo settings do you use 'Constant Value' (eg $5k on a $100k portfolio) OR 'Percent of Equity'?? They recommend NOT to use the latter. It makes a huge difference obviously
I dont have Tradesim ( or the time to learn it!) - Do you have any code or link to info re your comment :
"by adding the mtRandom() to your buy conditions and then doing an optimization on a dummy parameter to give you say 100, 500, 1000 or more runs."

Your comment - "standard simulation output from Amibroker Net Profit % is not really reflective of the overall system behavior and it is a complete outlier." is spot on - my system shows excellent returns in the standard simulation run but im not 100% sure of it and my knowledge of Amibroker monte carlo analysis is limited to reading the manual

any ideas appreciated

cheers
 
Hi all bit new to this, I recently purchased some shares and at 0.023 and it didn’t go through straight away . It’s now at 0.36 ive press amend . How long does it take to be executed . Thanks guys

if you had to 'amend' then you didn't purchase it. you may have got a few at that price but at best you got a 'partial fill'. you need to check out the order types with your broker. we can't help you with that.
 
Here's my 1/1/20 to 30/6/20 backtest Skate. Might be worth giving people PositionScore and Exit code to get better agreement. The exit condition is a bit tricky to write - I've got a suspicion my code let's the trailing stop out wide again if index filter goes "green" which isn't supposed to happen.

upload_2020-8-11_21-20-24.png


upload_2020-8-11_21-20-42.png
 
Here's my 1/1/20 to 30/6/20 backtest Skate. Might be worth giving people PositionScore and Exit code to get better agreement. The exit condition is a bit tricky to write - I've got a suspicion my code let's the trailing stop out wide again if index filter goes "green" which isn't supposed to happen.

View attachment 107350


View attachment 107351

@Newt, those returns are absolutely unbelievable. To get the Radge “WTT Strategy” to perform that well you must have had to massaged the parameters beyond recognition.

So I get this correct
The Backtest results that you posted are from a turnkey WTT Strategy OR is it a “WTT Strategy” that you coded?

Skate.
 
Hi All,
Great to see folks posting simulation results of the systems they're trading or investigating. Sorry if this has been recently covered but thought this might be a good time to remind folks (particularly those new to system trading) of the importance of treating a single run simulation with some caution. Here is my point:- the first pic below shows a standard simulation output from Amibroker. Look at the Net Profit % figure, not too bad hey. Well this Net Profit % is not really reflective of the overall system behavior and it is a complete outlier. To get a better feel for the Net Profit % performance of this system I ran a simple Monte Carlo analysis (100 different runs) and you can see from the second pic that the majority of the Monte sims delivered much less than half of the Net Profit % that the single run did. So, if you really want to understand how your systems perform then make sure you do some rigorous Monte Carlo simulations. Personally, I use TradeSim but it is easy to do in Amibroker by adding the mtRandom() to your buy conditions and then doing an optimization on a dummy parameter to give you say 100, 500, 1000 or more runs. Your Amibroker optimization window can then be dumped into a CSV and cut and diced in excel using the Data Analysis plugin.

Very much in agreement - the "Strawbroom" plots for Monte Carlo runs in AB are a particularly valuable too for considering the real range of simulated outcomes. More info, but of course can never be definitive going forward.

upload_2020-8-11_22-13-48.png
 
@Newt, those returns are absolutely unbelievable. To get the Radge “WTT Strategy” to perform that well you must have had to massaged the parameters beyond recognition.

So I get this correct
The Backtest results that you posted are from a turnkey WTT Strategy OR is it a “WTT Strategy” that you coded?

Skate.

That's my interpretation of WTT from the eBook, BUT with a price filter, turnover filter, PositionScore added (hadn't noticed I've never put one in there until people started talking about it today) - and as commented pretty sure the exit trailing stop isn't spot on.

Not sure about posting it publically as Radge property - don't mind messaging - its not that many lines of code. Suspect the turnkey would have trailing stop loops, parameters, graphics, Exploration etc.
 
Very much in agreement - the "Strawbroom" plots for Monte Carlo runs in AB are a particularly valuable too for consider the real range of simulated outcomes. More info, but of cause can never be definitive going forward.

i'll be honest, I have struggled to read the MC output properly. it's not entirely intuitive. i found some articles/blogs that went through how to read them to help out. AB's only info is alright but still not entirely clear. in some of my BT i force a certain amount of runs:

Code:
SetOption("MCEnable", 1 );
SetOption("MCRuns", 5000);

You can see here that there are very few chances of this system over this period of time staying above the 300000 mark. those above are the outliners. ideally you want it to skew the other way.

upload_2020-8-11_22-16-48.png



with the following graph, there is a 90% chance that the MC CAR will be -45% or higher (follow from the 10 percentile mark and their is a 90% chance that actual results will be anywhere to the right of that mark).

upload_2020-8-11_22-18-20.png
 
As opposed to the test over 2019 (1/1/19 to 30/12/19)

upload_2020-8-11_22-21-6.png


As you can see from the strawplot, even with the outliners they remain above 300000. this is promising over a min of 1000 iterations.
upload_2020-8-11_22-21-45.png

Here, there is a 90% chance that I will have a CAGR over 50% or greater for that year. That is obviously high (and I don't remember the backtest being so good for 2019).

upload_2020-8-11_22-24-12.png
 
Don't be fooled by the results, btw. Add in other years and the results are much more modest. 2019 just happens to be a good year for it. My strategy does good even in slightly sideways to upwards markets. (Acts more like a momentum strategy in those environment and not a trend system from what I've noticed.)
 
View attachment 107347

The procedure to code the WTT Strategy will be in 12 easy steps to follow
To keep the strategy construction simple I will outline the steps in order. In the next few posts, I'll upload screen captures so others are not tempted to do a "cut & paste". Don't worry I will upload the completed strategy after the construction has been completed.

The order of construction
1. First, we will set out our strategy "options" the "options" are management options & they are a part of Amibroker (features)
2. We will then add an "Index Filter" - this ultimately decides when we will trade & also our trailing stop levels
3. Next, we will add all our other filters
4. Then we will add our Buy condition
5. Add a sell conditions
6. Add a two-stage trailing stop
7. Add "Position Sizing"
8. Add "Filters for the Exploration Analysis"
9. Add Buy & Sell coding for use in trading the pre-auction
10. Add an Exploration code
11. Add columns to report & sort the Exploration Analysis results
12. Code chart signals & plots them with an Index Ribbon

After the construction phase is completed
I will upload a few backtests & then explain how we can squeeze a little more out of the strategy by adding or changing a few settings (parameters) & then compare the results.

I will start fresh tomorrow
Too much information in one go tends to be information overload but at least you have the mud map of what I'm planning to post tomorrow.

Skate.
The 12 steps provide a great framework for coding any system, wish I had this a few months ago, it would have set me on a much better path.
 
You're trying to convince me to buy Amibroker and code my discretionary trading plans into systems so that I can make so much more.

Arrgh, it might actually be a good idea, but can this old dog who used to write Fortran and Pascal programmes learn to code Amibroker at the advanced level in a short time?

It may be easier for me to modify entries and exits in already coded systems. I'll mull it over.
 
You're trying to convince me to buy Amibroker and code my discretionary trading plans into systems so that I can make so much more.

Arrgh, it might actually be a good idea, but can this old dog who used to write Fortran and Pascal programmes learn to code Amibroker at the advanced level in a short time?

It may be easier for me to modify entries and exits in already coded systems. I'll mull it over.


Which after reading through all of the above, is pretty much how I am feeling. The initial investment of time now, to save so much time later. What is the discount rate on that?

jog on
duc
 
Hi MA

Interested in your valuable post re monte carlo testing. In Amibroker monte carlo settings do you use 'Constant Value' (eg $5k on a $100k portfolio) OR 'Percent of Equity'?? They recommend NOT to use the latter. It makes a huge difference obviously
I dont have Tradesim ( or the time to learn it!) - Do you have any code or link to info re your comment :
"by adding the mtRandom() to your buy conditions and then doing an optimization on a dummy parameter to give you say 100, 500, 1000 or more runs."

Your comment - "standard simulation output from Amibroker Net Profit % is not really reflective of the overall system behavior and it is a complete outlier." is spot on - my system shows excellent returns in the standard simulation run but im not 100% sure of it and my knowledge of Amibroker monte carlo analysis is limited to reading the manual

any ideas appreciated

cheers

Hi @martyjames,

You raise a very good point regarding position sizing. Whenever I look at testing the performance and behavior of a system I always look at it with fixed dollar position sizes, typically I would use 20 position each being $5k. This IMHO is very important if you are testing a system over a very long time frame--5, 10, 20 or more years. Doing this gives me a better understanding of the system behavior per se without the "external" influence of a variable position size. As you probably know position sizing can have a major influence on a system's top line performance ($$$ made). I like to know how a system performs without external influences such as position sizing. Position sizing methodologies are most definitely important but in my mind position sizing is not a integral part of the system (how you buy and how you sell) and is external to the system so I think doing system evaluation should include fixed dollar position analysis. In reality I live trade using percent of total equity so I will also run sims using that position sizing approach as well, but my core testing is focused on fixed dollar positions.

In relation to Amibroker and monte carlo test. Amibroker does have a very rudimentary inbuilt capability to do monte carlo analysis, but I am not a fan of its inbuilt monte carlo capability for several reason (this alone could make a separate thread so I'll keep it simple for now). As you can see in some of the Amibroker backtest report pics in this thread, clicking on the "Monte Carlo" tab in the backtest report will show some Monte Carlo charts. While these Monte Carlo charts are better than nothing, for me they are very limited as there are many key characteristics of a system that I'd like to examine for which Amibroker doesn't do a Monte Carlo analysis. On a more technical issue I also have a problem with the way Amibroker internally "shuffles" trades to do the Monte Analysis which is one of the main reasons I use TradeSim. Anyway, it is easy enough to get Amibroker to do more comprehensive Monte Carlo analysis by adding the following few simple lines of code to your system:

MonteCarloParam = optimize("Monte", 1, 1, 1000, 1);

Buy = YourSystemBuyConditionsHere AND mtRandom() < 0.7;

With the above AFL code added click on the optimize button in your analysis window and it will do 1000 runs. The key here is that there is now a random element to determining whether your system takes each trade. There is about a 70% of the trade being taken. You can change the "0.7" value to suit but be aware that if you make it too low you won't take enough trades. For a system taking about 1000 trades I found 0.7 to be about right--all runs take about 1000 trades. Below is an example of the analysis window from Ami as an example Monte done as explained above--I've only run 10 sims for simplicity. The variation in the system characteristics for each run is purely down to the random determination of taking each trade. The MonteCarloParam variable is not a system parameter it is just a dummy parameter. You can export the analysis results to a CSV and then import into excel where you can do a much more comprehensive Monte analysis of all of the simulation results and all parameters output by Ami.

monteexample.PNG
 
Last edited:
Top