PureBytes Links
Trading Reference Links
|
This has be posted on the code-list and I hesitate to post it here due
to the size (what are your thougths on this?). But since this list is
where the original query came from, I will try to post it. The gifs will
be sent separately since they are too large (10K) to sent with this
post. Can someone tell us how to get a gif into a base64 format?
On Fri, 19 May 2000 12:25:10 -0400 Dirk de Vos wrote:
> Anyone know how to apply an indicator to a spread (TS4)? The problem
is
>that a spread is an "indicator" - not considered data 3 - hence no
other
> indicators plot on the "spread." Funny, as it's very easy to do in
QCharts.
On Fri, 19 May 2000 14:19:09 EDT Howard answered....
>Import the data to data downloader. Create the spread there. Then chart
> the spread in TS and you can apply indicators to it.
For EOD this is probably the best solution. But it does not work for
minute or tick charts. It is possible to place an indicator on a spread
in a minute chart according to the following.
The method follows my scheme for applying one indicator onto another
indicator as outlined in this list (and Mark Browns’ code-list) on 3
Sept, 1999. As pointed out there, the data stream from indicator1 is
used as a feed into indicator2 and thus indicator2 is applied to (on)
indicator1. An indicator on an indicator may seem like a straight
forward procedure. But even for a simple one, such as
Average(spread(c,len),length), there are subtle scaling factors that
must be considered.
Scaling relates to how the indicator plot looks in a chart, not to the
correctness of the numerical results (as seen in the data window) of a
calculation using that indicator. Scaling set to either "Screen" or
"Same as symbol" gives the same numerical answer but often a different
looking plot on the chart. (See the gif below for the moving average of
a spread). "Same as symbol" does not necessarily relate to the symbol
value. It only means, scale ever plot in the same subgraph to the same
scale, whatever is dictated by the highest and lowest values of the
various plots in that subgraph. I have found that for indicators on
indicators, scaling needs to be set to "Same as symbol" to give correct
looking results on the chart.
A spread (indicator1) does not need to be plotted to see the effects of
indicator2 on it. If you want to see the spread with indicator2 overlaid
on it, then of course, it must be plotted. The data output from the
spread (e.g., Close of data1 - Close of data2) is used as the input to
indicator2.
Create the spread (indicator1) between two symbols. Set the following
for the spread:
scaling to "Same as symbol" and
under the Properties sheet "Base study on:" (use the symbol in
subgraph2 even if using subgraph3 for the indicator) and "Subgraph:"
(two or three).
When applying some indicators (indicator2), in order for the plot to
appear at all, the spread must be put into subgraph2 with the price
data. Plotting in subgraph2 usually requires scaling the indicators to
the price data, in order to get the indicators to show properly. For
most indicators, subgraph3 can be used, when there is not a problem to
get indicator2 to appear. (You can tell if subgraph3 can not be used as
no plot of indicator2 will appear. Apply trial and error). If indicator2
can be put in subgraph3, that is the preferred setup as a scaling factor
is not needed to accommodate the symbol data. If using subgraph3, still
set all scaling to "Same as symbol" for any plots there.
The scaling of the indicators in subgraph2 may be set by applying a
factor to the inputs. After plotting the spread, look at the two graphs
(spread and symbol) in subgraph2 and estimate the factor difference
between them. E.g., if the symbol is at 106 and the spread is at 20 then
the factor is about 5.2. If the spread is X-Y the inputs, "close of
data1 and close of data2", in the "Format indicator:" box, must both be
multiplied by 5.2. Just add 5.2* in each of the "Edit input" boxes. If
the spread is X /Y then multiply only "close of data1". Close the
boxes. Now the spread and the symbol should be at about the same level.
(Actually, the scaling can be set with "User defined" but when
scrolling, the plot can go off the chart). If subgraph2 is used and the
two spread symbols diverge greatly from each other over the duration of
the charted minute data, the indicator plots may get too small or too
large. If so, the autoscaling code below can be used to keep the plots
using the majority of the minute chart as one day passes into the next
day.
The input (Price) for indicator2 that you want to apply to the spread
is the output from the spread, that is, X-Y or X/Y. (The same scaling as
used for the spread, will need to be added to indicator2 if it is in
subgraph2). Some indicators, such as Mov Avg 1 line, allow a change in
Price from the chart using the "Edit input" box. For those, enter X-Y or
X/Y at the "Edit input" in the chart. E.g., with Mov Avg 1 line replace
close with 5.2*(close of data1 - close of data2). (I think there is a
mistake in the indicators Mov Avg 1, 2, 3 line. The AverageFC is used
but it should be just Average. AverageFC is series and Average is simple
but the name given is "SimpAvg". Also, AverageFC does not work in the
example I give below.)
For indicators that do not allow a change of Price in the chart, you
must open indicator2 in the PowerEditor and add the spread output (X-Y
or X/Y) to the location where the Price data goes. E.g., in MACD it is
in plot1 and plot2 in the indicator itself. You may want to change the
code in some indicators or functions (adding Price(Close)) to allow the
Price change from the chart as I have done for the Linear Regression
Line that I posted on Mark Brown,s code-list, Sat, 27 May 2000 16:14.
The gif below is an X-Y spread at 5 minute intervals for HWP and IBM
with a Mov Avg 1 line and a Linear Regression Line (which must be in
subgraph2 to work). The Linear Regression Line code is that which I
posted on Mark Brown’s code-list (Price can be entered from the chart).
The symbol data showing in subgraph2 can be hidden by using: Style,
"Invisible bars".
To autoscale indicator1 and indicator2 the following code can be
included with both indicator1 and indicator2. (It is best to replicate
these indicators in a new window and add the new code there, thus
preserving the original code). The example is for a moving average on a
spread (these two can be put in subgraph3 and not need any scaling
factor but they are used here as a simple example). The first days worth
of data is used in the chart to properly align the indicators. Lengths
must be less than 1 days worth of bars if the autoscaling code is used.
PerDay("Yes") resets the value every day.
In the LRL the autoscaling code goes immediately after the Variables
part in the function (not the indicator).
{for the spread add}
Inputs: PerDay("Yes"), Price(c of data1-c of data2), Input1(Close of
data1), Input2(Close of data2);;
Var: Y(0);
{...........autoscaling code...........}
if PerDay="Yes" then begin
if D<>D[1] then
if AbsValue(Price)<>0 then
y= c of data2/AbsValue(Price) ;
end else if D<>D[1] and y=0 then begin
if AbsValue(Price)<>0 then
y= c of data2/AbsValue(Price);
end;
{............................................}
Plot1(Y*(Input1 - Input2), "SpreadDiff");
////////////////////////////////////
{for the moving average add}
input: PerDay("Yes"), Price(c of data1-c of data2);
var: Y(0), len(9);
{.................................}
if PerDay="Yes" then begin
if D<>D[1] then
if AbsValue(Price)<>0 then
y= c of data2/AbsValue(Price) ;
end else if D<>D[1] and y=0 then begin
if AbsValue(Price)<>0 then
y= c of data2/AbsValue(Price);
end; {...................................}
Plot1(Average(Y*(c of data1-c of data2), Len), "SimpAvg1");
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
The gifs are each sent separately as they will not fit with this post.
Wayne Mathews
|