GANN Square Of 9 Indicator for ThinkorSwim

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

Still testing. Gimme a little more time. I need to get @Hypoluxa ’s opinion also before posting.
So this morning i looked at /ES for the first time to monitor this. /ES at 9:00EST was $3859....so the GANN target was $3859.52 and then $3873 would be next. I did this to see if SPX would do that - make sense so far? well at 9:45 SPX hit $3873. Maybe a coincidence, but I'm def going to start testing this for GANN on /ES at 9:00 for SPX after opening.
 
Is there a script .. to get the GANN at pre-defined times ( say 6 AM PST, 7AM PST, 10AM PST, 12PM PST).


That'll be good visualization to begin with ... thoughts.

TIA
MN
 
So this morning i looked at /ES for the first time to monitor this. /ES at 9:00EST was $3859....so the GANN target was $3859.52 and then $3873 would be next. I did this to see if SPX would do that - make sense so far? well at 9:45 SPX hit $3873. Maybe a coincidence, but I'm def going to start testing this for GANN on /ES at 9:00 for SPX after opening.
whats ur opinion on barbados indication? @Hypoluxa
 
I have this setup now
Buy at / above: 3937.56 Targets: 3951.28 - 3967.01 - 3982.77 - 3998.56
Stoploss : 3921.89
Sell at / below: 3921.89 Targets: 3908.2 - 3892.58 - 3877 - 3861.44
Stoploss : 3937.56
 
So this morning i looked at /ES for the first time to monitor this. /ES at 9:00EST was $3859....so the GANN target was $3859.52 and then $3873 would be next. I did this to see if SPX would do that - make sense so far? well at 9:45 SPX hit $3873. Maybe a coincidence, but I'm def going to start testing this for GANN on /ES at 9:00 for SPX after opening.
So trying to understand what you said. You are using the /ES price at 9.00EST If /ES is at 3960 at 9.00EST, SPX should be about 10 points higher or at 3970. So do you then put the SPX price of 3970 into the GANN calculator?
 
I am not seeing a red dot when the price hit $3845, can u please help understand what time you checked?

IKC6MrG.png
Hello @bhaskar_madugula can you please share the code for this strategy? It seems like MACD_BB but I just like to see how strategy is working. Thank you very much.
 
Here is a GANN square of 9 indicator I put together based on the spreadsheet @Hypoluxa posted a few months back. It updates at RTH open, 30 minutes after open, 90 minutes after open, and then once finally at after hours start. Looks to work well on various futures and stocks with varying start times.

Ruby:
# GANN9 by bigboss
# v 1.2 - 20211222 - Added function to normalize to two decimal places, fixed fit studies bug
# v 1.1 - 20210727 - Added Buy Above / Sell Below Labels
# v 1.0 - 20210724 - Initial Release
# Calculates the GANN Square of Nine buy/sell lines, and 5 Support / Resistance targets
#     based on the open price at the following times:
#  1. Regular Trading Start
#  2. First Update minutes after RTH Start defined by input FirstUpdate
#  3. Second Update minutes after RTH Start defined by input SecondUpdate
#  4. After Hours Start

declare upper;

input FirstUpdate = 30; #hint FirstUpdate: Minutes after Regular Trading Start to update
input SecondUpdate = 90; #hint SecondUpdate: Minutes after Regular Trading Start to update
input PlotTargetsInsteadOfSR = no; #hint PlotTargetsInsteadOfSR: Plot targets instead of support/resistance. Targets are 99.95% of the S/R level.
input ShowAfterHours = yes; #hint ShowAfterHours: show gann9 levels after hours
input normalizeToTwoDps = yes; #hint normalizeToTwoSDs: treat small values (e.g. forex, penny stocks) as if they are large values with two digits after the decimal.

# This gets the # of significant digits to round values to.
def rf = fold index = 1 to 10 with c = 1 while power(10,index)*ticksize()%1 != 0 do c+1;
def mf = if normalizeToTwoDps then power(10,rf-2) else 1;

def srFactor = if plotTargetsInsteadOfSR then .0005 else 0;

def rthStart = RegularTradingStart(GetYYYYMMDD());
def rthEnd = RegularTradingEnd(GetYYYYMMDD());

def isupdateTime =
    if (GetTime() > rthstart and GetTime()[1] < rthstart) or  # Regular Hours Start
    (GetTime() > rthstart + firstUpdate * 60 * 1000 and GetTime()[1] < rthstart + firstUpdate * 60 * 1000) or # Firt Update
    (GetTime() > rthstart + secondupdate * 60 * 1000 and GetTime()[1] < rthstart + secondupdate * 60 * 1000) or # Second Update
    (GetTime() > rthend and getTime()[1] < rthend) # After Hours Start
or barnumber() == 1
then 1 else 0;

# if Show after hours is yes, then always show the lines, otherwise only between RTH
def showlines = if showafterhours then yes else (GetTime() between rthstart and rthend);

def gannprice = if !showlines then double.nan else if isupdateTime then sqrt(open * mf) else gannprice[1];
def gannpricebase = rounddown(gannprice,0);

# Calculate the angle of price, and adjust if it is a multiple of 45 degrees so the buy/sell lines are unique.
def angle = gannprice - gannpricebase;
def angleAdjusted = if angle % .125 == 0 then angle+.001 else angle;

# Calculate the buy and sell lines, which are the nearest angle cleanly divisible by 45 above and below price.
def lowergannangle = rounddown(angleadjusted / .125,0)*.125;
def uppergannangle = roundup(angleadjusted / .125,0)*.125;
plot SellBelow = round(power(gannpricebase + lowergannangle,2)/mf,rf);
plot BuyAbove = round(power(gannpricebase + uppergannangle,2)/mf,rf);

# Calculate the next 5 resistance/targets, each in +45 degrees increments from the BuyAbove price
plot R1 = round(power(gannpricebase + uppergannangle+.125,2)*(1-srfactor)/mf,rf);
plot R2 = round(power(gannpricebase + uppergannangle+.250,2)*(1-srfactor)/mf,rf);
plot R3 = round(power(gannpricebase + uppergannangle+.375,2)*(1-srfactor)/mf,rf);
plot R4 = round(power(gannpricebase + uppergannangle+.500,2)*(1-srfactor)/mf,rf);
plot R5 = round(power(gannpricebase + uppergannangle+.625,2)*(1-srfactor)/mf,rf);

# Calculate the next 5 support/targets, each in -45 degree increments from the SellBelow price
plot S1 = round(power(gannpricebase + lowergannangle-.125,2)*(1+srfactor)/mf,rf);
plot S2 = round(power(gannpricebase + lowergannangle-.250,2)*(1+srfactor)/mf,rf);
plot S3 = round(power(gannpricebase + lowergannangle-.375,2)*(1+srfactor)/mf,rf);
plot S4 = round(power(gannpricebase + lowergannangle-.500,2)*(1+srfactor)/mf,rf);
plot S5 = round(power(gannpricebase + lowergannangle-.625,2)*(1+srfactor)/mf,rf);

SellBelow.SetDefaultColor(Color.RED);
BuyAbove.SetDefaultColor(Color.GREEN);

R1.SetDefaultColor(color.dark_gray);
R2.SetDefaultColor(color.dark_gray);
R3.SetDefaultColor(color.dark_gray);
R4.SetDefaultColor(color.dark_gray);
R5.SetDefaultColor(color.dark_gray);

S1.SetDefaultColor(color.dark_gray);
S2.SetDefaultColor(color.dark_gray);
S3.SetDefaultColor(color.dark_gray);
S4.SetDefaultColor(color.dark_gray);
S5.SetDefaultColor(color.dark_gray);

AddLabel(showlines, "Buy Above: $" + BuyAbove, color.green);
AddLabel(showlines, "Sell Below: $" + SellBelow, color.red);

 
Last edited:
Here is a GANN square of 9 indicator I put together based on the spreadsheet @Hypoluxa posted a few months back. It updates at RTH open, 30 minutes after open, 90 minutes after open, and then once finally at after hours start. Looks to work well on various futures and stocks with varying start times.

Ruby:
# GANN9 by bigboss
# v 1.0 - 20210724 - Initial Release
# Calculates the GANN Square of Nine buy/sell lines, and 5 Support / Resistance targets
#     based on the open price at the following times:
#  1. Regular Trading Start
#  2. First Update minutes after RTH Start defined by input FirstUpdate
#  3. Second Update minutes after RTH Start defined by input SecondUpdate
#  4. After Hours Start

declare upper;

input FirstUpdate = 30; #hint FirstUpdate: Minutes after Regular Trading Start to update
input SecondUpdate = 90; #hint SecondUpdate: Minutes after Regular Trading Start to update
input PlotTargetsInsteadOfSR = no; #hint PlotTargetsInsteadOfSR: Plot targets instead of support/resistance. Targets are 99.95% of the S/R level.
input ShowAfterHours = yes; #hint ShowAfterHours: show gann9 levels after hours

def srFactor = if plotTargetsInsteadOfSR then .0005 else 0;

def rthStart = RegularTradingStart(GetYYYYMMDD());
def rthEnd = RegularTradingEnd(GetYYYYMMDD());

def isupdateTime =
    if (GetTime() > rthstart and GetTime()[1] < rthstart) or  # Regular Hours Start
    (GetTime() > rthstart + firstUpdate * 60 * 1000 and GetTime()[1] < rthstart + firstUpdate * 60 * 1000) or # Firt Update
    (GetTime() > rthstart + secondupdate * 60 * 1000 and GetTime()[1] < rthstart + secondupdate * 60 * 1000) or # Second Update
    (GetTime() > rthend and getTime()[1] < rthend) # After Hours Start
then 1 else 0;

# if Show after hours is yes, then always show the lines, otherwise only between RTH
def showlines = if showafterhours then yes else (GetTime() between rthstart and rthend);

def gannprice = if !showlines then double.nan else if isupdateTime == 1 then open else gannprice[1];

# Calculate the angle of price, and adjust if it is a multiple of 45 degrees so the buy/sell lines are unique.
def angle = sqrt(gannprice) - rounddown(sqrt(gannprice),0);
def angleAdjusted = if angle % .125 == 0 then angle+.001 else angle;

# Calculate the buy and sell lines, which are the nearest angle cleanly divisible by 45 above and below price.
def lowergannangle = rounddown(angleadjusted / .125,0)*.125;
def uppergannangle = roundup(angleadjusted / .125,0)*.125;
plot SellBelow = round(power(RoundDown(sqrt(gannprice),0) + lowergannangle,2),2);
plot BuyAbove = round(power(RoundDown(sqrt(gannprice),0) + uppergannangle,2),2);

# Calculate the next 5 resistance/targets, each in +45 degrees increments from the BuyAbove price
plot R1 = round(power(RoundDown(sqrt(gannprice),0) + uppergannangle+.125,2)*(1-srfactor),2);
plot R2 = round(power(RoundDown(sqrt(gannprice),0) + uppergannangle+.250,2)*(1-srfactor),2);
plot R3 = round(power(RoundDown(sqrt(gannprice),0) + uppergannangle+.375,2)*(1-srfactor),2);
plot R4 = round(power(RoundDown(sqrt(gannprice),0) + uppergannangle+.50,2)*(1-srfactor),2);
plot R5 = round(power(RoundDown(sqrt(gannprice),0) + uppergannangle+.625,2)*(1-srfactor),2);

# Calculate the next 5 support/targets, each in -45 degree increments from the SellBelow price
plot S1 = round(power(RoundDown(sqrt(gannprice),0) + lowergannangle-.125,2)*(1+srfactor),2);
plot S2 = round(power(RoundDown(sqrt(gannprice),0) + lowergannangle-.250,2)*(1+srfactor),2);
plot S3 = round(power(RoundDown(sqrt(gannprice),0) + lowergannangle-.375,2)*(1+srfactor),2);
plot S4 = round(power(RoundDown(sqrt(gannprice),0) + lowergannangle-.50,2)*(1+srfactor),2);
plot S5 = round(power(RoundDown(sqrt(gannprice),0) + lowergannangle-.625,2)*(1+srfactor),2);

SellBelow.SetDefaultColor(Color.RED);
BuyAbove.SetDefaultColor(Color.GREEN);

R1.SetDefaultColor(color.dark_gray);
R2.SetDefaultColor(color.dark_gray);
R3.SetDefaultColor(color.dark_gray);
R4.SetDefaultColor(color.dark_gray);
R5.SetDefaultColor(color.dark_gray);

S1.SetDefaultColor(color.dark_gray);
S2.SetDefaultColor(color.dark_gray);
S3.SetDefaultColor(color.dark_gray);
S4.SetDefaultColor(color.dark_gray);
S5.SetDefaultColor(color.dark_gray);

Thanks for this! Will try this out during trading hours.
 
Here is a GANN square of 9 indicator I put together based on the spreadsheet @Hypoluxa posted a few months back. It updates at RTH open, 30 minutes after open, 90 minutes after open, and then once finally at after hours start. Looks to work well on various futures and stocks with varying start times.

Ruby:
# GANN9 by bigboss
# v 1.0 - 20210724 - Initial Release
# Calculates the GANN Square of Nine buy/sell lines, and 5 Support / Resistance targets
#     based on the open price at the following times:
#  1. Regular Trading Start
#  2. First Update minutes after RTH Start defined by input FirstUpdate
#  3. Second Update minutes after RTH Start defined by input SecondUpdate
#  4. After Hours Start

declare upper;

input FirstUpdate = 30; #hint FirstUpdate: Minutes after Regular Trading Start to update
input SecondUpdate = 90; #hint SecondUpdate: Minutes after Regular Trading Start to update
input PlotTargetsInsteadOfSR = no; #hint PlotTargetsInsteadOfSR: Plot targets instead of support/resistance. Targets are 99.95% of the S/R level.
input ShowAfterHours = yes; #hint ShowAfterHours: show gann9 levels after hours

def srFactor = if plotTargetsInsteadOfSR then .0005 else 0;

def rthStart = RegularTradingStart(GetYYYYMMDD());
def rthEnd = RegularTradingEnd(GetYYYYMMDD());

def isupdateTime =
    if (GetTime() > rthstart and GetTime()[1] < rthstart) or  # Regular Hours Start
    (GetTime() > rthstart + firstUpdate * 60 * 1000 and GetTime()[1] < rthstart + firstUpdate * 60 * 1000) or # Firt Update
    (GetTime() > rthstart + secondupdate * 60 * 1000 and GetTime()[1] < rthstart + secondupdate * 60 * 1000) or # Second Update
    (GetTime() > rthend and getTime()[1] < rthend) # After Hours Start
then 1 else 0;

# if Show after hours is yes, then always show the lines, otherwise only between RTH
def showlines = if showafterhours then yes else (GetTime() between rthstart and rthend);

def gannprice = if !showlines then double.nan else if isupdateTime == 1 then open else gannprice[1];

# Calculate the angle of price, and adjust if it is a multiple of 45 degrees so the buy/sell lines are unique.
def angle = sqrt(gannprice) - rounddown(sqrt(gannprice),0);
def angleAdjusted = if angle % .125 == 0 then angle+.001 else angle;

# Calculate the buy and sell lines, which are the nearest angle cleanly divisible by 45 above and below price.
def lowergannangle = rounddown(angleadjusted / .125,0)*.125;
def uppergannangle = roundup(angleadjusted / .125,0)*.125;
plot SellBelow = round(power(RoundDown(sqrt(gannprice),0) + lowergannangle,2),2);
plot BuyAbove = round(power(RoundDown(sqrt(gannprice),0) + uppergannangle,2),2);

# Calculate the next 5 resistance/targets, each in +45 degrees increments from the BuyAbove price
plot R1 = round(power(RoundDown(sqrt(gannprice),0) + uppergannangle+.125,2)*(1-srfactor),2);
plot R2 = round(power(RoundDown(sqrt(gannprice),0) + uppergannangle+.250,2)*(1-srfactor),2);
plot R3 = round(power(RoundDown(sqrt(gannprice),0) + uppergannangle+.375,2)*(1-srfactor),2);
plot R4 = round(power(RoundDown(sqrt(gannprice),0) + uppergannangle+.50,2)*(1-srfactor),2);
plot R5 = round(power(RoundDown(sqrt(gannprice),0) + uppergannangle+.625,2)*(1-srfactor),2);

# Calculate the next 5 support/targets, each in -45 degree increments from the SellBelow price
plot S1 = round(power(RoundDown(sqrt(gannprice),0) + lowergannangle-.125,2)*(1+srfactor),2);
plot S2 = round(power(RoundDown(sqrt(gannprice),0) + lowergannangle-.250,2)*(1+srfactor),2);
plot S3 = round(power(RoundDown(sqrt(gannprice),0) + lowergannangle-.375,2)*(1+srfactor),2);
plot S4 = round(power(RoundDown(sqrt(gannprice),0) + lowergannangle-.50,2)*(1+srfactor),2);
plot S5 = round(power(RoundDown(sqrt(gannprice),0) + lowergannangle-.625,2)*(1+srfactor),2);

SellBelow.SetDefaultColor(Color.RED);
BuyAbove.SetDefaultColor(Color.GREEN);

R1.SetDefaultColor(color.dark_gray);
R2.SetDefaultColor(color.dark_gray);
R3.SetDefaultColor(color.dark_gray);
R4.SetDefaultColor(color.dark_gray);
R5.SetDefaultColor(color.dark_gray);

S1.SetDefaultColor(color.dark_gray);
S2.SetDefaultColor(color.dark_gray);
S3.SetDefaultColor(color.dark_gray);
S4.SetDefaultColor(color.dark_gray);
S5.SetDefaultColor(color.dark_gray);


@bigboss ..thanks for sharing your code.
Couple of requests, I tried to do it myself but was unable to as there is no reference of isupdatetime in the plots.

1. Can we have the labels related to the time. For ex: "RTH Buy Above: xxx.xx", "30min Buy Above. xxx.xx", "90 min Buy Above: xxx.xx"
2. Can this be used in a scanner to check if the price is above the plot line (5m aggregation) ?

Thanks!

Thanks
 
@bigboss ..thanks for sharing your code.
Couple of requests, I tried to do it myself but was unable to as there is no reference of isupdatetime in the plots.

1. Can we have the labels related to the time. For ex: "RTH Buy Above: xxx.xx", "30min Buy Above. xxx.xx", "90 min Buy Above: xxx.xx"
2. Can this be used in a scanner to check if the price is above the plot line (5m aggregation) ?

Thanks!

Thanks

I updated post 114 with version 1.1, which adds in labels for Buy Above and Sell Below. They'll always show the current buy above/sell below price. If it is after hours and the lines are set not to show outside of trading hours, then the labels won't display either.

The scan syntax you would use would look like this, if you saved the script as "GANN9":

Code:
close crosses above GANN9()."BuyAbove" within 5 bars

Obviously you can sub out for crossing below SellBelow, or crossing below BuyAbove if looking for a reversal, etc.
 
I updated post 114 with version 1.1, which adds in labels for Buy Above and Sell Below. They'll always show the current buy above/sell below price. If it is after hours and the lines are set not to show outside of trading hours, then the labels won't display either.

The scan syntax you would use would look like this, if you saved the script as "GANN9":

Code:
close crosses above GANN9()."BuyAbove" within 5 bars

Obviously you can sub out for crossing below SellBelow, or crossing below BuyAbove if looking for a reversal, etc.
Thanks @bigboss, I too was able to add the labels for the current above/below, but was not able to get it for the other times.. thought that would be easy to do.

Cheers
 
When I add the latest GANN9 my candlesticks are really small. I changed it to the left axis and that seems to work. Will the indicator work correctly if I change it to the left axis?
 
When I add the latest GANN9 my candlesticks are really small. I changed it to the left axis and that seems to work. Will the indicator work correctly if I change it to the left axis?
Uncheck "Fit Study" on Price Axis settings, you will be all set after that.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
315 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