Gann SQ9 Price Levels_version-4
Download scriptThis script is designed to provide visual price levels on a trading chart based on specific mathematical "angles." Instead of standard technical indicators like moving averages, it focuses on geometric expansion from a user-defined anchor point.
Core Functionality
The primary purpose of this tool is to project horizontal price lines that expand outward from a starting point. It interprets the market's price movement through a squaring/square-root logic, creating a visual map of potential price zones.
How it Works
The logic operates through three main stages:
1. Anchor Point Identification The script looks for specific manual objects (markers) placed on your chart by you, the user. It identifies these anchors based on their specific names (e.g., numbers like 1 through 6 or negative numbers like -1 through -6).
- If it detects a "positive" anchor, it treats that price as a base for an upward expansion.
- If it detects a "negative" anchor, it treats that price as a base for a downward expansion.
- The script automatically adjusts its internal scale based on which specific anchor you choose to use, ensuring the math remains accurate across different types of assets.
2. Mathematical Projection Once an anchor point is set, the script performs a calculation to determine where the "angle" lines should sit.
- It takes the square root of the price at your chosen anchor.
- It adds (or subtracts) a specific factor to that result.
- It then squares the final number to translate it back into a price value.
- This creates a non-linear expansion, meaning the distance between the lines changes as the price moves further away from the starting point.
3. Dynamic Visual Mapping The script automatically draws these calculated levels on your chart:
- Horizontal Lines: It populates the chart with a series of horizontal lines representing different degrees (e.g., 0° to 360°).
- Labels: Each line is accompanied by a text label showing its corresponding angle degree, making it easy to read at a glance.
- Asset Awareness: The script includes built-in logic to recognize different types of assets. It recognizes "JPY" (Japanese Yen) pairs and "GOLD," adjusting the math automatically so that the lines appear correctly on those specific instruments without the user needing to do manual conversions.
Summary for the User
Essentially, this is a geometric price projector. You place a marker on a significant price point, and the script automatically draws out a "web" of expansion levels. This helps traders visualize potential price targets or areas of interest based on the mathematical geometry of the move rather than just standard trend lines.
//+------------------------------------------------------------------+
//| SQ9 (Price).mq4 |
//| Copyright © 2006, Matt Trigwell |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Matt Trigwell"
#property link "m.trigwell@gmail.com" // then hacked around by deanz.
#property indicator_chart_window
int line_spacing_multiplier=0;
extern int levels__to=360;
extern int lines_every=90;
extern double factorNumber=0.5;
//extern color line_Color=CLR_NONE;
extern color line_Color=White;
extern int line_Style_choose_from_0_to_4=0;
extern int font_size=9;
bool is_this_the_HIGH_price=true;
int init()
{
return(0);
}
int deinit()
{
double AngleIndex_V=0;
string AngleName_V="";
for(AngleIndex_V=0;AngleIndex_V<=levels__to;AngleIndex_V=AngleIndex_V+lines_every)
{
AngleName_V = "Angle_V" + AngleIndex_V;
ObjectDelete(AngleName_V + " Label");
ObjectDelete(AngleName_V + " Line");
}
return(0);
}
int start()
{
double the_High_or_Low_Price=0;
double AngleIndex_V=0;
string AngleName_V="";
double FactorIndex=0;
double AnglePriceLevel=0;
int Index=0;
string strLabel="";
if(ObjectFind("1")!=-1)
{
line_spacing_multiplier=1000000;
the_High_or_Low_Price = iLow(0, 0, iBarShift(NULL, 0, ObjectGet("1", OBJPROP_TIME1)));
is_this_the_HIGH_price=false;
}
if(ObjectFind("2")!=-1)
{
line_spacing_multiplier=100000;
the_High_or_Low_Price = iLow(0, 0, iBarShift(NULL, 0, ObjectGet("2", OBJPROP_TIME1)));
is_this_the_HIGH_price=false;
}
// High
if(ObjectFind("3")!=-1)
{
line_spacing_multiplier=10000;
the_High_or_Low_Price = iLow(0, 0, iBarShift(NULL, 0, ObjectGet("3", OBJPROP_TIME1)));
is_this_the_HIGH_price=false;
}
if(ObjectFind("4")!=-1)
{
line_spacing_multiplier=1000;
the_High_or_Low_Price = iLow(0, 0, iBarShift(NULL, 0, ObjectGet("4", OBJPROP_TIME1)));
is_this_the_HIGH_price=false;
}
if(ObjectFind("5")!=-1)
{
line_spacing_multiplier=100;
the_High_or_Low_Price = iLow(0, 0, iBarShift(NULL, 0, ObjectGet("5", OBJPROP_TIME1)));
is_this_the_HIGH_price=false;
}
if(ObjectFind("6")!=-1)
{
line_spacing_multiplier=10;
the_High_or_Low_Price = iLow(0, 0, iBarShift(NULL, 0, ObjectGet("6", OBJPROP_TIME1)));
is_this_the_HIGH_price=false;
}
////////////////////////////////////////////////////////////////
if(ObjectFind("-1")!=-1)
{
line_spacing_multiplier=1000000;
the_High_or_Low_Price = iHigh(0, 0, iBarShift(NULL, 0, ObjectGet("-1", OBJPROP_TIME1)));
is_this_the_HIGH_price=true;
}
if(ObjectFind("-2")!=-1)
{
line_spacing_multiplier=100000;
the_High_or_Low_Price = iHigh(0, 0, iBarShift(NULL, 0, ObjectGet("-2", OBJPROP_TIME1)));
is_this_the_HIGH_price=true;
}
if(ObjectFind("-3")!=-1)
{
line_spacing_multiplier=10000;
the_High_or_Low_Price = iHigh(0, 0, iBarShift(NULL, 0, ObjectGet("-3", OBJPROP_TIME1)));
is_this_the_HIGH_price=true;
}
if(ObjectFind("-4")!=-1)
{
line_spacing_multiplier=1000;
the_High_or_Low_Price = iHigh(0, 0, iBarShift(NULL, 0, ObjectGet("-4", OBJPROP_TIME1)));
is_this_the_HIGH_price=true;
}
if(ObjectFind("-5")!=-1)
{
line_spacing_multiplier=100;
the_High_or_Low_Price = iHigh(0, 0, iBarShift(NULL, 0, ObjectGet("-5", OBJPROP_TIME1)));
is_this_the_HIGH_price=true;
}
if(ObjectFind("-6")!=-1)
{
line_spacing_multiplier=10;
the_High_or_Low_Price = iHigh(0, 0, iBarShift(NULL, 0, ObjectGet("-6", OBJPROP_TIME1)));
is_this_the_HIGH_price=true;
}
for(AngleIndex_V=0;AngleIndex_V<=levels__to;AngleIndex_V=AngleIndex_V+lines_every)
{
AnglePriceLevel = CalculateSquare(FactorIndex,the_High_or_Low_Price);
//Trim Zero's
if(Index==1)
{
strLabel = DoubleToStr(AngleIndex_V,1);
}
else
{
strLabel = DoubleToStr(AngleIndex_V,0);
}
AngleName_V = "Angle_V" + AngleIndex_V;
if(ObjectFind(AngleName_V + " Line") != 0)
{
ObjectCreate(AngleName_V + " Line", OBJ_HLINE, 0, Time[40], AnglePriceLevel);
ObjectSet(AngleName_V + " Line", OBJPROP_STYLE, line_Style_choose_from_0_to_4);
if(MathMod(Index,2) == 0)
{
ObjectSet(AngleName_V + " Line", OBJPROP_COLOR, line_Color);
}
else
{
ObjectSet(AngleName_V + " Line", OBJPROP_COLOR, line_Color);
}
}
else
{
ObjectMove(AngleName_V + " Line", 0, Time[40], AnglePriceLevel);
}
if(ObjectFind(AngleName_V + " Label") != 0)
{
ObjectCreate(AngleName_V + " Label", OBJ_TEXT, 0, Time[20], AnglePriceLevel);
if(MathMod(Index,2) == 0)
{
ObjectSetText(AngleName_V + " Label", strLabel + "°", font_size, "Arial", line_Color);
}
else
{
ObjectSetText(AngleName_V + " Label", strLabel + "°", font_size, "Arial", line_Color);
}
}
else
{
ObjectMove(AngleName_V + " Label", 0, Time[20], AnglePriceLevel);
}
FactorIndex = FactorIndex + factorNumber;
Index = Index + 1;
}
return(0);
}
double CalculateSquare(double Factor, double Price)
{
double AnglePrice=0;
if(Price > 0)
{
if(StringFind(Symbol(),"JPY",0) >= 0) // JPY pairs.
{
Price = Price * line_spacing_multiplier;
Price = Price / 100;
}
else if(StringFind(Symbol(),"GOLD",0) >= 0)
{
Price = Price * line_spacing_multiplier;
Price = Price / 1000;
}
else
{
Price = Price * line_spacing_multiplier;
}
if(is_this_the_HIGH_price==false)
{
AnglePrice = MathPow(MathSqrt(Price) + Factor,2);
}
else
{
AnglePrice = MathPow(MathSqrt(Price) - Factor,2);
}
if(StringFind(Symbol(),"JPY",0) >= 0)
{
AnglePrice = AnglePrice / line_spacing_multiplier;
AnglePrice = AnglePrice * 100;
}
else if(StringFind(Symbol(),"GOLD",0) >= 0)
{
AnglePrice = AnglePrice / line_spacing_multiplier;
AnglePrice = AnglePrice * 1000;
}
else
{
AnglePrice = AnglePrice / line_spacing_multiplier;
}
}
return(AnglePrice);
}
Comments