Login Page - Create Account

Technical Studies Reference


Square of 9

This study calculates and displays Gann's Square of 9 indicator.

If you find that your price graph is getting compressed by the Square of 9 lines, then set the Scale Range Type in the Scale settings for this study to Same As Region.

Let the Inputs Number of Days to Calculate, Anchor Value, Degrees, Level, and Price Multiplier be denotes as \(D\), \(a\), \(\theta\), \(l\), and \(v\), respectively. These Inputs are subject to the following restrictions.

  • If the Price Multiplier is set to \(0\), then it is automatically reset to \(1\).
  • Suppose there are \(N\) bars in the chart. If the Anchor Value is set to \(0\), then it is automatically reset to \(v \cdot C_{N - 1}\), which is the Price Multiplier times the Close Price at Index \(t = N - 1\).

The Square of 9 study calculates four Subgraphs. We denote their values at Index \(t\) as \(A_t(a,v)\), \(L1^{(+)}_t(a,\theta,l,v)\), \(L1^{(-)}_t(a,\theta,l,v)\), and \(L1_t(a,\theta,v)\). These Subgraphs are displayed as horizontal line segments over the last \(D\) days of the chart, with levels determined by the values of the Subgraphs at the most recent Index \(t\).

If the Auto Adjust Input is set to No, then these Subgraphs are calculated as follows.

\(\displaystyle{A_t(a,v) = \frac{a}{v}}\)
\(\displaystyle{L1^{(+)}_t(a,\theta,l,v) = \frac{\left(\sqrt{a} + \theta\cdot\left\lfloor l + 0.5 \right\rfloor/180^{\circ}\right)^2}{v}}\)
\(\displaystyle{L1_t(a,\theta,v) = 0}\)
\(\displaystyle{L1^{(-)}_t(a,\theta,l,v) = \frac{\left(\sqrt{a} - \theta\cdot\left\lfloor l + 0.5 \right\rfloor/180^{\circ}\right)^2}{v}}\)

For an explanation of the floor function (\(\left\lfloor{\space\space}\right\rfloor\)), refer to our description here.

If the Auto Adjust Input is set to Yes, then these Subgraphs are calculated using a more complicated set of rules, which we describe below.

We begin by defining six functions that are used in intermediate calculations.

  • Base Upper: \(BU_t(a,\theta)\)
  • Base Lower: \(BL_t(a,\theta)\)
  • Upper: \(U_t(a, \theta, l)\)
  • Mid: \(M_t(a, \theta, l, v)\)
  • Lower: \(L_t(a, \theta, l)\)
  • Offset: \(k_t(\theta)\)

These functions are initialized as follows at \(t = 0\).

\(\displaystyle{BU_t(a,\theta) = \left(\sqrt{a} + \frac{\theta}{180^{\circ}}\right)^2}\)
\(\displaystyle{BL_t(a,\theta) = \left(\sqrt{a} - \frac{\theta}{180^{\circ}}\right)^2}\)
\(\displaystyle{U_t(a, \theta, l) = \left(\sqrt{a} + \left\lfloor l + 0.5 \right\rfloor\cdot\frac{\theta}{180^{\circ}}\right)^2}\)
\(\displaystyle{M_t(a, \theta, l, v) = a}\)
\(\displaystyle{L_t(a, \theta, l) = \left(\sqrt{a} - \left\lfloor l + 0.5 \right\rfloor\cdot\frac{\theta}{180^{\circ}}\right)^2}\)

For \(t > 0\), we begin by setting the values of the six functions as follows.

\(BU_t(a,\theta) = BU_{t - 1}(a,\theta)\)
\(BL_t(a,\theta) = BL_{t - 1}(a,\theta)\)
\(U_t(a, \theta, l) = v \cdot L1^{(+)}_t(a, \theta, l, v)\)
\(M_t(a, \theta, l, v) = v \cdot L1_{t - 1}(a,\theta,v)\)
\(L_t(a, \theta, l) = v \cdot L1^{(-)}_t(a, \theta, l, v)\)
\(k_t(\theta) = k_{t - 1}(\theta)\)

Once these values are set, the Auto Adjustments are made via a sequence of two while loops, described below.

while\((vC_t > BU_t(a,\theta))\):

  • \(k_t(\theta) = k_t(\theta) + \theta\)
  • \(BU_t(a,\theta) = \left(\sqrt{a} + (k_t(\theta) + \theta)/180^{\circ}\right)^2\)
  • \(BL_t(a,\theta) = \left(\sqrt{a} + (k_t(\theta) - \theta)/180^{\circ}\right)^2\)
  • \(U_t(a, \theta, l) = \left(\sqrt{a} + (k_t(\theta) + \lfloor l + 0.5 \rfloor\cdot\theta)/180^{\circ}\right)^2\)
  • \(M_t(a, \theta, l, v) = \left(\sqrt{a} + k_t(\theta)/180^{\circ}\right)^2\)
  • \(L_t(a, \theta, l) = \left(\sqrt{a} + (k_t(\theta) - \lfloor l + 0.5 \rfloor\cdot\theta)/180^{\circ}\right)^2\)

while\((vC_t < BL_t(a,\theta))\):

  • \(k_t(\theta) = k_t(\theta) - \theta\)
  • \(BU_t(a,\theta) = \left(\sqrt{a} + (k_t(\theta) + \theta)/180^{\circ}\right)^2\)
  • \(BL_t(a,\theta) = \left(\sqrt{a} + (k_t(\theta) - \theta)/180^{\circ}\right)^2\)
  • \(U_t(a, \theta, l) = \left(\sqrt{a} + (k_t(\theta) + \lfloor l + 0.5 \rfloor\cdot\theta)/180^{\circ}\right)^2\)
  • \(M_t(a, \theta, l, v) = \left(\sqrt{a} + k_t(\theta)/180^{\circ}\right)^2\)
  • \(L_t(a, \theta, l) = \left(\sqrt{a} + (k_t(\theta) - \lfloor l + 0.5 \rfloor\cdot\theta)/180^{\circ}\right)^2\)

Upon completion of these two while loops, the four Subgraphs are computed as follows.

\(\displaystyle{A_t(a,v) = \frac{a}{v}}\)
\(\displaystyle{L1^{(+)}_t(a,\theta,l,v) = \frac{U_t(a, \theta, l)}{v}}\)
\(\displaystyle{L1_t(a,\theta,v) = \frac{M_t(a, \theta, l, v)}{v}}\)
\(\displaystyle{L1^{(-)}_t(a,\theta,l,v) = \frac{L_t(a, \theta, l)}{v}}\)

Inputs

  • Number of Days to Calculate: This sets the number of days over which the horizontal lines from the study Subgraphs are to be drawn.
  • Anchor Value: The user designated starting level for the calculations. This is usually a significant high or low in the chart.
  • Degrees: The degrees that you wish to use for the calculations.
  • Level: The degrees level for the lines. For example, if Degrees is set to 22.5 and the Level is set to 1, then lines are drawn at positive and negative 45 degrees from the Anchor Value. If Degrees is set to 22.5 and the Level is set to 2, then the lines are drawn at positive and negative 90 degrees from the Anchor Value. And so on.
  • Auto Adjust: This determines the calculation scheme for the study Subgraphs.
  • Price Multiplier

Spreadsheet

The spreadsheet below contains the formulas for this study in Spreadsheet format. Save this Spreadsheet to the Data Files Folder.

Open it through File >> Open Spreadsheet.

Square_Of_9.111.scss


*Last modified Wednesday, 11th March, 2020.