[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] SetTradeDelay & exploration-backtesting different results



PureBytes Links

Trading Reference Links




Antonio,
 
As I wrote in my previous response: you delay PRICE arrays 
which must NOT be done.
 
The OPEN price for AA on January 6, 2003 is 
23.95
 
Your code uses
BuyPrice = Ref( Open, -1 )
so it effectivelly delay OPEN Price one bar so 
Buyprice on Jan 7 becomes 23.95 (yesterdays open)
 
and this is WRONG. because on Jan 7 the open price is 
24.40.
 
What's more backtester checks if BuyPrice is within current 
bar H-L range.
and... it isn't because Low of Jan 7 was 24.10 therefore it 
readjust the buyprice to fit REAL TRADING RANGE:
 
As written in the TUTORIAL: Backtesting your trading 
ideas
"During back-testing AmiBroker will check 
if the values you assigned to buyprice, sellprice, shortprice, coverprice fit 
into high-low range of given bar. If not, AmiBroker will adjust it to high price 
(if price array value is higher than high) or to the low price (if price array 
value is lower than low)"
 
 
Therefore your code should look like this:
 

<FONT face="Courier New" 
color=green size=1><SPAN lang=EN-GB 
>//Filter= 
Buy=Cross(C,EMA(C,10)) OR Cross(EMA(C,10),C);
<FONT face="Courier New" 
color=darkred size=1><SPAN lang=EN-GB 
>Filter<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>= 
<SPAN lang=EN-GB 
>Buy<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>=<FONT 
face="Courier New" color=blue size=1><SPAN lang=EN-GB 
>DayOfWeek<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>()==<FONT 
face="Courier New" color=#ff6820 size=1><SPAN lang=EN-GB 
>1<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
> 
<SPAN lang=EN-GB 
>OR<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
> 
<SPAN lang=EN-GB 
>Sell<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>=<FONT 
face="Courier New" color=blue size=1><SPAN lang=EN-GB 
>DayOfWeek<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>()==<FONT 
face="Courier New" color=#ff6820 size=1><SPAN lang=EN-GB 
>1<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>;
<FONT face="Courier New" 
color=black size=1><SPAN lang=EN-GB 
> 
<FONT face="Courier New" color=blue 
size=1><SPAN lang=EN-GB 
>AddColumn<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>(<FONT 
face="Courier New" color=darkred size=1><SPAN lang=EN-GB 
>O<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>,<FONT 
face="Courier New" color=fuchsia size=1><SPAN lang=EN-GB 
>"Open"<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>,<FONT 
face="Courier New" color=#ff6820 size=1><SPAN lang=EN-GB 
>1.2<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>);
<FONT face="Courier New" color=blue 
size=1><SPAN lang=EN-GB 
>AddColumn<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>(<FONT 
face="Courier New" color=darkred size=1><SPAN lang=EN-GB 
>C<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>,<FONT 
face="Courier New" color=fuchsia size=1><SPAN lang=EN-GB 
>"Close"<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>,<FONT 
face="Courier New" color=#ff6820 size=1><SPAN lang=EN-GB 
>1.2<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>);
<FONT face="Courier New" color=blue 
size=1><SPAN lang=EN-GB 
>AddColumn<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>(<FONT 
face="Courier New" color=darkred size=1><SPAN lang=EN-GB 
>O<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>,<FONT 
face="Courier New" color=fuchsia size=1><SPAN lang=EN-GB 
>"Buy"<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>,<FONT 
face="Courier New" color=#ff6820 size=1><SPAN lang=EN-GB 
>1.2<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>);
<FONT face="Courier New" color=blue 
size=1><SPAN lang=EN-GB 
>AddColumn<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>(<FONT 
face="Courier New" color=darkred size=1><SPAN lang=EN-GB 
>C<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>,<FONT 
face="Courier New" color=fuchsia size=1><SPAN lang=EN-GB 
>"Sell"<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>,<FONT 
face="Courier New" color=#ff6820 size=1><SPAN lang=EN-GB 
>1.2<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>);
<FONT face="Courier New" 
color=black size=1><SPAN lang=EN-GB 
> 
<FONT face="Courier New" 
color=green size=1><SPAN lang=EN-GB 
>//DELAY manual 
setting
<FONT face="Courier New" 
color=black size=1><SPAN lang=EN-GB 
>Buy_Delay   
= <SPAN 
lang=EN-GB 
>1<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>;
<FONT face="Courier New" 
color=black size=1><SPAN lang=EN-GB 
>Sell_Delay  
= <SPAN 
lang=EN-GB 
>2<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>;
<FONT face="Courier New" 
color=black size=1><SPAN lang=EN-GB 
>Short_Delay = 
<SPAN lang=EN-GB 
>1<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>;
<FONT face="Courier New" 
color=black size=1><SPAN lang=EN-GB 
>Cover_Delay = 
<SPAN lang=EN-GB 
>1<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>;
<FONT face="Courier New" color=blue 
size=1><SPAN lang=EN-GB 
>SetTradeDelays<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>(Buy_Delay, 
Sell_Delay, Short_Delay, Cover_Delay);
<FONT face="Courier New" 
color=black size=1><SPAN lang=EN-GB 
> 
<FONT face="Courier New" 
color=green size=1><SPAN lang=EN-GB 
>//Buy=Cross(C,EMA(C,10)); 

<FONT face="Courier New" 
color=green size=1><SPAN lang=EN-GB 
>//Sell=Cross(EMA(C,10),C); 

<FONT face="Courier New" 
color=darkred size=1><SPAN lang=EN-GB 
>Buy<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>=<FONT 
face="Courier New" color=blue size=1><SPAN lang=EN-GB 
>DayOfWeek<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>()==<FONT 
face="Courier New" color=#ff6820 size=1><SPAN lang=EN-GB 
>1<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>;
<FONT face="Courier New" 
color=darkred size=1><SPAN lang=EN-GB 
>Sell<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>=<FONT 
face="Courier New" color=blue size=1><SPAN lang=EN-GB 
>DayOfWeek<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>()==<FONT 
face="Courier New" color=#ff6820 size=1><SPAN lang=EN-GB 
>1<FONT 
face="Courier New" size=1><SPAN lang=EN-GB 
>;
<FONT face="Courier New" 
size=1><SPAN lang=EN-GB 
> 
<FONT face="Courier New" 
size=2><SPAN lang=EN-GB 
>/* 
NEVER DELAY PRICE ARRAYS !!!!!!!!!!!!!!!!!!!! */
<FONT 
face="Courier New"><SPAN lang=EN-GB 
>/* 
<SPAN lang=EN-GB 
>BuyPrice<FONT 
face="Courier New"><SPAN lang=EN-GB 
> = 
<SPAN lang=EN-GB 
>Ref<FONT 
face="Courier New"><SPAN lang=EN-GB 
>(<FONT 
face="Courier New"><SPAN lang=EN-GB 
>O<FONT 
face="Courier New"><SPAN lang=EN-GB 
>,Buy_Delay); 
*/
<FONT 
face="Courier New"><SPAN lang=EN-GB 
>/* 
<SPAN lang=EN-GB 
>SellPrice<FONT 
face="Courier New"><SPAN lang=EN-GB 
> = 
<SPAN lang=EN-GB 
>Ref<FONT 
face="Courier New"><SPAN lang=EN-GB 
>(<FONT 
face="Courier New"><SPAN lang=EN-GB 
>C<FONT 
face="Courier New"><SPAN lang=EN-GB 
>,Sell_Delay); 
*/
<FONT face="Courier New" 
size=1><SPAN lang=EN-GB 
> 
<FONT face="Courier New" color=blue 
size=1><SPAN lang=EN-GB 
>AddColumn<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>(Buy_Delay,<FONT 
face="Courier New" color=fuchsia size=1><SPAN lang=EN-GB 
>"Buy 
Delay"<SPAN lang=EN-GB 
>,<FONT 
face="Courier New" color=#ff6820 size=1><SPAN lang=EN-GB 
>1.0<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>);
<FONT face="Courier New" color=blue 
size=1><SPAN lang=EN-GB 
>AddColumn<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>(<FONT 
face="Courier New" color=blue size=1><SPAN lang=EN-GB 
>IIf<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>(<FONT 
face="Courier New" color=darkred size=1><SPAN lang=EN-GB 
>Buy<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>==<FONT 
face="Courier New" color=#ff6820 size=1><SPAN lang=EN-GB 
>1<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>,<FONT 
face="Courier New" color=darkred size=1><SPAN lang=EN-GB 
>BuyPrice<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>,<FONT 
face="Courier New" color=#ff6820 size=1><SPAN lang=EN-GB 
>0<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>),<FONT 
face="Courier New" color=fuchsia size=1><SPAN lang=EN-GB 
>"Delayed Buy 
Price"<SPAN lang=EN-GB 
>,<FONT 
face="Courier New" color=#ff6820 size=1><SPAN lang=EN-GB 
>1.2<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>);
<FONT face="Courier New" color=blue 
size=1><SPAN lang=EN-GB 
>AddColumn<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>(Sell_Delay,<FONT 
face="Courier New" color=fuchsia size=1><SPAN lang=EN-GB 
>"Sell 
Delay"<SPAN lang=EN-GB 
>,<FONT 
face="Courier New" color=#ff6820 size=1><SPAN lang=EN-GB 
>1.0<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>);
<FONT face="Courier New" color=blue 
size=1><SPAN lang=EN-GB 
>AddColumn<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>(<FONT 
face="Courier New" color=blue size=1><SPAN lang=EN-GB 
>IIf<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>(<FONT 
face="Courier New" color=darkred size=1><SPAN lang=EN-GB 
>Sell<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>==<FONT 
face="Courier New" color=#ff6820 size=1><SPAN lang=EN-GB 
>1<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>,<FONT 
face="Courier New" color=darkred size=1><SPAN lang=EN-GB 
>SellPrice<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>,<FONT 
face="Courier New" color=#ff6820 size=1><SPAN lang=EN-GB 
>0<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>),<FONT 
face="Courier New" color=fuchsia size=1><SPAN lang=EN-GB 
>"Delayed Sell 
Price"<SPAN lang=EN-GB 
>,<FONT 
face="Courier New" color=#ff6820 size=1><SPAN lang=EN-GB 
>1.2<FONT 
face="Courier New" color=black size=1><SPAN lang=EN-GB 
>);
<SPAN lang=EN-GB 
> 
<SPAN lang=EN-GB 
> 
<SPAN lang=EN-GB 
>Then, if I change these conditions
<SPAN lang=EN-GB 
> 
<SPAN lang=EN-GB 
>      
Buy = DayOfWeek()==1;
<SPAN lang=EN-GB 
>      
Sell= 
DayOfWeek()==1;
 
Best regards,Tomasz Janeczkoamibroker.com
<BLOCKQUOTE 
>
  ----- Original Message ----- 
  <DIV 
  >From: 
  Antonio Marra 
  
  To: <A title=amibroker@xxxxxxxxxxxxxxx 
  href="">amibroker@xxxxxxxxxxxxxxx 
  Sent: Tuesday, March 11, 2003 8:24 
  PM
  Subject: Re: [amibroker] SetTradeDelay 
  & exploration-backtesting different results
  
  
  <SPAN lang=EN-GB 
  >Hello Tomasz,
  <SPAN lang=EN-GB 
  > 
  <SPAN lang=EN-GB 
  >You are clear as 
  usual.
  <SPAN lang=EN-GB 
  >I beg your pardon for wasting your 
  time,
  <SPAN lang=EN-GB 
  > 
  <SPAN lang=EN-GB 
  >But the question 
  is:
  <SPAN lang=EN-GB 
  >running exploration (the code I 
  posted) the AA give me a signal and respective open price for the next bar 
  (day), 
  <SPAN lang=EN-GB 
  >i.e., on <FONT 
  face=Arial size=2><SPAN lang=EN-GB 
  >06/01/2003<FONT 
  face=Arial size=2><SPAN lang=EN-GB 
  > there is a “signal” and the buy 
  price at open for the next bar is 17.91
  <SPAN lang=EN-GB 
  > 
  <SPAN lang=EN-GB 
  >Why does the backtester show me a 
  “buy price” at open on <SPAN lang=EN-GB 
  >07/01/2003<FONT 
  face=Arial size=2><SPAN lang=EN-GB 
  > (the right delay) at 18.25 (?) 
  and not 17.91 (the right open price)?
  <SPAN lang=EN-GB 
  >The same thing happens for the 
  exit price.
  <SPAN lang=EN-GB 
  > 
  <SPAN lang=EN-GB 
  >Thanks again
  <SPAN lang=EN-GB 
  > 
  <SPAN lang=EN-GB 
  >Best regard
  <SPAN lang=EN-GB 
  >Antonio
  <SPAN lang=EN-GB 
  > Send 
  BUG REPORTS to bugs@xxxxxxxxxxxxxSend SUGGESTIONS to 
  suggest@xxxxxxxxxxxxx-----------------------------------------Post 
  AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web page: <A 
  href="">http://groups.yahoo.com/group/amiquote/messages/)--------------------------------------------Check 
  group FAQ at: <A 
  href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
  Your use of Yahoo! Groups is subject to the <A 
  href="">Yahoo! Terms of Service. 







Yahoo! Groups Sponsor


  ADVERTISEMENT









Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html



Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.