----- Original Message -----
Sent: Thursday, September 29, 2005 10:55
AM
Subject: RE: [amibroker] Bitten the
bullet on loops
Hi,
Steve .... look's good. I really like loops
and inlude files.
Added some detail to get worst case intraday
slippage numbers.
The
following example does not account for daily gaps, not an issue
with
intraday stuff, but should be added.
It's also meant
for LMT orders on Buy/Short and MKT orders on
Sell/Cover.
I like putting repetitive code in include
files,
just another
example;
--jeff
//========================= Main Program
=========================
Stopprofit=0.0030;
Stoploss=0.0015; //1.2
BuyCond =
SellCond =
ShortCond =
CoverCond =
#include
"C:\Program
Files\AmiBroker\Formulas\Include\BuySell.afl"
//========================= End Main Program
=========================
// include the
following in file: buysell.afl
//=begin= "C:\Program
Files\AmiBroker\Formulas\Include\BuySell.afl"===
Buy=Sell=Short=Cover=isLong=isShort=0; //initialize
for( i = 1; i < BarCount; i++ )
{
if (NOT isLong AND BuyCond [i])
{
if (isShort)
{
Cover[i]=1;
CoverPrice[i]= Open[i]+TickSize; //MKT
Order
isShort=0;
}
Buy[i]=1;
BuyPrice[i]=Open[i]; //LMT
Order
TargetPr = BuyPrice[i] + Stopprofit;
StopLossPr = BuyPrice[i] - StopLoss;
isLong=1;
}
if (NOT isShort AND ShortCond [i] )
{
if (isLong)
{
Sell[i]=1;
SellPrice[i]= Open[i]-TickSize; //MKT
Order
isLong=0;
}
Short[i]=1;
ShortPrice[i]=Open[i]; //LMT
Order
TargetPr = ShortPrice[i] - Stopprofit;
StopLossPr = ShortPrice[i] + StopLoss;
isShort=1;
}
if (isLong)
{
//
exit
if (SellCond [i] )
{
Sell[i]=1;
SellPrice[i]= Open[i]-TickSize; //MKT
Order
isLong=0;
}
// Stop
Loss
else if( Low[i] <= StopLossPr
AND StopLoss >
0)
{
Sell[i]=1;
SellPrice[i]= StopLossPr -
TickSize; // add sell at open, if
gap, below target
isLong=0;
}
// Profit
Target
else if( High[i] >= TargetPr
AND Stopprofit
> 0)
{
Sell[i]=1;
SellPrice[i]=
TargetPr-TickSize; // add sell at open, if
gap, above target
isLong=0;
}
}
if (isShort)
{
//
exit
if (CoverCond [i] )
{
Cover[i]=1;
CoverPrice[i]= Open[i]+TickSize; //MKT
Order
isShort=0;
}
// Stop
Loss
else if( High[i] >= StopLossPr
AND StopLoss >
0)
{
Cover[i]=1;
CoverPrice[i]= StopLossPr +
TickSize; // add sell at open, if
gap, below target
isShort=0;
}
// Profit
Target
else if( Low[i] <= TargetPr
AND Stopprofit
> 0)
{
Cover[i]=1;
CoverPrice[i]= TargetPr +
TickSize; // add sell at open, if
gap, above target
isShort=0;
}
}
}
Equity(1); // To
remove redundant signals
//=========== end of BuySell.afl =============================
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 other support material please check also:
http://www.amibroker.com/support.html
YAHOO! GROUPS LINKS