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

Re: average true range for spread



PureBytes Links

Trading Reference Links

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<lSpread then lSpread = 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<lSpread then lSpread = 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