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

average true range for spread



PureBytes Links

Trading Reference Links

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[barsBack+1]));
	
spreadRange2=absValue(absValue(hSpread[barsBack+2])-absValue(lSpread[barsBack+2]));
	
spreadRange3=absValue(absValue(hSpread[barsBack+3])-absValue(lSpread[barsBack3]));
	
spreadRange4=absValue(absValue(hSpread[barsBack+4])-absValue(lSpread[barsBack+4]));
	
spreadRange5=absValue(absValue(hSpread[barsBack+5])-absValue(lSpread[barsBack+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