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

[amibroker] How signals are handled when cash is maxed out?



PureBytes Links

Trading Reference Links

I am testing a strategy on a basket of stocks. The strategy always exits n bars after entry. I 
found one interesting thing. When a buy signal is generated on a particular day on which 
previous other stock trades should be exited, the following two difference pieces of code 
will behave differently:

1. When cash is maxed out and Buy and Sell happen on the same bar,
this code will sell positions and use the proceeds to enter new positions:
BuyPrice = O;
SellPrice = O;
Buy = Ref(Condition, -1);
Buy = ExRemSpan(Buy, Delay);
Sell = Ref(Buy, -Delay);

2. When cash is maxed out and Buy and Sell happen on the same bar,
this code will sell positions and skip the new positions:
BuyPrice = O;
SellPrice = O;
Buy = Ref(Condition, -1);
Buy = ExRemSpan(Buy, Delay);
Sell = 0;

priceatbuy = 0;
for(i = 0; i < BarCount; i++) {
	if (priceatbuy == 0 AND Buy[i]) {
		priceatbuy = BuyPrice[i];
	}
	if (priceatbuy > 0 AND Buy[i - Delay]) {
		SellPrice[i] = O[i];
		Sell[i] = 5; // n-bar exit code
		priceatbuy = 0;
	}
}

Changing the BuyPrice and/or SellPrice to Open or Close does not change the behavior. 
Does anyone know how to make code 2 behave the same as code 1? I have to use the for 
loop approach for scaling out.

Thanks in advanced,


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

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

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

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

For other support material please check also:
http://www.amibroker.com/support.html

*********************************
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:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto: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/