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

Re: SAR


  • To: "Keith Bennett" <kbennett@xxxx>
  • Subject: Re: SAR
  • From: "Dima Rasnitsyn" <rasnitsyn@xxxx>
  • Date: 17 Nov 2001 21:00:36 -0000
  • In-reply-to: <001001c16eb5$066edfb0$e7479ec2@xxxx>

PureBytes Links

Trading Reference Links


Keith,
 
the problem is that SAR() does not accept the 
arrays of "High" and "Low" (I do not remember wheter SAR is using "Close"),i.e. 
it internaly uses array of closing price for the currently selected 
security.
 
To work around this you need to re-assign "close" 
to to to some temporary array:
 
Replace

Cl=<FONT 
color=#0000ff>Foreign("^tmti",<FONT 
color=#ff00ff>"C");
s = SAR (accel, 
maxS); 
by
qqqClose = close;
qqqHigh = High;
qqqLow = Low;
Cl=<FONT 
color=#0000ff>Foreign("^tmti",<FONT 
color=#ff00ff>"C");
Hg = Foreign ("^tmti", "H");
Lo = Foreign ("^tmti", "L");
C=close = Cl;  // I'm not sure whether C should be reassigned as well. 

                      
// Probably close = Cl; is enough
H = High = Hg;
L = Low = Lo;
s = <FONT face=Arial 
color=#0000ff>SAR (accel, maxS); 
C=close = qqqClose; // restore original values
H = High = qqqHigh;
L = Low = qqqLow;
 
Regards,
Dima.
 
PS. I CC my response to AmiBroker group so 
Tomasz/Dimitris or other AFL gurus can correct me if I'm wrong.
 
<BLOCKQUOTE dir=ltr 
>
----- Original Message ----- 
<DIV 
>From: 
Keith 
Bennett 
To: <A title=rasnitsyn@xxxx 
href="">Dima Rasnitsyn 
Sent: Friday, November 16, 2001 10:38 
AM
Subject: SAR

Dima,
 
Thank you for your helpful fax which hasenabled 
me to make progress. I would appreciate it if you could find the time to check 
my code, which I think may contain a logical error.
 
Explanation:
I am using a custom index (^TMTI) to track the 
market.  Go LONG when the Index Closing Price is above theSAR. 
 Go SHORT when the Index Closing Price is below the 
SAR.  Additionally, before going LONG the Index must be 
above a fixed level, and before going SHORT the Index must be below a fixed 
level. This section of code is running correctly, and if I set Automatic 
Analysis - Current Stock to ^TMTI, I get an acceptable listing of Entry 
and Exit dates. (See Below).
 
Objective:
I want to use these ^TMTI/SAR signals totime my 
market entry and exit using other tickers - for example QQQ.
When the TMTI Index Closing Price is above the 
SAR, AND the Closing Price is higher than the set level, I go long QQQ. When 
the TMTI Index Closing Price is below the SAR, AND the Closing Price is lower 
than the set level, I go short QQQ.
 
When I set Automatic Analysis - Current Stock to 
QQQ, no trades are selected. Is there an error in my code, in my logic, or am 
I trying to do something which is not possible with AFL ?  I have noticed 
that if I remove LoLimit and HiLimit from BuyBreak and SellBreak, I can get a 
list of trades, but of course they are not acceptable.
 
I have done something similar to the above using 
EMA crossovers instead of SAR, and everything worked just fine. I can't 
understand why this does not and would appreciate your help.
 
Keith
 
//Index tracker//

Cl=<FONT 
color=#0000ff>Foreign("^tmti",<FONT 
color=#ff00ff>"C");
accel=<FONT face=Arial 
color=#ff00ff>0.06;
accel=<FONT face=Arial 
color=#0000ff>LastValue(accel);
accel=<FONT 
color=#0000ff>Optimize("accel",accel,<FONT 
color=#ff00ff>0.01,0.2,<FONT 
color=#ff00ff>0.01);
maxS =<FONT face=Arial 
color=#ff00ff>0.5;
maxS =<FONT face=Arial 
color=#0000ff>LastValue(maxS);
maxS = <FONT 
color=#0000ff>Optimize ("Max", maxS, <FONT 
color=#ff00ff>0.1, 0.6, <FONT 
color=#ff00ff>0.1);
s = <FONT face=Arial 
color=#0000ff>SAR (accel, maxS); 
signalPrice = <FONT 
color=#0000ff>Ref (s, -1<FONT 
face=Arial>);
LoLimit=<FONT face=Arial 
color=#ff00ff>7;
LoLimit=<FONT face=Arial 
color=#0000ff>LastValue(LoLimit);
LoLimit=<FONT 
color=#0000ff>Optimize(<FONT 
color=#ff00ff>"LoLimit",LoLimit,2,<FONT 
color=#ff00ff>7,0.5<FONT 
face=Arial>);
HiLimit=<FONT face=Arial 
color=#ff00ff>15;
HiLimit=<FONT 
color=#0000ff>LastValue(HiLimit);
HiLimit=<FONT 
color=#0000ff>Optimize(<FONT 
color=#ff00ff>"HiLimit",HiLimit,8,<FONT 
color=#ff00ff>15,0.5<FONT 
face=Arial>);
BuyBreak = Cl > signalPrice AND 
Cl < LoLimit; 

SellBreak = Cl < signalPrice AND 
Cl > <FONT 
face=Arial>HiLimit;
Buy= 
BuyBreak;
Sell 
=SellBreak;
Buy = 
ExRem 
(Buy, Sell);
Sell = 
ExRem 
(Sell,Buy);
Short<FONT face=Arial 
size=2>=Sell;
Cover<FONT face=Arial 
size=2>=Buy;
 




Trade list for ^TMTI 

Trade
Entry date
Exit date



Out
1/2/1998
3/5/1998



Short
3/5/1998
6/17/1998



Long
6/17/1998
7/8/1998



Short
7/8/1998
8/7/1998



Long
8/7/1998
11/9/1998



Short
11/9/1998
2/24/1999



Long
2/24/1999
5/3/1999



Short
5/3/1999
8/11/1999



Long
8/11/1999
11/22/1999



Short
11/22/1999
4/11/2000



Long
4/11/2000
7/18/2000



Short
7/18/2000
10/17/2000



Long
10/17/2000
2/7/2001



Short
2/7/2001
3/28/2001



Long
3/28/2001
5/11/2001



Short
5/11/2001
9/25/2001



Open Long
9/25/2001
11/12/2001

<FONT face=Arial 
size=2>