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

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



PureBytes Links

Trading Reference Links




Hello,
 
1. SetTradeDelay is FOR BACKTESTER, not for 
exploration.
2. Also you must not delay PRICES. Ref( buyprice, something ) 
is wrong. Only signal can be delayed.
3. Ref( ) with positive shift references FUTURE not past. The 
delay can be coded usign Ref( array, -1 ).
Ref( array, 1 ) is incorrect.
 
The intention is as follows:
your EOD system generates signals using close 
price.
You run this after trading session close. Via SCAN/EXPLORATION 
you get signals TODAYs evening so you can
place it for tommorrows open.
 
BUT...
for the BACKTESTING you need to SetTradeDelays( 1, 1, 1, 
1)
so backtester trades on next bar OPEN price (as you trade in 
reality).
 
This way SINGLE formula can work BOTH for scan and backtest 
without need to modify anything.
Just run SCAN / EXPLORE and you get SIGNALS TODAY to place 
order FOR TOMMORROW.
and you run BACKTEST and it trades next bar (as in 
reality)
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 5:21 
  PM
  Subject: [amibroker] SetTradeDelay & 
  exploration-backtesting different results
  
  
  <SPAN lang=EN-GB 
  >Hello,
  <SPAN lang=EN-GB 
  > 
  <SPAN lang=EN-GB 
  >I found useful the code posted by Graham with the 
  message 30344, so I have used a part of it for testing and verify how 
  “<SPAN lang=EN-GB 
  >SetTradeDelay() 
  function” works.
  <SPAN lang=EN-GB 
  >Well, starting an exploration it give me a right buy 
  and sell price in the "results" window, but the backtesting don't give the 
  same results: the buy and sell prices don't correspond.  
  
  <SPAN lang=EN-GB 
  >This is the code I used (tested on one single stock 
  [BRCM], from 01/01/2003 to 31/01/2003):
  <FONT face="Courier New" 
  size=2><SPAN lang=EN-GB 
  > 
  <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" 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=darkred size=1><SPAN lang=EN-GB 
  >BuyPrice<FONT 
  face="Courier New" color=black size=1><SPAN lang=EN-GB 
  > = 
  <SPAN lang=EN-GB 
  >Ref<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 
  >,Buy_Delay);
  <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 
  > = 
  <SPAN lang=EN-GB 
  >Ref<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 
  >,Sell_Delay);
  <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 
  >(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;
  <SPAN lang=EN-GB 
  > 
  <SPAN lang=EN-GB 
  >with these ones
  <SPAN lang=EN-GB 
  > 
  <SPAN lang=EN-GB 
  >      
  Buy=Cross(C,EMA(C,10));  
  
  <SPAN lang=EN-GB 
  >      
  <SPAN 
  >Sell=Cross(EMA(C,10),C);
  <SPAN lang=EN-GB 
  > 
  <SPAN lang=EN-GB 
  >both the exploration and the backtesting seem to 
  work.
  <SPAN lang=EN-GB 
  >What I'm doing wrong ?
  <SPAN lang=EN-GB 
  > 
  <SPAN lang=EN-GB 
  >Thanks for your valuable help.
  <SPAN lang=EN-GB 
  > 
  <SPAN 
  >Best Regards
  <SPAN 
  >Antonio
  <SPAN 
  > 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.