PureBytes Links
Trading Reference Links
|
I would appreciate any help that anyone could give with the code that
follows (hopefully it is formatted correctly and easy to read).
I set out to create an extremely easy system in order to see if
everything in terms of entries, exits, etc. was working as I expected
so that I could implement ideas into more complex systems.
The system:
- buy today's open if yesterday's open > yesterday's close
- short today's open if yesterday's close <= yesterday's open
- all trades will be held for 5 days and then exited on the close
I really just want to see a trade trigger, hold the position for 5
days, exit at that close, and trigger the next day if applicable.
The code below works just fine if I specify only long or only short
trades within AA.
However, if I set AA to trade both long and short trades together, I
get trade lengths of everything from 2 to 11 days vs the 5 expected
and I really don't know why.
Basically there should always be a trade on for five days, or at least
this is what I am trying to accomplish.
Any help would be very much appreciated.
jw
SetTradeDelays(0,0,0,0);
SetPositionSize( 25, spsPercentOfEquity );
BuyPrice = ShortPrice = O;
SellPrice = CoverPrice = C;
//enter long positions
Cond1= O > C;
Buy = Ref(Cond1,-1);
Sell = 0;
//enter short positions
Cond2= O <= C;
Short = Ref(Cond2,-1);
Cover = 0;
PriceAtBuy= 0;
PriceAtShort= 0;
BarsSinceBuy= 0;
BarsSinceShort= 0;
// Loop through all the bars.
for( i = 0; i < BarCount; i++ )
{
//////////////////long
if (PriceAtBuy==0 AND Buy[i]==1)
{
PriceAtBuy = BuyPrice[i];
BarsSinceBuy= BarsSinceBuy + 1;
}
else
if (PriceAtBuy > 0 AND BarsSinceBuy < 5 )
{
BarsSinceBuy= BarsSinceBuy + 1;
}
if (PriceAtBuy > 0 AND BarsSinceBuy == 5 )
{
Sell[i] = 1;
priceAtBuy = 0;
BarsSinceBuy = 0;
}
////////////////short
if (PriceAtShort==0 AND Short[i]==1)
{
PriceAtshort = ShortPrice[i];
BarsSinceShort= BarsSinceShort + 1;
}
else
if (PriceAtShort > 0 AND BarsSinceShort < 5 )
{
BarsSinceShort= BarsSinceShort + 1;
}
if (PriceAtShort > 0 AND BarsSinceShort == 5 )
{
Cover[i] = 1;
priceAtshort = 0;
BarsSinceShort = 0;
}
}
------------------------------------
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/
|