I modified the Gann9
https://usethinkscript.com/threads/gann-square-of-9-indicator-for-thinkorswim.5816/
to start at 9:20 and use target calculations, ported the Trail Stop and Take Profit indicators and their bar coloring, and added in a study by mobius called scalper pivots that gets pretty close to the pivots used in the original AFL code.
/NQ 1 min 12/23
/NQ 5 min 12/27
https://usethinkscript.com/threads/gann-square-of-9-indicator-for-thinkorswim.5816/
to start at 9:20 and use target calculations, ported the Trail Stop and Take Profit indicators and their bar coloring, and added in a study by mobius called scalper pivots that gets pretty close to the pivots used in the original AFL code.
Ruby:
# PROFIT TAKER TRAIL STOP PIVOT GANN9
# ported (cobbled, hacked?!) to thinkscript by bigboss
# original by KrT Group / www.pipcharts.com
#
# Version 1.0 - 20211227 Initial port with Pivot, GANN9, and ATR components
# Todo: volume profile and ribbon
# JIMBERG
def EntrySignal = close > ( lowest( low, 20 ) + 2 * ATR( 10 ) );
def ExitSignal = close < ( highest( high, 20 ) - 2 * ATR( 10 ) );
AssignPriceColor(If EntrySignal then color.Blue else if ExitSignal then color.dark_Orange else color.Gray );
plot TrailStop = Highest( Close - 2 * ATR(10), 15 );
plot ProfitTaker = ExpAverage( high, 13 ) + 2 * ATR(10);
profittaker.setdefaultColor(color.lime);
trailstop.setdefaultColor(color.red);
#PIVOTS
# Mobius_Scalper_Pivots
# V01.2011
input n = 12;
#input ShowLines = yes;
#input SoundAlerts = yes;
def h = high;
def l = low;
def Firstbar = BarNumber();
def Highest = fold i = 1 to n + 1
with p = 1
while p
do h > GetValue(h, -i);
def A = if (Firstbar > n and
h == Highest(h, n) and
Highest)
then h
else Double.NaN;
def Lowest = fold j = 1 to n + 1
with q = 1
while q
do l < GetValue(l, -j);
def B = if (Firstbar > n and
l == Lowest(l, n) and Lowest)
then l
else Double.NaN;
def Al = if !IsNaN(A)
then A
else Al[1];
def Bl = if !IsNaN(B)
then B
else Bl[1];
plot ph = Round(A, 2);
ph.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ph.SetDefaultColor(Color.RED);
plot pl = Round(B, 2);
pl.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
pl.SetDefaultColor(Color.GREEN);
# End Study Mobius_Scalper_Pivots
# GANN9 by bigboss
input normalizeGannToTwoDps = 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 normalizeGannToTwoDps then power(10,rf-2) else 1;
def srFactor = .0005;
def rthStart = RegularTradingStart(GetYYYYMMDD());
def rthEnd = RegularTradingEnd(GetYYYYMMDD());
input Gann9StartTime = 0920;
def isupdateTime =
if secondsTillTime(Gann9StartTime) == 0
or barnumber() == 1
then 1 else 0;
# if Show after hours is yes, then always show the lines, otherwise only between RTH
def gannprice = 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);
plot R6 = round(power(gannpricebase + uppergannangle+.750,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);
plot S6 = round(power(gannpricebase + uppergannangle+.750,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);
R6.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);
S6.SetDefaultColor(color.dark_gray);
AddLabel(1, "Buy Above: $" + BuyAbove, color.green);
AddLabel(1, "Sell Below: $" + SellBelow, color.red);
/NQ 1 min 12/23
/NQ 5 min 12/27
Last edited by a moderator: