PureBytes Links
Trading Reference Links
|
Hi,
Trying to scale out of a position in my code and used the code from
one of the articles on the AB website. What is happening is that the
program does not recognize the profit targets or trailing stops that
have been set up in the code. At one point it was recognizing it,
but not correctly and when it scaled out it scaled out 100% rather
than 50%.
I've spent a few hours trying to make this work. I'd really
appreciate it if anyone could take a look at the portion of the code
in question below and let me know if they see any obvious problems.
Yes, I have defined TrailingStop and FirstProfitTarget parameters.
thx,
PriceatBuy = 0;
PriceatShort = 0;
HighSinceBuy = 0;
LowSinceShort = 0;
Exit = 0;
for( i = 0; i < BarCount; i++)
{
if(PriceAtBuy == 0 AND Buy[i])
{
PriceAtBuy = BuyPrice[i];
}
if(PriceAtBuy > 0)
{
HighSinceBuy = Max(High[i] , HighSinceBuy);
if(Exit == 0 AND High[i] >= (FirstProfitTarget +
PriceAtBuy))
{
// first profit target hit - Scale Out
Exit = 1;
Buy[i] = sigScaleOut;
SellPrice[i] = FirstProfitTarget + PriceAtBuy;
}
if(Low[i] <= (HighSinceBuy - TrailingStop))
{
// trailing stop hit - exit
Exit = 2;
SellPrice[i] = (HighSinceBuy - TrailingStop);
}
if(Exit == 2)
{
Buy[i] = 0;
Exit = 0;
PriceAtBuy = 0;
HighSinceBuy = 0;
}
}
if(PriceatShort == 0 AND Short[i])
{
PriceatShort = ShortPrice[i];
}
if(PriceatShort > 0)
{
LowSinceShort = Min(Low[i] , LowSinceShort);
if(Exit == 0 AND Low[i] <= (PriceatShort -
FirstProfitTarget))
{
// first profit target hit - Scale Out
Exit = 1;
Short[i] = sigScaleOut;
}
if(High[i] >= (LowSinceShort + TrailingStop))
{
// trailing stop hit - exit
Exit = 2;
BuyPrice[i] = (LowSinceShort + TrailingStop);
}
if(Exit == 2)
{
Short[i] = 0;
Exit = 0;
PriceatShort = 0;
LowSinceShort = 0;
}
}
}
SetPositionSize(50,spsPercentOfPosition*((Buy == sigScaleOut)+(Short
== sigScaleOut)));
//scale out of 50% of position
Please note that this group is for discussion between users only.
To get 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/
|