GANN Square Of 9 Indicator for ThinkorSwim

germanburrito

Active member
You can change the square of 9 to be dictated by the highest high or lowest low, this indicator lets you place the your own price. lets keep this thread going with all of Gann indicators and ideas, I'm willing to share my ideas i hope you do as well.

Code:
#GANN SQUARE OF 9

input sh= 9999.99;

def data00 = Sqrt(sh) - (0 / 180);
def data0 = Power(data00, 2);
plot line00 = data0;


def data45 = Sqrt(sh) - (45 / 180);
def data1 = Power(data45, 2);
plot line45 = data1;

line45.SetDefaultColor(Color.GREEN);

def data90 = Sqrt(sh) - (90 / 180);
def data2 = Power(data90, 2);
plot line90 = data2;

line90.SetDefaultColor(Color.GREEN);

def data135 = Sqrt(sh) - (135 / 180);
def data3 = Power(data135, 2);
plot line135 = data3;

line135.SetDefaultColor(Color.GREEN);

def data180 = Sqrt(sh) - (180 / 180);
def data4 = Power(data180, 2);
plot line180 = data4;

line180.SetDefaultColor(Color.GREEN);

def data225 = Sqrt(sh) - (225 / 180);
def data5 = Power(data225, 2);
plot line225 = data5;

line225.SetDefaultColor(Color.GREEN);

def data270 = Sqrt(sh) - (270 / 180);
def data6 = Power(data270, 2);
plot line270 = data6;

line270.SetDefaultColor(Color.GREEN);

def data315 = Sqrt(sh) - (315 / 180);
def data7 = Power(data315, 2);
plot line315 = data7;

line315.SetDefaultColor(Color.GREEN);

def data360 = Sqrt(sh) - (360 / 180);
def data8 = Power(data360, 2);
plot line360 = data8;

line360.SetDefaultColor(Color.GREEN);


def data405 = Sqrt(sh) - (405 / 180);
def data9 = Power(data405, 2);
plot line405 = data9;

line405.SetDefaultColor(Color.GREEN);

def data450 = Sqrt(sh) - (450 / 180);
def data10 = Power(data450, 2);
plot line450 = data10;

line450.SetDefaultColor(Color.GREEN);

def data495 = Sqrt(sh) - (495 / 180);
def data11 = Power(data495, 2);
plot line495 = data11;

line495.SetDefaultColor(Color.GREEN);
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Can you post a screenshot of your chart? I added this to mine and I have no idea what to do or what its supposed to look like. All I have are about 10 lines straight across the top and the candles are smashed down to one line and cant see them.
 
@germanburrito can you add comment header to your script so if any changes by community, we can track the changes.

Can you post a screenshot of your chart? I added this to mine and I have no idea what to do or what its supposed to look like. All I have are about 10 lines straight across the top and the candles are smashed down to one line and cant see them.
thats exactly what it is, it is the sqaure of 9 with different angles below the price that you desire, we can change it to get the possiitve angles not just the negative ones, and to get the price at a certain time, i don't understand the strategy you are using so i dont really know how to modify it.
 
Study with lines on the screen:

Screen with fit studies unchecked:
i wrote the code where you can input the price yourself, because i dont know wht price you wan to use as reference therefore it is using 9999.99 dollars as reference to create the gann levels however it is only using that price below, however on the video i saw you were watchig it also gives gann levels above the reference price which could also be achieved. does that make sense, the gann levels you are getting from the website gives you the levels based on a number you plot so does this, its just using a stock price of 9999.99.
 
What's the best time to begin using this? 15mins after open? 30mins? etc..
And how often should it be updated throughout the day?
 
germanburrito,

I'm glad that you posted your Gann SO9, because I've been working on a code for that too; but I'm having problems with it. Here is the code and a share link below it. It's based on the Law Of Vibration from Michael Jenkin's Gann course using musical frequencies attuned to each stock on the chart. You have to set the Life Path Number of the stock to get a correct plot. Please take a look at it and maybe you can get it to work. This website can give you an idea of how Michael Jenkins does the calculation. http://tradingfives.com/square-of-nine-in-excel.htm

Code:
#  GannSO9_LOV

# ===============================================================
# Dislaimer: For educational purposes only! Obviously, no guarantees whatsoever and use at your own risk.
# ===============================================================

#  Gann Square Of Numbers
#  Using the Law Of Vibrations (LOV)
#  The LOV number is taken from the stock's life path number
#  Reference Material
#  Physics Of Musical Notes: http://pages.mtu.edu/~suits/Physicsofmusic.html
#  Frequencies for equal-tempered scale, A4 = 440 Hz:  http://pages.mtu.edu/~suits/notefreqs.html
#  Pythagorean Scale: http://pages.mtu.edu/~suits/pythagorean.html
#  Frequencies for equal-tempered scale, A4 = 440 Hz
#  Questions/Comments to: [email protected]
#  Pythagorean Scale: http://www.phys.uconn.edu/~gibson/Notes/Section3_4/Sec3_4.htm
#  Life Path Number: https://www.tokenrock.com/numerology/life_path/
#  First Trade Dates of Stocks: http://www.magiastrology.com/firsttradedate/mostrecent_ipo.php
#  Inception Dates of ETFs: http://www.proshares.com/funds/sds.html


declare upper;

input Square = {"Square Of 3", "Square Of 4", "Square Of 5", "Square Of 6", "Square Of 7", default "Square Of 8", "Square Of 9", "Square Of 10", "Square Of 11", "Square Of 12"};
input Multiplier = {"0.001", "0.01", "0.10", default "1", "10", "100", "1000", "10000"};
input DegreeIncrements = {"11.25", "22.50", default "45.00", "90.00", "180.00"};
input numMonths1 = 5;
input VScale = 0.5;
input HScale = 5.0;
input GridSize = 50;

input Show1      = yes;
input lineWeight = 2;

def numdays  = 21;

def numBars1  = numdays * numMonths1;
def barNum    = if IsNaN( close ) then Double.NaN else BarNumber();
def lastBar   = HighestAll( barNum );
def startBar1 = if lastBar <= numBars1 then 1 else lastBar - numBars1;
def bar = BarNumber();

def hData1    = If( barNum < startBar1, Double.NaN, high );
def lData1    = If( barNum < startBar1, Double.NaN, low );

def a_price   = HighestAll(high);
def b_price   = LowestAll(low);
def barnumber = BarNumber();
def c_price   = if high == a_price then barnumber else Double.NaN;
def d_price   = if low == b_price then barnumber else Double.NaN;
rec highnumber    = CompoundValue(1, if IsNaN(c_price) then highnumber[1] else c_price, c_price);
def highnumberall = HighestAll(highnumber);
rec lownumber     = CompoundValue(1, if IsNaN(d_price) then lownumber[1] else d_price, d_price);
def lownumberall  = LowestAll(lownumber);

def months1   = Round( ( lastBar - startBar1 + 1 ) / 21, 0 );
plot HighestHigh1 = If( Show1, HighestAll( hData1 ), Double.NaN );
plot LowestLow1   = If( Show1, LowestAll( lData1 ),  Double.NaN );

# ===============================================================
#                Chart Bubbles
# ===============================================================
def BeginBarH = if barNum >= startBar1 and HighestAll(HighestHigh1) == high
                then  BarNumber() else BeginBarH[1];
def BeginBarL = if barNum >= startBar1 and HighestAll(LowestLow1) == low
                then  BarNumber() else  BeginBarL[1];
def BeginBar  = HighestAll(Min(BeginBarH, BeginBarL));

# ===============================================================
#                Plotting Section
# ===============================================================

#===================[ Define Plot Appearences ]=====================
DefineGlobalColor( "H1", Color.VIOLET);
DefineGlobalColor( "L1", Color.PINK);

HighestHigh1.SetPaintingStrategy( PaintingStrategy.Dashes );
HighestHigh1.SetLineWeight( 1 );
HighestHigh1.AssignValueColor( GlobalColor( "H1" ) );
HighestHigh1.HideBubble();

LowestLow1.SetPaintingStrategy( PaintingStrategy.Dashes );
LowestLow1.SetLineWeight( 1 );
LowestLow1.AssignValueColor( GlobalColor( "L1" ) );
LowestLow1.HideBubble();

AddChartBubble( Show1 and barNum == BeginBar, HighestHigh1, Concat( "Highest High in ",  Concat( months1, Concat (" Months is ", HighestHigh1)) ), GlobalColor( "H1" ), yes );

AddChartBubble( Show1 and barNum == BeginBar, LowestLow1,   Concat( "Lowest Low in ",   Concat( months1, Concat (" Months is ", LowestLow1)) ), GlobalColor( "L1" ), no  );

def begindate  = if BarNumber() == BeginBar then GetYYYYMMDD() else begindate[1];
def beginclose = if BarNumber() == BeginBar then close else beginclose[1];
def enddate    = if BarNumber() == BeginBar + GridSize then GetYYYYMMDD() else enddate[1];

def BeginPrice  = HighestAll(Min(HighestHigh1, LowestLow1));

# =============================
#  SquareOf
#  Gann Musical Value from each musical note
# =============================
def GMV;
switch (Square) {
case "Square Of 3":
    GMV = 1.25992;
case "Square Of 4":
    GMV = 1.41421;
case "Square Of 5":
    GMV = 1.49831;
case "Square Of 6":
    GMV = 1.68179;
case "Square Of 7":
    GMV = 1.88775;
case "Square Of 8":
    GMV = 2.00000;
case "Square Of 9":
    GMV = 2.24492;
case "Square Of 10":
    GMV = 2.51984;
case "Square Of 11":
    GMV = 2.82843;
case "Square Of 12":
    GMV = 2.99661;
}
# ===============================================================
def Multiplier_N;
switch (Multiplier) {
case "0.001":
    Multiplier_N = 0.001;
case "0.01":
    Multiplier_N = 0.01;
case "0.10":
    Multiplier_N = 0.10;
case "1":
    Multiplier_N = 1.00;
case "10":
    Multiplier_N = 10;
case "100":
    Multiplier_N = 1000;
case "1000":
    Multiplier_N = 1000;
case "10000":
    Multiplier_N = 10000;
}
# ===============================================================
def Degrees_N;
switch (DegreeIncrements) {
case "11.25":
    Degrees_N = 11.25;
case "22.50":
    Degrees_N = 22.50;
case "45.00":
    Degrees_N = 45.00;
case "90.00":
    Degrees_N = 90.00;
case "180.00":
    Degrees_N = 180.00;
}

# ===============================================================
#                Gann Square Section
# ===============================================================

def upward   = highnumberall > lownumberall;
def downward = highnumberall < lownumberall;

# =============================
# Plot Gann Square Root Horizontal Lines
# =============================

def BaseValue = if bar >= BeginBar and BeginBarH == BeginBar
          then HighestHigh1
          else if bar >= BeginBar and BeginBarL == BeginBar
               then LowestLow1
          else double.nan;

def startbar = if GetYYYYMMDD() == begindate then BarNumber() else startbar[1];

plot GLH0 = if barnumber between startbar and startbar + numBars1 then BaseValue else Double.NaN;

# def Focus = Sqrt(beginclose);
def Cycle = 360 / Degrees_N;
def Focus = Sqrt(BaseValue);
def Factor = GMV / Cycle;

def GannValue = Focus + (1 * GMV) * Multiplier_N;
def GannLevel = Sqr(Focus + (1 * Cycle))/Multiplier_N;

plot GLH1  = if upward
              then Sqr(Focus + (1 * Factor)) * Multiplier_N
              else Sqr(Focus - (1 * Factor)) * Multiplier_N;
plot GLH2  = if upward
              then Sqr(Focus + (2 * Factor)) * Multiplier_N
              else Sqr(Focus - (2 * Factor)) * Multiplier_N;
plot GLH3  = if upward
              then Sqr(Focus + (3 * Factor)) * Multiplier_N
              else Sqr(Focus - (3 * Factor)) * Multiplier_N;
plot GLH4  = if upward
              then Sqr(Focus + (4 * Factor)) * Multiplier_N
              else Sqr(Focus - (4 * Factor)) * Multiplier_N;
plot GLH5  = if upward
              then Sqr(Focus + (5 * Factor)) * Multiplier_N
              else Sqr(Focus - (5 * Factor)) * Multiplier_N;
plot GLH6  = if upward
              then Sqr(Focus + (6 * Factor)) * Multiplier_N
              else Sqr(Focus - (6 * Factor)) * Multiplier_N;
plot GLH7  = if upward
              then Sqr(Focus + (7 * Factor)) * Multiplier_N
              else Sqr(Focus - (7 * Factor)) * Multiplier_N;
plot GLH8  = if upward
              then Sqr(Focus + (8 * Factor)) * Multiplier_N
              else Sqr(Focus - (8 * Factor)) * Multiplier_N;
plot GLH9  = if upward
              then Sqr(Focus + (9 * Factor)) * Multiplier_N
              else Sqr(Focus - (9 * Factor)) * Multiplier_N;
plot GLH10  = if upward
              then Sqr(Focus + (10 * Factor)) * Multiplier_N
              else Sqr(Focus - (10 * Factor)) * Multiplier_N;
plot GLH11  = if upward
              then Sqr(Focus + (11 * Factor)) * Multiplier_N
              else Sqr(Focus - (11 * Factor)) * Multiplier_N;
plot GLH12  = if upward
              then Sqr(Focus + (12 * Factor)) * Multiplier_N
              else Sqr(Focus - (12 * Factor)) * Multiplier_N;
plot GLH13  = if upward
              then Sqr(Focus + (13 * Factor)) * Multiplier_N
              else Sqr(Focus - (13 * Factor)) * Multiplier_N;
plot GLH14  = if upward
              then Sqr(Focus + (14 * Factor)) * Multiplier_N
              else Sqr(Focus - (14 * Factor)) * Multiplier_N;
plot GLH15  = if upward
              then Sqr(Focus + (15 * Factor)) * Multiplier_N
              else Sqr(Focus - (15 * Factor)) * Multiplier_N;
plot GLH16  = if upward
              then Sqr(Focus + (16 * Factor)) * Multiplier_N
              else Sqr(Focus - (16 * Factor)) * Multiplier_N;
plot GLH17  = if upward
              then Sqr(Focus + (17 * Factor)) * Multiplier_N
              else Sqr(Focus - (17 * Factor)) * Multiplier_N;
plot GLH18  = if upward
              then Sqr(Focus + (18 * Factor)) * Multiplier_N
              else Sqr(Focus - (18 * Factor)) * Multiplier_N;
plot GLH19  = if upward
              then Sqr(Focus + (19 * Factor)) * Multiplier_N
              else Sqr(Focus - (19 * Factor)) * Multiplier_N;
plot GLH20  = if upward
              then Sqr(Focus + (20 * Factor)) * Multiplier_N
              else Sqr(Focus - (20 * Factor)) * Multiplier_N;

# =============================
# Format Gann Square Root Lines
# =============================

GLH0.SetDefaultColor(Color.BLUE);
GLH0.SetLineWeight(lineWeight);
GLH0.SetPaintingStrategy(PaintingStrategy.LINE);
AddChartBubble( barNum == BeginBar, GLH0, Concat(0 * Degrees_N, " *"), Color.White, yes );

GLH1.SetDefaultColor(Color.BLUE);
GLH1.SetLineWeight(lineWeight);
GLH1.SetPaintingStrategy(PaintingStrategy.LINE);
AddChartBubble(  barNum == BeginBar, GLH1, Concat(1 * Degrees_N, " *"), Color.White, yes );

GLH2.SetDefaultColor(Color.BLUE);
GLH2.SetLineWeight(lineWeight);
GLH2.SetPaintingStrategy(PaintingStrategy.LINE);
AddChartBubble( barNum == BeginBar, GLH2, Concat(2 * Degrees_N, " *"), Color.White, yes );

GLH3.SetDefaultColor(Color.BLUE);
GLH3.SetLineWeight(lineWeight);
GLH3.SetPaintingStrategy(PaintingStrategy.LINE);
AddChartBubble( barNum == BeginBar, GLH3, Concat(3 * Degrees_N, " *"), Color.White, yes );

GLH4.SetDefaultColor(Color.BLUE);
GLH4.SetLineWeight(lineWeight);
GLH4.SetPaintingStrategy(PaintingStrategy.LINE);
AddChartBubble( barNum == BeginBar, GLH4, Concat(4 * Degrees_N, " *"), Color.White, yes );

GLH5.SetDefaultColor(Color.BLUE);
GLH5.SetLineWeight(lineWeight);
GLH5.SetPaintingStrategy(PaintingStrategy.LINE);
AddChartBubble( barNum == BeginBar, GLH5, Concat(5 * Degrees_N, " *"), Color.White, yes );

GLH6.SetDefaultColor(Color.BLUE);
GLH6.SetLineWeight(lineWeight);
GLH6.SetPaintingStrategy(PaintingStrategy.LINE);
AddChartBubble( barNum == BeginBar, GLH6, Concat(6 * Degrees_N, " *"), Color.White, yes );

GLH7.SetDefaultColor(Color.Blue);
GLH7.SetLineWeight(lineWeight);
GLH7.SetPaintingStrategy(PaintingStrategy.line);
AddChartBubble( barNum == BeginBar, GLH7, Concat(7 * Degrees_N, " *"), Color.White, yes );

GLH8.SetDefaultColor(Color.BLUE);
GLH8.SetLineWeight(lineWeight);
GLH8.SetPaintingStrategy(PaintingStrategy.LINE);
AddChartBubble( barNum == BeginBar, GLH8, Concat(8 * Degrees_N, " *"), Color.White, yes );

GLH9.SetDefaultColor(Color.BLUE);
GLH9.SetLineWeight(lineWeight);
GLH9.SetPaintingStrategy(PaintingStrategy.LINE);
AddChartBubble( barNum == BeginBar, GLH9, Concat(9 * Degrees_N, " *"), Color.White, yes );

GLH10.SetDefaultColor(Color.BLUE);
GLH10.SetLineWeight(lineWeight);
GLH10.SetPaintingStrategy(PaintingStrategy.LINE);
AddChartBubble( barNum == BeginBar, GLH10, Concat(10 * Degrees_N, " *"), Color.White, yes );

GLH11.SetDefaultColor(Color.BLUE);
GLH11.SetLineWeight(lineWeight);
GLH11.SetPaintingStrategy(PaintingStrategy.LINE);

GLH12.SetDefaultColor(Color.BLUE);
GLH12.SetLineWeight(lineWeight);
GLH12.SetPaintingStrategy(PaintingStrategy.LINE);

GLH13.SetDefaultColor(Color.BLUE);
GLH13.SetLineWeight(lineWeight);
GLH13.SetPaintingStrategy(PaintingStrategy.LINE);

GLH14.SetDefaultColor(Color.BLUE);
GLH14.SetLineWeight(lineWeight);
GLH14.SetPaintingStrategy(PaintingStrategy.LINE);

GLH15.SetDefaultColor(Color.BLUE);
GLH15.SetLineWeight(lineWeight);
GLH15.SetPaintingStrategy(PaintingStrategy.LINE);

GLH16.SetDefaultColor(Color.BLUE);
GLH16.SetLineWeight(lineWeight);
GLH16.SetPaintingStrategy(PaintingStrategy.LINE);

GLH17.SetDefaultColor(Color.BLUE);
GLH17.SetLineWeight(lineWeight);
GLH17.SetPaintingStrategy(PaintingStrategy.LINE);

GLH18.SetDefaultColor(Color.BLUE);
GLH18.SetLineWeight(lineWeight);
GLH18.SetPaintingStrategy(PaintingStrategy.LINE);

GLH19.SetDefaultColor(Color.BLUE);
GLH19.SetLineWeight(lineWeight);
GLH19.SetPaintingStrategy(PaintingStrategy.LINE);

GLH20.SetDefaultColor(Color.BLUE);
GLH20.SetLineWeight(lineWeight);
GLH20.SetPaintingStrategy(PaintingStrategy.LINE);

# AddVerticalLine(boolean visible, Any text, CustomColor color, int stroke);

# ===============================================================
#                Vertical Lines
# ===============================================================

def VInc = GannValue;

def GLV0  = BeginBar;
def GLV1  = GLV0 + (1 * VInc);
def GLV2  = GLV0 + (2 * VInc);
def GLV3  = GLV0 + (3 * VInc);
def GLV4  = GLV0 + (4 * VInc);
def GLV5  = GLV0 + (5 * VInc);
def GLV6  = GLV0 + (6 * VInc);
def GLV8  = GLV0 + (7 * VInc);
def GLV9  = GLV0 + (8 * VInc);
def GLV10 = GLV0 + (9 * VInc);
def GLV11 = GLV0 + (10 * VInc);

AddVerticalLine(BarNumber() == Floor(GLV0), "", Color.GREEN, Curve.FIRM);
AddVerticalLine(BarNumber() == Floor(GLV1), "", Color.RED, Curve.FIRM);
AddVerticalLine(BarNumber() == Floor(GLV2), "", Color.RED, Curve.FIRM);
AddVerticalLine(BarNumber() == Floor(GLV3), "", Color.RED, Curve.FIRM);
AddVerticalLine(BarNumber() == Floor(GLV4), "", Color.RED, Curve.FIRM);
AddVerticalLine(BarNumber() == Floor(GLV5), "", Color.RED, Curve.FIRM);
AddVerticalLine(BarNumber() == Floor(GLV6), "", Color.RED, Curve.FIRM);
AddVerticalLine(BarNumber() == Floor(GLV8), "", Color.RED, Curve.FIRM);
AddVerticalLine(BarNumber() == Floor(GLV9), "", Color.RED, Curve.FIRM);
AddVerticalLine(BarNumber() == Floor(GLV10), "", Color.RED, Curve.FIRM);
AddVerticalLine(BarNumber() == Floor(GLV11), "", Color.RED, Curve.FIRM);

AddVerticalLine( BarNumber() == Floor(BeginBar + GridSize), GetYYYYMMDD() + " ", Color.GRAY, Curve.FIRM);

# ===============================================================
#AddLabel (yes, Square, Color.Light_Gray);
#AddLabel (yes, "GMV: " + GMV, Color.LIGHT_GRAY);
#AddLabel (yes, "Multiplier: " + Multiplier_N, Color.LIGHT_GRAY);
#AddLabel (yes, "GridSize: " + GridSize, Color.LIGHT_GRAY);
#AddLabel (yes, "Horizontal Scale: " + HScale, Color.LIGHT_GRAY);
#AddLabel (yes, "Vertical Scale: " + VScale, Color.LIGHT_GRAY);
#AddLabel (yes, "Degree Increments: " + Degrees_N, Color.LIGHT_GRAY);
#
#AddLabel (yes, "Cycle: " + Cycle, Color.LIGHT_GRAY);
#AddLabel (yes, "Focus: " + Focus, Color.LIGHT_GRAY);
#AddLabel (yes, "Factor: " + Factor, Color.LIGHT_GRAY);
#AddLabel (yes, "GannLevel: " + GannLevel, Color.LIGHT_GRAY);
#AddLabel (yes, "GannValue: " + GannValue, Color.LIGHT_GRAY);
#AddLabel (yes, "GLH1: " + GLH1, Color.LIGHT_GRAY);

http://tos.mx/zdzHqep
i actually wrote something like this a while back, i usualy wouldnt share it because people are so greedy with their knowledge but i guess yo might like this
Code:
input slope_adjust_multiplier = 1.00;
input price = close;
input high = high;
input low = low;
input coefficient_0 = 0.000;

input Coefficient_7 = 1.0;

def slope_adj = slope_adjust_multiplier;
def a = HighestAll(high);
def b = LowestAll(low);
def barnumber = barNumber();
def c = if high == a then barnumber else double.nan;
def d = if low == b then barnumber else double.nan;
rec highnumber = compoundValue(1, if IsNaN(c) then highnumber[1] else c, c);
def highnumberall = HighestAll(highnumber);
rec lownumber = compoundValue(1, if IsNaN(d) then lownumber[1] else d, d);
def lownumberall = LowestAll(lownumber);

def upward = highnumberall > lownumberall;
def downward = highnumberall < lownumberall;
def range =  a - b;
def value0 = range * coefficient_0;

def value7 = range * coefficient_7;


def condition1 = downward and barnumber >= highnumberall;
def condition2 = upward and barnumber >= lownumberall;

Plot Retracement0 = if condition1 then highestall(b + value0) else if condition2 then highestall(a - value0) else double.nan;

Plot Retracement7 = if condition1 then highestall(b + value7) else if condition2 then highestall(a - value7) else double.nan;



def x = AbsValue(lownumberall - highnumberall );

def slope = (a - b) / x;
def slopelow = (b - a) / x;

def day = getDay();
def month = getMonth();
def year = getYear();
def lastDay = getLastDay();
def lastmonth = getLastMonth();
def lastyear = getLastYear();
def isToday = if(day == lastDay and month == lastmonth and year == lastyear, 1, 0);
def istodaybarnumber = HighestAll(if isToday then barnumber else double.nan);


def line = b + (slope * (barnumber - lownumber));
def linelow = a + (slopelow * (barnumber - highnumber));
def currentlinelow = if barnumber <= lownumberall then linelow else double.nan;
def currentline = if barnumber <= highnumberall then line else double.nan;



def xx = if condition1 then (barnumber - highnumberall) else (barnumber - lownumberall);
def mm = if condition1 then highestall((ohlc4 - retracement7) / xx) else lowestall((ohlc4 - retracement7) / xx);

#PLOT FIBS with slope
# Y = MX + B
#y = end value, m = slope = x is time b = beg value
def r7 = mm*slope_adj*xx + retracement7;

def r0 = mm*slope_adj*xx + retracement0;

#VISUALS AND ALERTS
Retracement0.assignvaluecolor(CreateColor(255,255,255));
Retracement0.setLineWeight(4);
retracement0.hidebubble();




Retracement7.assignvaluecolor(CreateColor(255,255,255));
Retracement7.setLineWeight(4);
Retracement7.hidebubble();





retracement0.Hide();
retracement7.hide();


def sh =  if condition1 then r7 else if condition2 then r0 else double.nan;;

def data00 = Sqrt(sh) - (0 / 180);
def data0 = Power(data00, 2);
plot line00 = data0;


def data45 = Sqrt(sh) - (45 / 180);
def data1 = Power(data45, 2);
plot line45 = data1;

line45.SetDefaultColor(Color.GREEN);

def data90 = Sqrt(sh) - (90 / 180);
def data2 = Power(data90, 2);
plot line90 = data2;

line90.SetDefaultColor(Color.GREEN);

def data135 = Sqrt(sh) - (135 / 180);
def data3 = Power(data135, 2);
plot line135 = data3;

line135.SetDefaultColor(Color.GREEN);

def data180 = Sqrt(sh) - (180 / 180);
def data4 = Power(data180, 2);
plot line180 = data4;

line180.SetDefaultColor(Color.GREEN);

def data225 = Sqrt(sh) - (225 / 180);
def data5 = Power(data225, 2);
plot line225 = data5;

line225.SetDefaultColor(Color.GREEN);

def data270 = Sqrt(sh) - (270 / 180);
def data6 = Power(data270, 2);
plot line270 = data6;

line270.SetDefaultColor(Color.GREEN);

def data315 = Sqrt(sh) - (315 / 180);
def data7 = Power(data315, 2);
plot line315 = data7;

line315.SetDefaultColor(Color.GREEN);

def data360 = Sqrt(sh) - (360 / 180);
def data8 = Power(data360, 2);
plot line360 = data8;

line360.SetDefaultColor(Color.GREEN);


def data405 = Sqrt(sh) - (405 / 180);
def data9 = Power(data405, 2);
plot line405 = data9;

line405.SetDefaultColor(Color.GREEN);

def data450 = Sqrt(sh) - (450 / 180);
def data10 = Power(data450, 2);
plot line450 = data10;

line450.SetDefaultColor(Color.GREEN);

def data495 = Sqrt(sh) - (495 / 180);
def data11 = Power(data495, 2);
plot line495 = data11;

line495.SetDefaultColor(Color.GREEN);
 
germanburrito,

I worked on my code until I got exhausted of debugging it. If I didn't have such a problem with ThinkScript, I would have also include an option for choosing either dynamic or static Gann Squares. Not many people know that there are different ways to plot SO9. Anyway, I already made a code like yours before I studied Michael Jenkins work. Gann said that all stocks, commodities, etc. have their own vibration; so the SO9 is not the only square -- it's just the most common. My code is intended to provide that accuracy.
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
497 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top