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

The Equation of a Study



PureBytes Links

Trading Reference Links


You may have the equation of a Study, drawn by 
hand and use
it as a new function for crossovers or anything 
else.
First draw the line.
Then right click on the line, select properties 
and, suppose
you read
Start X :2/8/2001
Start Y :11.88
End X :8/10/2001
End Y :10.06
Add to your code the following lines
 <FONT 
face=Courier>
x=Cum(1);<FONT 
color=#ffff00>
x1=LastValue(ValueWhen(DateNum()==1010802,x,1));<FONT 
color=#ffff00>
y1=11.88;<FONT 
color=#ffff00>
x2=LastValue(ValueWhen(DateNum()==1011008,x,1));<FONT 
color=#ffff00>
y2=10.06;
<FONT color=#ffff00 face=Courier 
size=2>f1=y2+(y2-y1)*(x-x2)/(x2-x1);<FONT 
color=#ffff00>
Graph0=IIf(x>=x1 AND 
x<=LastValue(Cum(1)),f1,-1e10);
 
f1 is now the equation of your trendline, 
extended up to the last 
day of your data.
Comments
1. If you want to see just what you havedrawn by 
hand, change the 
last line to
 
Graph0=IIf(x>=x1 AND 
x<=x2,f1,-1e10);<FONT 
color=#000000>
2. Any parallel to f1 will come from the general 
formula
<FONT face=Courier 
size=2> 
Graph1=IIf(x>=x1 AND 
x<=LastValue(Cum(1)),f1+D,-1e10);
 
where D may be positive or negative number.
3. Use f1 like a function in any formula or relation, such as
cross(f1,H) or C<=f1 etc.
 
Dimitris 
Tsokakis