Australian (ASX) Stock Market Forum

Amibroker FAQ

Hi captain black

I'm not sure I understand your reply, a Buy signal is generated in my strategy when the close is greater than the Upper Donchian Channel Buy= C > DonchianUpper

You can't know the close price until after the close that day, therefore you wont know the buy signal until after the close. Therefore you can't place the trade until the following day.
 
Hi captain black

Are you saying I don't need Howard Bandy's code in my strategy as Backtesting will make that correction for me?

skate
 
Hi captain black

Are you saying I don't need Howard Bandy's code in my strategy as Backtesting will make that correction for me?

skate

Not at all. You need to put the delay code into your formula because you need to delay your trade by one day. You can't know which stocks have met your buy criteria until AFTER today's close.
 
To put it another way, you're going to put buy orders in today based on what stocks have closed above the donchian channel today. Can you tell me now what stocks are going to close above the donchian channel? No, you wont know that until after the close.
 
captain black is correct, it's looking at future data.
But one possibility is to use a limit order set above the Donchian Channel top. Although there is still no guarantee that the actual close will also be above it, at least it allows you to place the trade and test your system. In addition you will be able to compare the results, e.g. how many trades are different and by how much.

Your other question is very interesting. It would appear that you have discovered an extraordinarily effective entry signal. You might as well forget about he rest of your system, enter your trade just before the close and sell at next day's open. That's $ 41,000 per year right there.

Before you implement it, you should make absolutely sure that this is what you've got (an extraordinarily effective entry signal, that is). If it's based on a Donchian channel breakout or another popular indicator, or something that you have read in a book or a blog - I'll let you fill in the rest ...

On a more serious note, it's usually best to use explicit trade delay code, rather than just commenting out, i.e.

SetTradeDelays(1,1,1,1);

or

SetTradeDelays(0,0,0,0);

Try to get to the bottom of this discrepancy in your test results. Save the two versions of code if it's not already too late and find out exactly what you did wrong. You will learn a lot this way. Comparing a few individual trades might give you the solution.
 
To put it another way, you're going to put buy orders in today based on what stocks have closed above the donchian channel today. Can you tell me now what stocks are going to close above the donchian channel? No, you wont know that until after the close.

OK, I accept that - but can you explain why the backtest are so different in Scenario (1) compared to Scenario (2)?

Backtest:

Scenario (1) - Buys on the day it gets the signal - GOOD result - Net Profit
Scenario (2) - Buys on the NEXT day it gets its signal - POOR result - Net LOSS

skate
 
captain black is correct, it's looking at future data.
But one possibility is to use a limit order set above the Donchian Channel top. Although there is still no guarantee that the actual close will also be above it, at least it allows you to place the trade and test your system. In addition you will be able to compare the results, e.g. how many trades are different and by how much.

Your other question is very interesting. It would appear that you have discovered an extraordinarily effective entry signal. You might as well forget about he rest of your system, enter your trade just before the close and sell at next day's open. That's $ 41,000 per year right there.

Before you implement it, you should make absolutely sure that this is what you've got (an extraordinarily effective entry signal, that is). If it's based on a Donchian channel breakout or another popular indicator, or something that you have read in a book or a blog - I'll let you fill in the rest ...

On a more serious note, it's usually best to use explicit trade delay code, rather than just commenting out, i.e.

SetTradeDelays(1,1,1,1);

or

SetTradeDelays(0,0,0,0);

Try to get to the bottom of this discrepancy in your test results. Save the two versions of code if it's not already too late and find out exactly what you did wrong. You will learn a lot this way. Comparing a few individual trades might give you the solution.

Hi Habakkuk

I replied to captain black before I read your post.

MY ENTRY formula in full scanning the ASX Small Cap Industrials:
Buy= C > DonchianUpper AND IndexBuyfilter AND NOT OnLastTwoBarsOfInactiveSecurity AND C >=1 AND C <= 10 AND MA(V, 7)>= 500000 AND PositionScore * 100 > 5 ;

Is there a clue in the BUY formula, I'll do as you suggested and check each entry and exits in Scenario (1) comparing it with scenario (2)

skate
 
OK, I accept that - but can you explain why the backtest are so different in Scenario (1) compared to Scenario (2)?

Backtest:

Scenario (1) - Buys on the day it gets the signal - GOOD result - Net Profit
Scenario (2) - Buys on the NEXT day it gets its signal - POOR result - Net LOSS

skate

Because in scenario 1 you're looking into the future!!
 
OK, I accept that - but can you explain why the backtest are so different in Scenario (1) compared to Scenario (2)?

Backtest:

Scenario (1) - Buys on the day it gets the signal - GOOD result - Net Profit
Scenario (2) - Buys on the NEXT day it gets its signal - POOR result - Net LOSS

skate

Is your BuyPrice set to Open in both scenarios?

Assuming it is, Scenario 1 is buying on the Open TODAY, but the buy signal won't be generated until the Close today. So the code is looking in to the future. Scenario 1 is buying BEFORE the buy signal is generated.
 
Hi Skate,

I'm not much of a programmer, so I can't see any obvious logic error apart from using "close". I would suggest that you got such different results because of your stock universe and the fact that you did this comparison with a single run for each scenario.
Path dependence would be a significant factor. It's only a guess, but if you compare the trades, there will be different stocks picked at least some of the time to make up the difference in performance. It is unlikely to be just the price difference between today's close and tomorrows open. In other words, scenario 1 is just a "lucky" sequence.

I always say that I'm not qualified to give advice and then I do so anyway. Here is my (unqualified) opinion:

while it is quite interesting and even exciting to play around with backtests, I would suggest most of it is a waste of time. Consider this, masses of people use Metastock, Amibroker, Ninjatrader, Metatrader, etc. The sort of system you are testing has probably been tried thousands of times just this week, and it's only Tuesday.
It would be discouraging to hear this. Luckily it's only my opinion, not proof of anything.

What you will need for a system is a concept that has an edge. Otherwise you rely on a bull market or luck.
It would be good to have an entry signal with an edge. Maybe you can also find an exit with an edge. If there are a lot of trading opportunities this way, then you are really getting somewhere.

Secondly, it should be a simple concept. I'm not a believer in a lot of AND and AND NOT in my Buy or Sell statements, but that's just me. I avoid using parameters as much as possible and always examine how the range affects the various results like CAR, DD, exposure, #Trades, Winrate %, ProfitFactor, Sharpe, etc.
Just picking a "sweet spot" in a parameter is a big no-no. Of course there will be a different result for every parameter value, but there should be a range of profitable values.

Most indicators provide no edge. Don't trust me on this because technical analysts will disagree with me. Find out for yourself. An edge should be quantifiable. See if you can measure the edge of your Donchian Channel breakout.

Lastly, as you probably know, Howard Bandy has some good advice on in-sample and out-of-sample backtesting, some on posts here on ASF. It's hard to fault the logic. But there is an interesting consequence to consider. Unfortunately this post is getting too long to explain it. It would be almost good enough for its own thread.

The above is still only my opinion.
 
OK, I accept that - but can you explain why the backtest are so different in Scenario (1) compared to Scenario (2)?

Backtest:

Scenario (1) - Buys on the day it gets the signal - GOOD result - Net Profit
Scenario (2) - Buys on the NEXT day it gets its signal - POOR result - Net LOSS

skate
Same as Captain Black repeated

Scenario 1 you bought before the daily close is greater than the Richard Donchian Channel
You bought the open price for the same day before the close price revealed the close above DC

Scenario 2 you bought after the daily close is greater than the Richard Donchian Channel
You bought the open price for the next day after the close price revealed the close above DC

p.s. for EOD backtesting purposes --- before you type you bought the same day close price well impossible because the market has closed :D
 
Hi Skate,

I'm not much of a programmer, so I can't see any obvious logic error apart from using "close". I would suggest that you got such different results because of your stock universe and the fact that you did this comparison with a single run for each scenario.Path dependence would be a significant factor. It's only a guess, but if you compare the trades, there will be different stocks picked at least some of the time to make up the difference in performance. It is unlikely to be just the price difference between today's close and tomorrows open. In other words, scenario 1 is just a "lucky" sequence.

I always say that I'm not qualified to give advice and then I do so anyway. Here is my (unqualified) opinion:

while it is quite interesting and even exciting to play around with backtests, I would suggest most of it is a waste of time. Consider this, masses of people use Metastock, Amibroker, Ninjatrader, Metatrader, etc. The sort of system you are testing has probably been tried thousands of times just this week, and it's only Tuesday. It would be discouraging to hear this. Luckily it's only my opinion, not proof of anything.

What you will need for a system is a concept that has an edge. Otherwise you rely on a bull market or luck.
It would be good to have an entry signal with an edge. Maybe you can also find an exit with an edge. If there are a lot of trading opportunities this way, then you are really getting somewhere.

Secondly, it should be a simple concept. I'm not a believer in a lot of AND and AND NOT in my Buy or Sell statements, but that's just me. I avoid using parameters as much as possible and always examine how the range affects the various results like CAR, DD, exposure, #Trades, Winrate %, ProfitFactor, Sharpe, etc. Just picking a "sweet spot" in a parameter is a big no-no. Of course there will be a different result for every parameter value, but there should be a range of profitable values.

Most indicators provide no edge. Don't trust me on this because technical analysts will disagree with me. Find out for yourself. An edge should be quantifiable. See if you can measure the edge of your Donchian Channel breakout.

Lastly, as you probably know, Howard Bandy has some good advice on in-sample and out-of-sample backtesting, some on posts here on ASF. It's hard to fault the logic. But there is an interesting consequence to consider. Unfortunately this post is getting too long to explain it. It would be almost good enough for its own thread.

The above is still only my opinion.

Hi Habakkuk

MY REPLY in bold

Hi Skate,

I'm not much of a programmer, so I can't see any obvious logic error apart from using "close". I would suggest that you got such different results because of your stock universe and the fact that you did this comparison with a single run for each scenario.

ANSWER - "Yes TRUE I did the same run over many time frames and got very similar results Sceniro (1) good results and Scenario (2) NOT so good

Path dependence would be a significant factor. It's only a guess, but if you compare the trades, there will be different stocks picked at least some of the time to make up the difference in performance. It is unlikely to be just the price difference between today's close and tomorrows open. In other words, scenario 1 is just a "lucky" sequence.

ANSWER - After your first reply to my problem I exported the Backtest scan results into an EXCEL spreadsheet put them side-to-side and YES you are correct there was Lots and Lots of different securities picked, the two list were nearly completely different, there were some similar but lots were different with different Buy dates. Without your suggestion to check the two scans I would have never have found out that the two scans had different securities purchased. I assumed without checking the only difference between the two list would be the Buy and Sell Dates.

I always say that I'm not qualified to give advice and then I do so anyway. Here is my (unqualified) opinion:

ANSWER - Your opinion is valued by me..

while it is quite interesting and even exciting to play around with backtests, I would suggest most of it is a waste of time. Consider this, masses of people use Metastock, Amibroker, Ninjatrader, Metatrader, etc. The sort of system you are testing has probably been tried thousands of times just this week, and it's only Tuesday. It would be discouraging to hear this. Luckily it's only my opinion, not proof of anything.

ANSWER - I've just started using Amibroker after using Metastock for a few years and getting my Metastock mind around Amibroker Formula Language is a challenge at the moment.

What you will need for a system is a concept that has an edge. Otherwise you rely on a bull market or luck.It would be good to have an entry signal with an edge. Maybe you can also find an exit with an edge. If there are a lot of trading opportunities this way, then you are really getting somewhere.

ANSWER - Tech/a's wonderful strategy Techtrader I believe has that edge, I've been playing with that program for a few years using the Metastock formula without being able to improve the results. When I started using Amibroker I revisited TechTrader and again played around with every adjustment that I could think of without any luck. The original code is beyond solid IMHO. I stumbled on a NEW Exit: Sell= C < MA(C,50); I believe this new EXIT improved the system but the trade off was to make the system more active thus increasing the Total Transaction costs. I now use this code as my Exit Strategy: Sell= C < MA(C,50) OR sell OR OnSecondLastBarOfInactiveSecurity OR IndexSellfilter ;

Secondly, it should be a simple concept. I'm not a believer in a lot of AND and AND NOT in my Buy or Sell statements, but that's just me. I avoid using parameters as much as possible and always examine how the range affects the various results like CAR, DD, exposure, #Trades, Winrate %, ProfitFactor, Sharpe, etc. Just picking a "sweet spot" in a parameter is a big no-no. Of course there will be a different result for every parameter value, but there should be a range of profitable values.

Most indicators provide no edge. Don't trust me on this because technical analysts will disagree with me. Find out for yourself. An edge should be quantifiable. See if you can measure the edge of your Donchian Channel breakout.

The Donchian Channel Breakout I thought was my edge. If a security had the strength to break the HIGH upper channel criteria it has a good probability to keep trending higher so my BUY code was my edge for my Trend Following System entry. The CODE I use: DonchianUpper =HHV(Ref(C,-1),100);

Lastly, as you probably know, Howard Bandy has some good advice on in-sample and out-of-sample backtesting, some on posts here on ASF. It's hard to fault the logic. But there is an interesting consequence to consider. Unfortunately this post is getting too long to explain it. It would be almost good enough for its own thread.

ANSWER - My reply is also lengthy and I know some get put off reading lengthy responses but It was hard for me to make my response any shorter

The above is still only my opinion. AND VALUED..

skate
 
Same as Captain Black repeated

Scenario 1 you bought before the daily close is greater than the Richard Donchian Channel
You bought the open price for the same day before the close price revealed the close above DC

Scenario 2 you bought after the daily close is greater than the Richard Donchian Channel
You bought the open price for the next day after the close price revealed the close above DC

p.s. for EOD backtesting purposes --- before you type you bought the same day close price well impossible because the market has closed :D

Hi Wysiwyg

Yes I accept captain black's explanation and I accept the reinforcements made by you.

Amibroker Backtest program makes the decision to BUY on the same day as it's generated and not myself (if no Trade Delay is used) Amibroker uses the open price of the day which is illogical, meaning if a BUY signal is generated TODAY using the results at the End of Trading NOBODY can wind back time BUT Amibroker CAN. Amibroker CAN and DOES have the ability to purchase the security at todays OPEN.

Amibroker having the ability to wind back time to BUY at today OPENING price in it's calculations defies logic.

Amibroker by default should have a End Of Day Radio Button in the Settings under the tab "TRADES" that can be selected. When running a Backtest Amibroker would use the next day as the LOGICAL next time the security can be physically purchased at the OPEN Weighted Average Price by default, so in reality that's how I thought the system would run.

If there is an EOD Radio Button to select I would appreciate someone letting me know.

skate
 
Hi Skate,

I'm not much of a programmer, so I can't see any obvious logic error apart from using "close". I would suggest that you got such different results because of your stock universe and the fact that you did this comparison with a single run for each scenario.
Path dependence would be a significant factor. It's only a guess, but if you compare the trades, there will be different stocks picked at least some of the time to make up the difference in performance. It is unlikely to be just the price difference between today's close and tomorrows open. In other words, scenario 1 is just a "lucky" sequence.

I always say that I'm not qualified to give advice and then I do so anyway. Here is my (unqualified) opinion:

while it is quite interesting and even exciting to play around with backtests, I would suggest most of it is a waste of time. Consider this, masses of people use Metastock, Amibroker, Ninjatrader, Metatrader, etc. The sort of system you are testing has probably been tried thousands of times just this week, and it's only Tuesday.
It would be discouraging to hear this. Luckily it's only my opinion, not proof of anything.

What you will need for a system is a concept that has an edge. Otherwise you rely on a bull market or luck.
It would be good to have an entry signal with an edge. Maybe you can also find an exit with an edge. If there are a lot of trading opportunities this way, then you are really getting somewhere.

Secondly, it should be a simple concept. I'm not a believer in a lot of AND and AND NOT in my Buy or Sell statements, but that's just me. I avoid using parameters as much as possible and always examine how the range affects the various results like CAR, DD, exposure, #Trades, Winrate %, ProfitFactor, Sharpe, etc.
Just picking a "sweet spot" in a parameter is a big no-no. Of course there will be a different result for every parameter value, but there should be a range of profitable values.

Most indicators provide no edge. Don't trust me on this because technical analysts will disagree with me. Find out for yourself. An edge should be quantifiable. See if you can measure the edge of your Donchian Channel breakout.

Lastly, as you probably know, Howard Bandy has some good advice on in-sample and out-of-sample backtesting, some on posts here on ASF. It's hard to fault the logic. But there is an interesting consequence to consider. Unfortunately this post is getting too long to explain it. It would be almost good enough for its own thread.

The above is still only my opinion.

Hi Habakkuk

I started PAPER trading my strategy on 23rd January 2015 and with $100,000 invested in 20 equal positions has a profit so far - $4,666

Scenario (1)
Backtesting my strategy using those exact figures above with Scenario (1) settings having the Trade Delay applied my Balance after the Backtest scan was reported as: Net Profit $1082

Scenario (2)
Backtesting my strategy using those exact figures above using Scenario (2) settings having NO Trade Delay applied my Balance after the Backtest scan was reported as: Net Profit $4031

The balance of Scenario (2) is closer than the results generated by Scenario (1) compared to the actual results of my paper trading.

Paper Trading.PNG

Sorry the image is so small (click on the image to expand it) , I attached the photo of the securities with the actual result after the close today

skate
 
I've just noticed your second post while I was about to reply to the first. I'm not sure what you mean exactly with paper trading. Don't you get your signals from an Amibroker scan or exploration? Why don't they match exactly? There is no slippage or spread in papertrading.
All I can suggest is that you should use a procedure that you can actually execute in real-life. If you are running the exploration after trading hours and place your trades the next day, there is no need for "scenarios". Maybe I haven't understood properly.

By the way, I also disagree with much of the reply you gave to Wysiwyg, but I'll leave it up to him to respond.

This is in response to your previous post

Thanks for your reply, Skate. I'm also an ex-Metastock user.
I hope I'm not upsetting you with my next comment.
You said:
Techtrader I believe has that edge
and
The Donchian Channel Breakout I thought was my edge

You "believe" and you "thought". How about measuring that edge instead?
It's only a suggestion, not particularly difficult to do unless you need to be really thorough like if it's for publication or peer-review.

You take that signal as a Buy order and then you measure the profit/loss 1, 2, 3, 4 ... 20 days after. 20 days is a month. If your signal needs more than 20 days to show a profit, ... anyway, it's up to you.

If you just want a quick indication, a few hundred trades should be enough. That's the quick-and-dirty method.

To do it scientifically, you would need to de-trend your data first and you would need a lot of it, 100,000 trades would be good. Then, having the results, you need to check them for statistical significance, that they are not just random, using t-score or similar.
I don't need that, because I "already know" from other people's research what works. But it's still nice to confirm stuff independently if possible.

I hope this helps and I would recommend trying it at least. You might get a big surprise.
Anyway, I hope I haven't offended you.
 
Amibroker by default should have a End Of Day Radio Button in the Settings under the tab "TRADES" that can be selected.

Hello skate

there are default Settings as in the screen shot attached. Set the defaults there and click OK and the defaults will always stay defaults until you change them again. With Amibroker it is the users knowledge of the software that people stumble on. The software will do what ever you have the skill and knowledge to create. :) Periodicity is in General section.

p.s. you have to delay entry/exit until next price is available because that is how real trading works

Untitled.png
 
Hello skate

there are default Settings as in the screen shot attached. Set the defaults there and click OK and the defaults will always stay defaults until you change them again. With Amibroker it is the users knowledge of the software that people stumble on. The software will do what ever you have the skill and knowledge to create. :) Periodicity is in General section.

p.s. you have to delay entry/exit until next price is available because that is how real trading works

View attachment 61747

Hi Wysiwyg

p.s. you have to delay entry/exit until next price is available because that is how real trading works

That's my point - if entry/exit can only be executed the next day what is the point of Amibroker having a NO TRADE DELAY feature - is it because not everyone is an EOD trader? (something I didn't consider)

skate
 
That's my point - if entry/exit can only be executed the next day what is the point of Amibroker having a NO TRADE DELAY feature - is it because not everyone is an EOD trader? (something I didn't consider)

skate

Because you can enter on current bar's open also.
But entering on current bars open while indicator value is calculated at current bar's close is a stupid idea.

YOU are the one being responsible for your code but not the software.
Garbage in -> garbage out.


And yes, there is not just EOD.
 
I've just noticed your second post while I was about to reply to the first. I'm not sure what you mean exactly with paper trading. Don't you get your signals from an Amibroker scan or exploration? Why don't they match exactly? There is no slippage or spread in papertrading.
All I can suggest is that you should use a procedure that you can actually execute in real-life. If you are running the exploration after trading hours and place your trades the next day, there is no need for "scenarios". Maybe I haven't understood properly.

By the way, I also disagree with much of the reply you gave to Wysiwyg, but I'll leave it up to him to respond.

This is in response to your previous post

Thanks for your reply, Skate. I'm also an ex-Metastock user.
I hope I'm not upsetting you with my next comment.
You said:

and


You "believe" and you "thought". How about measuring that edge instead?
It's only a suggestion, not particularly difficult to do unless you need to be really thorough like if it's for publication or peer-review.

You take that signal as a Buy order and then you measure the profit/loss 1, 2, 3, 4 ... 20 days after. 20 days is a month. If your signal needs more than 20 days to show a profit, ... anyway, it's up to you.

If you just want a quick indication, a few hundred trades should be enough. That's the quick-and-dirty method.

To do it scientifically, you would need to de-trend your data first and you would need a lot of it, 100,000 trades would be good. Then, having the results, you need to check them for statistical significance, that they are not just random, using t-score or similar.
I don't need that, because I "already know" from other people's research what works. But it's still nice to confirm stuff independently if possible.

I hope this helps and I would recommend trying it at least. You might get a big surprise.
Anyway, I hope I haven't offended you.

Hi Habakkuk

Lets clear up the last point first "I hope I haven't offended you" its not possible to offend me I'm too old for that.

When you don't know you just don't know.

Sometimes helpful answers are not all that clear when you don't have enough knowledge to comprehend the answer you have just been given.

Tonight's conversation confirms I just don't know enough to word the question correctly or succinctly. That should do me for now till I gain more knowledge.

Thanks to captain black,Wysiwyg and yourself for the time you have spent helping me understand Amibroker a little better.

skate
 
Top