Square of Nine

Download script
Author: Copyright � 2006, Matt Trigwell
Square of Nine

The Square of Nine indicator is a specialized visual tool designed for traders who utilize geometric price action theories. It automatically projects specific price levels onto your trading chart based on a mathematical concept where the square roots of numbers are used to identify potential zones of interest.

Core Functionality

The script simplifies the complex manual calculations required to plot "Square of Nine" levels. Instead of you having to calculate these figures yourself, the indicator takes a starting price point provided by the user and automatically generates a series of horizontal dashed lines across the chart. These lines represent projected price milestones based on incremental mathematical shifts.

How the Logic Works

The script follows a systematic three-step process to organize your chart:

1. Input Configuration You can define three primary parameters to customize how the levels appear:

  • Start Price: The base number from which all calculations begin.
  • Direction: You can choose whether the levels should project upward (addition) or downward (subtraction).
  • Color: You can choose the visual style of the lines to ensure they are easily visible against your chosen background.

2. Dynamic Calculation Engine The indicator performs several automated "behind-the-scenes" steps to ensure accuracy across different types of assets:

  • Currency Adjustment: It detects if you are trading a JPY (Japanese Yen) pair or a standard currency. It automatically scales the price data (by 100 or 10,000 units) to ensure the square root math remains accurate for those specific markets.
  • Square Root Math: The script takes the square root of your starting price, applies a specific growth factor, and then squares the result again to find the new price level.
  • Incremental Scaling: It calculates a sequence of levels by increasing the factor systematically, ensuring a consistent distribution of lines across the chart.

3. Visual Representation Once the calculations are complete, the script draws the data directly on your screen:

  • Horizontal Lines: It creates a series of dashed horizontal lines representing the calculated price levels.
  • Degree Labels: To help you identify each level, it places text labels on the chart (e.g., "45 Degrees," "90 Degrees," etc.). These labels correspond to the specific step in the mathematical sequence, allowing for quick identification of key zones.

Summary for the User

Essentially, this tool automates a geometric pricing theory. By providing a single starting price, the script handles all the heavy lifting—calculating, scaling for different currencies, and drawing—to provide you with a clear visual map of potential price levels based on the Square of Nine methodology.

7 Views
0 Downloads
0 Favorites
Square of Nine
//+------------------------------------------------------------------+
//|                                               Square of Nine.mq4 |
//|                                  Copyright © 2006, Matt Trigwell |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Matt Trigwell"
#property link      "m.trigwell@gmail.com"

#property indicator_chart_window


extern double    StartPrice=0;
extern bool      Direction_Up=true;
extern color     Angle_Color=Yellow;


   

int init()
{

   return(0);
}

int deinit()
{
   int AngleIndex=0;
   string AngleName="";
   
   for(AngleIndex=45;AngleIndex<=720;AngleIndex=AngleIndex+45)
   {
      AngleName = "Angle_" + AngleIndex;
      ObjectDelete(AngleName + " Label");
      ObjectDelete(AngleName + " Line");
   }
   
   return(0);
}

int start()
{
   int AngleIndex=0;
   string AngleName="";
   double FactorIndex=0.25;
   double AnglePriceLevel=0;

   for(AngleIndex=45;AngleIndex<=720;AngleIndex=AngleIndex+45)
   {
      AnglePriceLevel = CalculateSquare(FactorIndex,StartPrice);
      AngleName = "Angle_" + AngleIndex;
      
      if(ObjectFind(AngleName + " Line") != 0)
      {
         ObjectCreate(AngleName + " Line", OBJ_HLINE, 0, Time[40], AnglePriceLevel);
         ObjectSet(AngleName + " Line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
         ObjectSet(AngleName + " Line", OBJPROP_COLOR, Angle_Color);
      }
      else
      {
         ObjectMove(AngleName + " Line", 0, Time[40], AnglePriceLevel);
      }
   
      if(ObjectFind(AngleName + " Label") != 0)
      {
         ObjectCreate(AngleName + " Label", OBJ_TEXT, 0, Time[20], AnglePriceLevel);
         ObjectSetText(AngleName + " Label", AngleIndex + " Degrees", 8, "Arial", EMPTY);
      }
      else
      {
         ObjectMove(AngleName + " Label", 0, Time[0], AnglePriceLevel);
      }
      
      FactorIndex = FactorIndex + 0.25;
   }

   return(0);
}






double CalculateSquare(double Factor, double Price)
{
   double AnglePrice=0;
   
   if(Price > 0)
   {
   
      if(StringFind(Symbol(),"JPY",0) == -1)
      {
         Price = Price * 10000;
      }
      else
      {
         Price = Price * 100;
      }
            
      if(Direction_Up==true)
      {
         AnglePrice = MathPow(MathSqrt(Price) + Factor,2);
      }
      else
      {
         AnglePrice = MathPow(MathSqrt(Price) - Factor,2);
      }
   
      if(StringFind(Symbol(),"JPY",0) == -1)
      {
         AnglePrice = AnglePrice / 10000;
      }
      else
      {
         AnglePrice = AnglePrice / 100;
      }
   
   }
   
   return(AnglePrice);
 
}

Comments