Gann SQ9 Price Levels_version-4





//+------------------------------------------------------------------+
//|                                                  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);

 
} 



Sample





Analysis



Market Information Used:

Series array that contains the lowest prices of each bar
Series array that contains the highest prices of each bar
Series array that contains open time of each bar


Indicator Curves created:


Indicators Used:



Custom Indicators Used:

Order Management characteristics:

Other Features: