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

Fwd: Re: ATR for spread [with correction]



PureBytes Links

Trading Reference Links


Thanks for the feedback Lee. 
 
First let me take a step back. I use intraday (5min)
data to collect all my high and low for the spread
during the day data. I collect the high and low for
the spread by always using the closing price(close-
close) of each stock and trapping the highest spread
high and lowest spread low. Then at the end of the day
I wish to register four things, but the first two are
especially important. 
1. The high of the spread for the day.(intraday traps)
2. The low of the spread for the day.
3. The close of the spread for the day. (closeD
data1-closeD data2)
4. The open of the spread for the day, when both
stocks are open, not the opening price of both stocks
(perhaps off volume...).
 
>From here with these 2-4 data points I want to put
them into an array/function and convert the intraday
collection to an end of day average true range for
twenty days calculation. (I like to know when a spread
has traveled more than 100% atr20, if open is extreme
%...)
 
With my, I call them traps, trap code, I don't know
how to populate an array. Functions seems to be the
way to go, it would be a piece of cake if there was a
highD for a spread. 
 
It seems like each day the functions you submitted
would need to clear themselves each morning and
store the data at the end of the day for reference
purposes. 
 
Sorry if I am way off base. I hope what I am saying
makes sense.
 
Can your code achieve this? 
 
Thanks again.
Doug
 
Lee Goldberg <best-revenge@xxxxxxx> wrote:
Sorry. The indicator needs the function inputs so it
is

SprdTR = average(SprdTrueRange(Adj1,Adj2) ,N);

*******************************************************
Hi Doug,

I took the easy way out (maybe the wrong way out?) and
made 3 user 
functions like so:

{SpreadTrueHigh user function}
Inputs: Adj1(numeric), Adj2(numeric) ;
Vars: SprdC(0), SprdH(0) ;

SprdC = (C data1)*Adj1 - (C data2)*Adj2 ;
SprdH = (H data1)*Adj1 - (H data2)*Adj2 ;

If SprdC[1] > SprdH Then
SprdTrueHigh = SprdC[1]
Else
SprdTrueHigh = SprdH ;
*********************************************************
{SpreadTrueLow user function}
Inputs: Adj1(numeric), Adj2(numeric) ;
Vars: SprdC(0), SprdL(0) ;

SprdC = (C data1)*Adj1 - (C data2)*Adj2 ;
SprdL = (L data1)*Adj1 - (L data2)*Adj2 ;

If SprdC[1] < SprdL Then
SprdTrueLow = SprdC[1]
Else
SprdTrueLow = SprdL ;
****************************************************
{SpreadTrueRange user function}
Inputs: Adj1(numeric), Adj2(numeric);

SprdTrueRange =
SprdTrueHigh(Adj1,Adj2)-SprdTrueLow(Adj1,Adj2) ;
**********************************************************
Then you can do something like

SprdTR = average(SprdTrueRange,N) ;

Regards,
Lee

At 10:55 AM 6/29/2004 -0700, you wrote:
>Hello all,
>
>I am a spread trader of stock pairs. I am trying to
>create some tradestation code for average true range
>of a spread relationship.
>
>Below is my attempt, but it is flawed, and gets even
>more flawed when 1/2 days are in the mix.
>
>What I wish to do is create an array and during the
>day capture the high of the spread on say a 5 min
>basis, and the low of the spread on a 5 min basis, as
>well as the close. The close should be no problem.
>
>What I want to do is mimic the highD, lowD function,
>for a spread relationship, and be able to call back
20
>days of data. I know how to capture the hi and low,
>see below, for the day, but I don't know how to
>successively store those values in an array.
>
>Can anyone help me adapt this code into a more stable
>and dynamic array format?
>
>inputs: spreadMultiple(1) , rangePct(1),
>timeBack(390);
>variables: hSpread(0), lSpread(0), spreadRange(0),
>spreadRange2(0), spreadRange3(0), spreadRange4(0),
>spreadRange5(0), avgRange5(0), spread(0), barsBack(0)
>;
>
>spread=(close data1*spreadMultiple) - close data2;
>
>if date<>date[1] then
>begin
> hSpread=-999999;
> lSpread=999999;
>
>if barInterval<>0 then barsBack =
>timeBack/barInterval;
>
>if currentBar>500 then
>begin
>
>spreadRange=absValue(absValue(hSpread[barsBack+1])-absValue(lSpread[barsBac

> k+1]));
>
>spreadRange2=absValue(absValue(hSpread[barsBack+2])-absValue(lSpread[barsBa

> ck+2]));
>
>spreadRange3=absValue(absValue(hSpread[barsBack+3])-absValue(lSpread[barsBa

> ck3]));
>
>spreadRange4=absValue(absValue(hSpread[barsBack+4])-absValue(lSpread[barsBa

> ck+4]));
>
>spreadRange5=absValue(absValue(hSpread[barsBack+5])-absValue(lSpread[barsBa

> ck+5]));
>
>avgRange5=spreadRange+spreadRange2+spreadRange3+spreadRange4+spreadRange5)/5;
>end;
>
>if spread>hSpread then hSpread=spread;
>
>if spread>
>if currentBar>300 then
>begin
> value1=hSpread-(avgRange5*rangePct);
> value2=lSpread+(avgRange5*rangePct);
>
> plot1(spread,"spread",magenta);
> plot2(value1,"ar-",green );
> plot3(value2,"ar+",green );
>end;
>
>Thanks,
>Doug



At 10:55 AM 6/29/2004 -0700, Doug Johnson wrote:
>Hello all,
>
>I am a spread trader of stock pairs. I am trying to
>create some tradestation code for average true range
>of a spread relationship.
>
>Below is my attempt, but it is flawed, and gets even
>more flawed when 1/2 days are in the mix.
>
>What I wish to do is create an array and during the
>day capture the high of the spread on say a 5 min
>basis, and the low of the spread on a 5 min basis, as
>well as the close. The close should be no problem.
>
>What I want to do is mimic the highD, lowD function,
>for a spread relationship, and be able to call back
20
>days of data. I know how to capture the hi and low,
>see below, for the day, but I don't know how to
>successively store those values in an array.
>
>Can anyone help me adapt this code into a more stable
>and dynamic array format?
>
>inputs: spreadMultiple(1) , rangePct(1),
>timeBack(390);
>variables: hSpread(0), lSpread(0), spreadRange(0),
>spreadRange2(0), spreadRange3(0), spreadRange4(0),
>spreadRange5(0), avgRange5(0), spread(0), barsBack(0)
>;
>
>spread=(close data1*spreadMultiple) - close data2;
>
>if date<>date[1] then
>begin
> hSpread=-999999;
> lSpread=999999;
>
>if barInterval<>0 then barsBack =
>timeBack/barInterval;
>
>if currentBar>500 then
>begin
>
>spreadRange=absValue(absValue(hSpread[barsBack+1])-absValue(lSpread[barsBac

> k+1]));
>
>spreadRange2=absValue(absValue(hSpread[barsBack+2])-absValue(lSpread[barsBa

> ck+2]));
>
>spreadRange3=absValue(absValue(hSpread[barsBack+3])-absValue(lSpread[barsBa

> ck3]));
>
>spreadRange4=absValue(absValue(hSpread[barsBack+4])-absValue(lSpread[barsBa

> ck+4]));
>
>spreadRange5=absValue(absValue(hSpread[barsBack+5])-absValue(lSpread[barsBa

> ck+5]));
>
>avgRange5=spreadRange+spreadRange2+spreadRange3+spreadRange4+spreadRange5)/5;
>end;
>
>if spread>hSpread then hSpread=spread;
>
>if spread>
>if currentBar>300 then
>begin
> value1=hSpread-(avgRange5*rangePct);
> value2=lSpread+(avgRange5*rangePct);
>
> plot1(spread,"spread",magenta);
> plot2(value1,"ar-",green );
> plot3(value2,"ar+",green );
>end;
>
>Thanks,
>Doug