Australian (ASX) Stock Market Forum

Amibroker FAQ

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.

Hi Trash

You amaze me with your knowledge and I did forget to thank you for the helpful advice you have given me.

I didn't understand or comprehend a feature of Amibroker - a program at the moment that is challenging for me but with your help and comments from other just goes to prove why ASF is a well respected site. I'm really taken back with how many member were willing to help me.

All comments were appreciated..

skate
 
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

Your code controls the radio button.

AmiBroker , MetaStock, BullCharts, whatever the testing platform you choose, they all require instructions on how to handle the various aspects of system development, so don't fall into the trap of blaming the platform as you are in control....scary eh!

I believe that many budding system developers have been caught by the same mistake you have made, just learn from these mistakes and don't feel embarrassed, potentially one down and many to go.

Hey Captain Black, Tech/a, Wysiwyg and many others, I reckon this will have happened to you and I know damn well it's happened to me!

This code

Code:
Buy = C > DonchianUpper;
BuyPrice = Open;
Sell = C < MA(C,50);
SellPrice = Open;
SetTradeDelays(1,1,1,1);

will have the same results as this code

Code:
Buy = Ref(C > DonchianUpper,-1);
BuyPrice = Open;
Sell = Ref(C < MA(C,50),-1);
SellPrice = Open;

The power is in your hands and it can be an interesting, although sometimes frustrating, journey.

Enjoy and don't forget to ask when you need help.
 
Greetings all --

I see my name in some of the recent messages, but I don't see the code attributed to me. So, my comments may be off the mark. Sorry if that is the case.

That said ----

Future leaks occur when the code "reads" or "knows" data that would not yet be available in real time. Some trading system development platforms attempt to make it impossible to look into the future. It is often very valuable to intentionally use future data during development of trading ideas. AmiBroker allows use of future data, leaving it up to the person coding and testing to be aware and take precautions.

Sometimes what appears to be a simple change enables a future leak and is easily overlooked. For example, changing the time at which a signal is acted upon from Close to Open. If this is hidden in an #include file, or in one of the alternatives being testing in an optimization, it can be hard to find.

Here are three symptoms of a future leak:

1. The "check code and profile" function available from the Formula Editor informs you that there is a future leak. Note that this option is not perfect -- code inside an include is not checked, and computations of variables applied to price or time may create may create a future leak during execution that cannot be determined during compilation.

2. The equity curve looks way too good.

3. When the program is run using "bar replay" from the Tools menu, indicators, including buy and sell arrows, change when new data is received.

I hope this helps,
Best regards,
Howard
 
Greetings all --

I see my name in some of the recent messages, but I don't see the code attributed to me. So, my comments may be off the mark. Sorry if that is the case.

That said ----

Future leaks occur when the code "reads" or "knows" data that would not yet be available in real time. Some trading system development platforms attempt to make it impossible to look into the future. It is often very valuable to intentionally use future data during development of trading ideas. AmiBroker allows use of future data, leaving it up to the person coding and testing to be aware and take precautions.

Sometimes what appears to be a simple change enables a future leak and is easily overlooked. For example, changing the time at which a signal is acted upon from Close to Open. If this is hidden in an #include file, or in one of the alternatives being testing in an optimization, it can be hard to find.

Here are three symptoms of a future leak:

1. The "check code and profile" function available from the Formula Editor informs you that there is a future leak. Note that this option is not perfect -- code inside an include is not checked, and computations of variables applied to price or time may create may create a future leak during execution that cannot be determined during compilation.

2. The equity curve looks way too good.

3. When the program is run using "bar replay" from the Tools menu, indicators, including buy and sell arrows, change when new data is received.

I hope this helps,
Best regards,
Howard

TO CLEAR UP THE CONFUSION

QUESTION

I was backtesting my strategy and achieving pleasing results before I read Howard Bandy answer to a members question wanting to know the formula to execute a BUY the next day after the signals is generated - meaning the BUY is execute at the next day's opening price.

As that's how I plan to trade I added this code to my strategy.

Once I added the code below to my strategy my Backtest results went from Net Profit of $26,044 to a Net Loss of -$3,534

I wouldn't have thought buying the next day compared to buying the same day would make such a difference to my Backtest results.

Can anyone shed light on how this could be possible?

The Code I added
/////////////////////////////////////////////////
BuyPrice = Open;
SellPrice = Open;
SetTradeDelays(1,1,1,1);
/////////////////////////////////////////////////

skate.

Habakkuk kindly replied to my concern and gave me a suggestion of placing SetTradeDelays(1,1,1,1); to my code that I quickly applied:

This is an extract lifted from Habakkuk reply giving me help..

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);


Howard you also said in your reply to the member:

Statements in the afl code take precedence over settings made on the Settings dialog box. I recommend that you always write code in the afl that explicitly sets the execution price.

I, like everyone else on this forum values your knowledge and I accept what you say is Gospel.

The Code you supplied that I added to my strategy

/////////////////////////////////////////////////
BuyPrice = Open;
SellPrice = Open;
SetTradeDelays(1,1,1,1);
/////////////////////////////////////////////////

I quickly added your code to my strategy immediately after reading your post and went from receiving great results from my Backtest without a trade delay to very disappointing results after the insertion of the Trade Delay code.

I posted my query seeking an answer to why by changing the Trade Delay by one day could have a DRAMATIC change to the result in the Backtest reports.

I know this forum has some of the smartest bunnies around and even a very knowledgeable duck - I knew someone would answer a question I could figure out..

skate
 
TO CLEAR UP THE CONFUSION



Habakkuk kindly replied to my concern and gave me a suggestion of placing SetTradeDelays(1,1,1,1); to my code that I quickly applied:

This is an extract lifted from Habakkuk reply giving me help..

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);


Howard you also said in your reply to the member:

Statements in the afl code take precedence over settings made on the Settings dialog box. I recommend that you always write code in the afl that explicitly sets the execution price.

I, like everyone else on this forum values your knowledge and I accept what you say is Gospel.

The Code you supplied that I added to my strategy

/////////////////////////////////////////////////
BuyPrice = Open;
SellPrice = Open;
SetTradeDelays(1,1,1,1);
/////////////////////////////////////////////////

I quickly added your code to my strategy immediately after reading your post and went from receiving great results from my Backtest without a trade delay to very disappointing results after the insertion of the Trade Delay code.

I posted my query seeking an answer to why by changing the Trade Delay by one day could have a DRAMATIC change to the result in the Backtest reports.

I know this forum has some of the smartest bunnies around and even a very knowledgeable duck - I knew someone would answer a question I could figure out..

skate

EDIT TO MY PREVIOUS POST

I know this forum has some of the smartest bunnies around and even a very knowledgeable duck - I knew someone would answer a question I couldn't figure out..

An alteration to a ONE word has made a huge difference to the meaning on the sentence..

skate
 
A question about running a backtest..

If you run a backtest on the same universe of securities with the same setting, one after the other - should the report results be the same every time?

So there is no confusion - I run the backtest 10 times straight AFTER EACH OTHER - I take a note of the report results, I than hit the backtest button again run the Backtest again take a record of the report results and repeat ten times in a row - should the backtest report results display exactly the same report results TEN TIMES?

OR can the 10 consecutive Backtests 'run seconds apart' display 10 different report results?

skate
 
A question about running a backtest..

If you run a backtest on the same universe of securities with the same setting, one after the other - should the report results be the same every time?

So there is no confusion - I run the backtest 10 times straight AFTER EACH OTHER - I take a note of the report results, I than hit the backtest button again run the Backtest again take a record of the report results and repeat ten times in a row - should the backtest report results display exactly the same report results TEN TIMES?

OR can the 10 consecutive Backtests 'run seconds apart' display 10 different report results?

skate

Yes, they are the same ones if there are same afl, same settings, same data.

But… http://www.amibroker.com/kb/2014/05/07/why-do-backtest-results-change/
 
A question about running a backtest..

If you run a backtest on the same universe of securities with the same setting, one after the other - should the report results be the same every time?

So there is no confusion - I run the backtest 10 times straight AFTER EACH OTHER - I take a note of the report results, I than hit the backtest button again run the Backtest again take a record of the report results and repeat ten times in a row - should the backtest report results display exactly the same report results TEN TIMES?

OR can the 10 consecutive Backtests 'run seconds apart' display 10 different report results?

skate

If you're getting different results then one issue may be if you have positionscore set to random.
 
Thanks..

That was the culprit..

PositionScore = mtRandomA();

skate

The same thing is written in Tomasz's article already. But it seems that short article was way too long and after all short attention span rules nowadays.
 
Greetings --

In a slightly earlier post, Skate made reference to these statements:

/////////////////////////////////////////////////
BuyPrice = Open;
SellPrice = Open;
SetTradeDelays(1,1,1,1);
/////////////////////////////////////////////////

-----------------------------------

When designing a trading system, I find it helps to imagine myself at some particular time, then adjust the rule calculation, BuyPrice, and Delay statements so that all the calculations are both consistent and appropriate for potential use as a real trading system.

-----

For example, if when trading I will be taking a position at the close of the day using that day's data, I will use these statements:

BuyPrice = Close;
SellPrice = Close;
SetTradeDelays(0,0,0,0);

xxx = ...;
yyy = ...;
Rule1 = xxx < yyy;
Buy = Rule1;

-----

If I will be taking a position at the next open using data from the previous close, I imagine myself looking at the AmiBroker screen as the first data at the time of tomorrow's open appears, and I will use these statements:

BuyPrice = Open;
SellPrice = Open;
SetTradeDelays(0,0,0,0);

xxx = ...;
yyy = ...;
Rule1 = xxx < yyy;
Buy = Ref(Rule1,-1);

---

If I will be taking a position at today's open using data from today's open, I will use these statements:

BuyPrice = Open;
SellPrice = Open;
SetTradeDelays(0,0,0,0);

xxx = ...;
yyy = ...;
Rule1 = xxx < yyy;
Buy = Rule1;

---

If I will be taking a position at the next day's close using data from today, as I might when using a traditional mutual fund computing signals in the evening, I will use these statements:

BuyPrice = Close;
SellPrice = Close;
SetTradeDelays(1,1,0,0);

xxx = ...;
yyy = ...;
Rule1 = xxx < yyy;
Buy = Rule1;

----

In all of these cases, it is important to think through what data is being used, and when it is available. Hoping to test different entry conditions, such as from today's close to tomorrow's open, is more complex than simply changing SetTradeDelay and BuyPrice. The calculation of xxx, yyy, and Rule1 may change. In particular, they may or may not have Ref functions applied in one set of circumstances versus others.

--------

I want my AmiBroker code to reflect how I will generate signals and trade as I am trading. That is -- I want everything relative to the moment I will be placing the order. This allows the version of the system I use to backtest to be exactly the same as the version I trade. It removes (at least for me) the difficulty of aligning SetTradeDelay with Ref, and ensures that all data is present when it is needed.

-------

I hope this helps more than it adds to the confusion,
Best,
Howard
 
When designing a trading system, I find it helps to imagine myself at some particular time, then adjust the rule calculation, BuyPrice, and Delay statements so that all the calculations are both consistent and appropriate for potential use as a real trading system.

Hi Doc,

Excellent presentation - as usual.

I wish I'd used your method six months ago. I was backtesting a gap down system. I didn't know if it was today, tomorrow, or yesterday. And that was without my usual nighttime wee dram or three.

Another of your recommendations in these tricky situations is to use "validation" in the Interpretation window.

So, in your own example, you could add the following code:

"BuyPrice = " + BuyPrice ;
"SellPrice = " + SellPrice ;
"xxx = " + xxx ;
"yyy = " + yyy ;
"xxx < yyy = " + ( xxx < yyy ) ; // parentheses
"Rule1 = " + Rule1 ;
"Ref(Rule1,-1) = " + Ref(Rule1,-1); // bingo
"Buy = " + Buy ;

Use Buy and Sell arrows, and check every variable bar by bar, starting a few bars before the Buy.

(You can see that there are several redundant validation steps. But better so many than so few - as Churchill used to say.)

These validation steps can also be used for "reverse engineering". In fact, that was how I solved my gap system. I finally saw that I needed the "Ref" of Rule1.

Best regards,
OG
 
Hi All,

I have a slight issue with my portfolio backtest.

I want to limit my position PER STOCK to 1 only.

I want to be able to enter on redundant signals
ie SetBacktestMode( backtestRegularRaw );
I have set my max open positions
SetOption("MaxOpenPositions",10);

Is there a way of checking if you have a position in the current symbol and then removing the buy signal if already holding a position in that symbol.

P.S. I am not talking about Exrem as this has no knowledge of if the backtester has taken the trade and removes signals that I potentially want to take.


Thanks.
 
I'm back with another question.

I've been testing a system based on Nick Radge's Weekend Trend Trader. I'm OK with the basic code and have run some back-testing so I can see that the code is working.

I am just in the throes of working through Nick Radge's Weekend Trend Trader and have set the following filters


Code:
SetForeign( "XAO" );

Filter1 =  MA( C, 10 ) > C;

RestorePriceArrays();

Filter2 = ROC(C,20)> 30;

Filter = Filter1 AND Filter2;


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


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


BolliBot = BBandBot(C,100,1);


Sell = C<= BolliBot;

I am testing this code on Qantas [QAN] and for the time frame 05/12/2014 to 31/12/2014. A buy is being generated on 5/12/2014. However from my analysis, the filter on XAO 10 week MA should exclude the trade.

I would welcome any comment on where my code is incorrect.
 
I am testing this code on Qantas [QAN] and for the time frame 05/12/2014 to 31/12/2014. A buy is being generated on 5/12/2014. However from my analysis, the filter on XAO 10 week MA should exclude the trade.

I would welcome any comment on where my code is incorrect.

If you're using an index filter then you need to have the "pad and align data to reference symbol" box in the AA settings ticked and also the reference symbol set to "XAO".
 
If you're using an index filter then you need to have the "pad and align data to reference symbol" box in the AA settings ticked and also the reference symbol set to "XAO".

Captain Black -thanks foir your reply, but I do have this setting tick. So this is not the issue
 
Top