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

Re: [amibroker] Re: BUY and SELL signal on same bar cashflow problem


  • Date: Tue, 09 Mar 2010 09:08:41 +0100
  • From: Tomasz Janeczko <groups@xxxxxxxxxxxxx>
  • Subject: Re: [amibroker] Re: BUY and SELL signal on same bar cashflow problem

PureBytes Links

Trading Reference Links



Hello,

You got it all wrong
1. You should NEVER use different buy/sell delays in SetTradeDelays. So either use SetTradeDelays( 0, 0, 0, 0 )
or use SetTradeDelays( 1, 1, 1, 1 ).
What SetTradeDelays does is internally Ref() the buy or sell array.
If you are using unequal delays (as you did) and buy delay is greater than sell delay
you could move buy signals AFTER sell signals, destroying original sequence of events.
2. trade length includes ENTRY bar, 1st day is ENTRY bar, therefore if you need to exit at 3rd day
you should use -2 (not -3) in the ref() function call, because bars are counted: 0, 1, 2.
Then you won't have problem with your "exit date".
3. Actually the best way to implement n-bar delay is to use ApplyStop

ApplyStop( stopTypeNBar, stopModeBars, 3 );

ApplyStop works in ALL BACKTESTER MODES (raw, raw2, rotational) and regardless of trade delays.
ExRemSpan is *obsolete* and it works only in regular mode, therefore should be avoided.

Best regards,
Tomasz Janeczko
amibroker.com

On 2010-03-09 02:06, Mike wrote:

Hi,

as a workaround it seems that I can cheat AB by setting:
SetTradeDelays(1,1,1,1);
This will move the closing trades to the next bar, but it will result
in a wrong reporting from the backtester, because now the "Exit Date"
for the trade is for instance no longer "day 3" in my example but "day
4". I still hope anybody has a better idea how to solve this issue ...

Best regards,
Markus

--- In amibroker@xxxxxxxxxxxxxxx, "markhoff" <markhoff@> wrote:
      
Hi folks,

I have a problem with the backtester. I have a trading system which
opens all positions on OPEN price and closes all positions CLOSE
price. Maximum number of positions is set to 1. Now, if I might have
the situation below:

Day             1          2          3          4          5
Trade #1 (A) BUY@xxxxxxxxxxxxxxxx>SELL@xxxxx
Trade #2 (B)                       BUY@xxxxxxxxxxxxxxxx>SELL@xxxxx

Trade #1 with symbol (A) has a SELL signal on day 3 and some other
symbol (B) has a BUY signal on the same day, and this causes AmiBroker
to make trade #2 also on day 3.
But, in fact this is not possible because there is no
cash available on day 3 to BUY@xxxx (because first I must SELL trade
#1). Therefore, the correct behaviour would be to start trade #2 on
day 4 after the other position for trade #1 was closed. It seems that
AB always asumes that the cash for closing positions is available at
the same bar to start new trades. Please see also the code below.

How can I force AB to consider that cash from a SELL@xxxxx is not
available on the same bar?

Thanks in advance and best regards,
Markus

//--- cut here ---
Buy = Sell = Short = Cover = False;
BuyPrice = SellPrice = ShortPrice = CoverPrice = 0;
SetOption("MaxOpenPositions", 1);
SetPositionSize(100, spsPercentOfEquity);
SetTradeDelays(1,0,1,0);
TradeDays = 3;
BuyPrice = ShortPrice = Open;
SellPrice = CoverPrice = Close;
Buy = ExRemSpan(True, TradeDays);
Sell = Ref(Buy, -TradeDays); 
//--- cut here ---

        
      
    



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

**** 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

__,_._,___