<< SquareOfNine code removed due to issues reported by EZ >>
The attached indicator was written for my own trading, there are several places where it can be improved, but for my use it is fine. If it suits your needs, then I'm glad to have helped. If it just does not work for you then you have some base code to work with
Square Nine is a mathematical progression of numbers produced by incrementing each value by a step size (usually 1) in a spiral fashion, with a "seed" number in the center of the spiral.
From what I gather in reading articles on the net, this technique was intended by Gann to be based off of a recent Swing Hi/Lo, where the price at that Swing would be the "seed" value for the center of the Spiral.
Well, I did not program it that way. My exposure to Square of 9, came from Gio at tradingelements.com. Her use of Square of 9, always used a seed value of 0.
When used in this way an issues arises.
For Instruments that trade with small whole number values, like the Euro, and other currencies, and a lot of stocks, the SQ9 values, calculated as above, are too far apart to be of practical use in trading.
to compensate for this, a power of 10 factor must be used to shift the values outward in the spiral, to arrive at SQ9 values that are more meaningful for trading. I call these synthetic Square of 9. I can find no reference in Gann material supporting this, it is just the way I learned it.
The input parameter ScaleOffset is provided to allow this shifting for Synthetic Squares, Set to 0 to use internally assigned values for ScaleOffset.
When transitioning to the next level of the spiral , one gets a large jump in value, from (level n, angle 270), to (level n+1, angle 0). To avoid this jump the increase between levels is evenly distributed on angles between 270 and 0/360, thereby creating a smoother transition.
This indicator calculates the Major Squares at (0,90,180,270 degrees) and plots them with a Blue dashed line, it also calculates the minor Squares at angles divisible by 22.5 degrees, plotting them as magenta lines
The indicator finds a SQ9 value which is close to the Symbol value being charted. It then plots 15 SQ9 lines below, and 15 lines above that value. It uses lines because they are not included in the chart scaling calculations, so that lines not close to price do not skew the displayed chart. It repeats this at the beginning or each new trading day, which works well for what I trade. (Stock Index)
Using this on daily charts, will produce odd looking charts.
As price advances about half way to the next SQ9 value, the chart's "white space" is adjusted to bring the next SQ9 line onto the chart, this allows using Chart Trader to place/move target orders around the SQ if so desired.

Comment