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

Re: [amibroker] Re: Backtester is opening positions at bar *low*,notat *close*


  • Date: Wed, 30 Dec 2009 17:29:47 -0500
  • From: Herman <psytek@xxxxxxxx>
  • Subject: Re: [amibroker] Re: Backtester is opening positions at bar *low*,notat *close*

PureBytes Links

Trading Reference Links



By far the easiest way to detect pricing errors in complex systems is to turn off PriceBoundChecking and plot a big Red vertical bar whenever you have a pricing error. This is far quicker than studying code for hours :-)
I use the code below.

Herman

_SECTION_BEGIN( "CHECKING PRICE BOUNDS" );
// Buy, Sell, Short and Cover must be defined for this code to work.
// In use this code would be appended to the very end of your code.
// When working on complex system's code where BuyPrice, SellPrice, etc.
// are modified in different sections it is easy to introduce a pricing
// error so that you are trading outside the bar. Especially so since
// SetOption("PriceBoundChecking",TRUE) is the default and Amibroker
// will fit your trades within the bar limits and hide the problem.
// This code check the limits of your tradeprices, display the number
// of errors in the chart title and plot a red marker at the bottom of
// chart where the error occurs.

SetOption( "PriceBoundChecking", False );
BuyError = ( BuyPrice > H OR BuyPrice < L ) AND Buy;
SellError = ( SellPrice > H OR SellPrice < L ) AND Sell;
ShortError = ( ShortPrice > H OR ShortPrice < L ) AND Short;
CoverError = ( CoverPrice > H OR CoverPrice < L ) AND Cover;
PricingErrors = BuyError OR SellError OR ShortError OR CoverError;
Plot( PricingErrors , "", 4, styleArea | styleOwnScale, 0, 10 );
Title = "# Price Bound Errors: " + NumToStr( Cum( PricingErrors ), 1.0, False ) + "\n";
_SECTION_END();




Potato Soup wrote:
I will send the formula soon. Just know that I'm not using BuyPrice/SellPrice/ShortPrice/CoverPrice at all. 

Thx. 

-----Original Message-----
From: Tomasz Janeczko <groups@xxxxxxxxxxxxx>
Date: Wed, 30 Dec 2009 21:40:11 
To: <amibroker@xxxxxxxxxxxxxxx>
Subject: Re: [amibroker] Re: Backtester is opening positions at bar *low*,not
 at *close*

Hello,

I wrote you send the formula to support. It is pointless to discuss 
otherwise.
Let me give you simple example. If you write in your formula things like 
that:

BuyPrice = Ref( C, -1 );

It will assign BUYPRICE variable to be CLOSE OF YESTERDAY.

But the trade occurs TODAY (because you have set "delay of zero" as you 
wrote).

Now if YESTERDAY CLOSE was lower than TODAYS LOW,  the backtester will 
use  todays LOW price (lowest possible price) because by default it 
protects from using prices outside H-L range as described in the manual 
http://www.amibroker.com/guide/h_backtest.html

The other example can be:

BuyPrice = C - ATR(1);

This will SUBTRACT true range from todays close price and use it as 
buyprice, but if result is lower than todays low, the backtester will 
use lowest possible price (i.e. todays low).

The above is just example of what can happen if you manipulate 
BuyPrice/SellPrice/ShortPrice/CoverPrice in the formula without really 
knowing what you are doing.

As this is academic discussion without you showing the formula you are 
using , I repeat that if you have troubles understanding what your own 
formula is doing you should send it to support.

Best regards,
Tomasz Janeczko
amibroker.com

On 2009-12-30 21:03, Potato Soup wrote:
  
Its not assigning a trade price outside the boundaries of the bar. Its assigning it to the low of the bar, not the close. So where does lower than low come in to play?
-----Original Message-----
From: "progster01"<progster@xxxxxxxxxxxxxxxxxx>
Date: Wed, 30 Dec 2009 18:21:07
To:<amibroker@xxxxxxxxxxxxxxx>
Subject: [amibroker] Re: Backtester is opening positions at bar *low*,not at *close*


No, he meant "lower than low" as stated.

The reason is that the backtester "knows" not to assign a trade price outside the boundaries of the bar.

--- In amibroker@xxxxxxxxxxxxxxx, "Potato Soup"<potatosoupz@xxx>  wrote:
   
    
You mean with prices lower than "Close", not Low right?
     
      
   
    
-----Original Message-----
From: Tomasz Janeczko<groups@xxx>
Date: Wed, 30 Dec 2009 16:48:53
To:<amibroker@xxxxxxxxxxxxxxx>
Subject: Re: [amibroker] Re: Backtester is opening positions at bar *low*,
  not at *close*

Hello,

Such behaviour can only have one explanation, you
are overriding BuyPrice/ShortPrice with prices lower than Low.
It can happen for example if you are referring to previous day prices
(using Ref())
that can easily be lower than todays.
If you can not spot the error in formula send it to support and Marcin
will tell you where
error is.

Best regards,
Tomasz Janeczko
amibroker.com

On 2009-12-30 13:12, Potato Soup wrote:
     
      
I have that value set to 0% in the Portfolio tab. Has been that way
for some tmie. I will run the test with detailed reports. Thanks.

------------------------------------------------------------------------
*From:* Mike<sfclimbers@xxx>
*To:* amibroker@xxxxxxxxxxxxxxx
*Sent:* Wed, December 30, 2009 1:32:53 AM
*Subject:* [amibroker] Re: Backtester is opening positions at bar
*low*, not at *close*

There is a setting in AA Settings that prevents taking a position if
your volume exceeds a certain threshold of the bar's volume. If you
were right on the cusp of that threshold with a lessor commission,
perhaps with the greater commission (fewere units, same total price)
you squeeked under the limit and took the trade.

Best way to compare is to set AA Settings reporting to detailed, then
run under both scenarios and compare the output. You will see why each
signal was accepted/rejected.

Mike

--- In amibroker@xxxxxxxxxxxxxxx<mailto:amibroker@xxxxxxxxxxxxxxx>,
Potato Soup<potatosoupz@>  wrote:
       
        
Well I have my account balance at $350k and I'm trading no more than
         
          
$30k max in positions, how on earth could it skip a trade with that? I
am using 2:1 margin but with that ratio of capital to exposure it
should be impossible to have an effect. What else could be the reason?
       
        
Also I have no changes or uses of BuyPrice/SellPrice and I have
         
          
trade delays set to 0 for all four types of orders.
       
        
Given all that, what other reasons could cause this behavior?

Thanks for your help, as always.




________________________________
From: Mike<sfclimbers@>
To: amibroker@xxxxxxxxxxxxxxx<mailto:amibroker@xxxxxxxxxxxxxxx>
Sent: Tue, December 29, 2009 11:52:48 PM
Subject: [amibroker] Re: Backtester is opening positions at bar
         
          
*low*, not at *close*
       
        
1. Changing *any* setting related to pricing can affect your trades.
         
          
All it takes is one penny too little in your account to prevent the
taking of a trade, which in turn would mean having more funds
available for the next opportunities (i.e. able to take other trades)
that would not have been there if the original trade were able to be
taken at a penny less.
       
        
2. If you've confirmed that the AA Settings window has the trade
         
          
price marked as Close, and that you have not put in an override in
your AFL code (look for BuyPrice, SellPrice and Signal alteration in
custom backtester code), then check too that you have not set any
trade delays. A trade delay will cause the next bar(s) price to be
used which will likely be different than that of the bar on which the
signal was triggered.
       
        
Mike

--- In amibroker@xxxxxxxxxxxxxxx<mailto:amibroker@xxxxxxxxxxxxxxx>,
         
          
Potato Soup<potatosoupz@>  wrote:
       
        
Now this is really weird. I just ran the backtester again and also
           
            
noticed that the trade opening and closing is happening on the LOW of
bars that have signals, not on the CLOSE, as I've defined it in the
settings for the backtester. I have it set to execute trades on Close
for all four parameters (buy,sell,short,cover).
       
        
Why would this be happening? I haven't overriden it in my AFL
           
            
either. It's completely throwing off the results of the test.
Obviously there's no way to know what the low of a bar would be until
the bar is complete, and in the past.
       
        
           
            

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

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com<http://amibroker.com>

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

         
          

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

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links


amibroker-fullfeatured@xxxxxxxxxxxxxxx
<mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx>






       
        
     
      

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

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links





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

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links




   
    


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

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links





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

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    amibroker-digest@xxxxxxxxxxxxxxx 
    amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/



  


__._,_.___


**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/





Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___