Gann 3-Day Low or High

john88

New member
VIP
Hello,

Would someone please code this up on a daily time frame?
I appreciate your help.
Thank you.

Gann_3.JPG


@samer800
Would you please take a look to see if you can code this? Thank you very much!
 
Last edited by a moderator:
Solution
Hello,

Would someone please code this up on a daily time frame?
I appreciate your help.
Thank you.

View attachment 21994

@samer800
Would you please take a look to see if you can code this? Thank you very much!

i think this works as expected,

here is my version of the 3 day low,
. find peaks. find the highest high, that will be bar1
. find mother bars for inside bars, smaller future bars. count how many inside bars after the mother bar
. look at prev bars. find bar2 and bar3
. skip inside bars , smaller than prev non inside , countable bars
. stop is lowest of those 3 bars


draws cyan squares on bars with a peak or valley
a peak is bar #1
valid bars before the peak get a #2 and #3
draws numbers above the candles ( 3 , 2 , 1 )...
Hello,

Would someone please code this up on a daily time frame?
I appreciate your help.
Thank you.

View attachment 21994

@samer800
Would you please take a look to see if you can code this? Thank you very much!

i think this works as expected,

here is my version of the 3 day low,
. find peaks. find the highest high, that will be bar1
. find mother bars for inside bars, smaller future bars. count how many inside bars after the mother bar
. look at prev bars. find bar2 and bar3
. skip inside bars , smaller than prev non inside , countable bars
. stop is lowest of those 3 bars


draws cyan squares on bars with a peak or valley
a peak is bar #1
valid bars before the peak get a #2 and #3
draws numbers above the candles ( 3 , 2 , 1 )
inside bars are skipped
draws a white dot on inside bars
draws a horizontal line at the lowest low of 3 numbered bars


Code:
#gann_3day_low_high_stoploss

#https://usethinkscript.com/threads/gann-3-day-low-or-high.18875/
#Gann 3-Day Low or High

#3 day low,
#find peaks. find the highest high, that will be bar1
#find mother bars for inside bars, smaller future bars. count how many inside bars after the mother bar
#look at prev bars. find bar2 and bar3
#skip inside bars , smaller than prev non inside , countable bars
#stop is lowest of those 3 bars


#=======================================
#=======================================

# peaks

#peaksvalleys_robert_03_updated

#https://usethinkscript.com/threads/zigzag-high-low-with-supply-demand-zones-for-thinkorswim.172/#post-7048
#post10
#robert
# define peaks / valleys
def na = Double.NaN;
def bn = BarNumber();

#def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def lastbn = HighestAll(if IsNaN(close) then 0 else bn);
def lastbar = bn == lastbn;
#def lastbar = (!isnan(close) and isnan(close[-1]));

def highx = high;
def lowx = low;
input pkval_length = 7;

def offset = Min(pkval_length - 1, lastbn - bn);
def peak = highx > Highest(highx[1], pkval_length - 1) and highx == GetValue(Highest(highx, pkval_length), -offset);
def valley = lowx < Lowest(lowx[1], pkval_length - 1) and lowx == GetValue(Lowest(lowx, pkval_length), -offset);

input pkval_arrows = yes;
def y1 = 0.002;
plot zpk = if pkval_arrows and peak then high*(1+y1) else na;
plot zval = if pkval_arrows and valley then low*(1-y1) else na;

zpk.SetPaintingStrategy(PaintingStrategy.SQUARES);
#zpk.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
zpk.SetDefaultColor(Color.cyan);
zpk.SetLineWeight(2);
zpk.HideBubble();

zval.SetPaintingStrategy(PaintingStrategy.SQUARES);
#zval.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_down);
zval.SetDefaultColor(Color.cyan);
zval.SetLineWeight(2);
zval.HideBubble();


#=======================================
#=======================================

# inside bars

def hi = high;
def lo = low;

# find inside bars
# look at future bars for smaller bars
# white dots on inside bars , skipped

def n = 100;
# count how many inside bars after mother bar
def inside_qty = fold i = 1 to n
 with p
 while (high > getvalue(high,-i) and low < getvalue(low,-i))
 do p + 1;

def ismother = inside_qty > 0;

# after mother bar, count down over the inside bars
def cntdown = if ismother and cntdown[1] < 0 then inside_qty 
 else if cntdown[1] > 0 then cntdown[1] - 1
 else -1;

def insidebar = if cntdown >= 0 and cntdown[1] >= 0 then 1 else 0;

# inside bars
plot zin = if insidebar then MidBodyVal() else na;
zin.SetPaintingStrategy(PaintingStrategy.points);
zin.AssignValueColor(Color.WHITE);
zin.SetLineWeight(3);
zin.HideBubble();

#------------------------

# inside bars horz lines
input test_inside_lines = no;

def insidehi = if cntdown >= 0 and !insidebar then high
 else if cntdown >= 0 then insidehi[1]
 else na;

def insidelo = if cntdown >= 0 and !insidebar then low
 else if cntdown >= 0 then insidelo[1]
 else na;

plot zinhi = if test_inside_lines then insidehi else na;
zinhi.AssignValueColor(Color.WHITE);
zinhi.HideBubble();

plot zinlo = if test_inside_lines then insidelo else na;
zinlo.AssignValueColor(Color.WHITE);
zinlo.HideBubble();

#=======================================
#=======================================

# look for a future peak
# count the bars to the peak
#   are there (barz - 1) future valid bars (not inside bars) before it?

def barz = 3;

def bar3 = fold f = 0 to n
  with q = 1
  while !getvalue(peak, -f)
  do q + (if getvalue(insidebar, -f) then 0 else 1);

def big = 99999;

# find lowest low
def lolo = if bn == 1 then na
  else if bar3 == bar3[-1] then lolo[1]
  else if bar3 == barz and bar3 != bar3[-1] then (
    fold g = 0 to bar3
    with r = big
    do min(r, getvalue(low,-g))
  ) else lolo[1];

plot z1 = lolo;
z1.SetPaintingStrategy(PaintingStrategy.horizontal);
z1.AssignValueColor(Color.magenta);
z1.HideBubble();

# show bar #s
def upcnt = if bar3 == barz and !insidebar then barz
else if !insidebar then upcnt[1] - 1
else upcnt[1];

plot zupcnt = if upcnt > 0 and upcnt != upcnt[1] then upcnt else na;
zupcnt.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);  
#x.SetPaintingStrategy(PaintingStrategy.VALUES_below); 
zupcnt.AssignValueColor(Color.white);

#=======================================
#=======================================


input inside_bar_count_bubble = no;
addchartbubble(inside_bar_count_bubble and ismother, low,
 inside_qty 
,color.yellow, no);


# inside bars count down
addchartbubble(0, low,
cntdown
, color.cyan, no);


def t = 0;
addchartbubble(bar3 == barz and t, low,
bar3
#bar3 + " b3\n" +
#insidebar + " in\n" +
#(getvalue(peak, - bar3)) + " pk\n" +
#bar3_low
#" "
, (if lolo then color.cyan else color.gray), no);
#, (if bar3_low then color.cyan else color.gray), no);


addchartbubble(0,low,
 cntdown
, color.magenta, no);
#
 

Attachments

  • img3.JPG
    img3.JPG
    154.8 KB · Views: 258
Last edited:
Solution

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

i think this works as expected,

here is my version of the 3 day low,
. find peaks. find the highest high, that will be bar1
. find mother bars for inside bars, smaller future bars. count how many inside bars after the mother bar
. look at prev bars. find bar2 and bar3
. skip inside bars , smaller than prev non inside , countable bars
. stop is lowest of those 3 bars


draws cyan squares on bars with a peak or valley
a peak is bar #1
valid bars before the peak get a #2 and #3
draws numbers above the candles ( 3 , 2 , 1 )
inside bars are skipped
draws a white dot on inside bars
draws a horizontal line at the lowest low of 3 numbered bars


Code:
#gann_3day_low_high_stoploss

#https://usethinkscript.com/threads/gann-3-day-low-or-high.18875/
#Gann 3-Day Low or High

#3 day low,
#find peaks. find the highest high, that will be bar1
#find mother bars for inside bars, smaller future bars. count how many inside bars after the mother bar
#look at prev bars. find bar2 and bar3
#skip inside bars , smaller than prev non inside , countable bars
#stop is lowest of those 3 bars


#=======================================
#=======================================

# peaks

#peaksvalleys_robert_03_updated

#https://usethinkscript.com/threads/zigzag-high-low-with-supply-demand-zones-for-thinkorswim.172/#post-7048
#post10
#robert
# define peaks / valleys
def na = Double.NaN;
def bn = BarNumber();

#def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def lastbn = HighestAll(if IsNaN(close) then 0 else bn);
def lastbar = bn == lastbn;
#def lastbar = (!isnan(close) and isnan(close[-1]));

def highx = high;
def lowx = low;
input pkval_length = 7;

def offset = Min(pkval_length - 1, lastbn - bn);
def peak = highx > Highest(highx[1], pkval_length - 1) and highx == GetValue(Highest(highx, pkval_length), -offset);
def valley = lowx < Lowest(lowx[1], pkval_length - 1) and lowx == GetValue(Lowest(lowx, pkval_length), -offset);

input pkval_arrows = yes;
def y1 = 0.002;
plot zpk = if pkval_arrows and peak then high*(1+y1) else na;
plot zval = if pkval_arrows and valley then low*(1-y1) else na;

zpk.SetPaintingStrategy(PaintingStrategy.SQUARES);
#zpk.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
zpk.SetDefaultColor(Color.cyan);
zpk.SetLineWeight(2);
zpk.HideBubble();

zval.SetPaintingStrategy(PaintingStrategy.SQUARES);
#zval.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_down);
zval.SetDefaultColor(Color.cyan);
zval.SetLineWeight(2);
zval.HideBubble();


#=======================================
#=======================================

# inside bars

def hi = high;
def lo = low;

# find inside bars
# look at future bars for smaller bars
# white dots on inside bars , skipped

def n = 100;
# count how many inside bars after mother bar
def inside_qty = fold i = 1 to n
 with p
 while (high > getvalue(high,-i) and low < getvalue(low,-i))
 do p + 1;

def ismother = inside_qty > 0;

# after mother bar, count down over the inside bars
def cntdown = if ismother and cntdown[1] < 0 then inside_qty
 else if cntdown[1] > 0 then cntdown[1] - 1
 else -1;

def insidebar = if cntdown >= 0 and cntdown[1] >= 0 then 1 else 0;

# inside bars
plot zin = if insidebar then MidBodyVal() else na;
zin.SetPaintingStrategy(PaintingStrategy.points);
zin.AssignValueColor(Color.WHITE);
zin.SetLineWeight(3);
zin.HideBubble();

#------------------------

# inside bars horz lines
input test_inside_lines = no;

def insidehi = if cntdown >= 0 and !insidebar then high
 else if cntdown >= 0 then insidehi[1]
 else na;

def insidelo = if cntdown >= 0 and !insidebar then low
 else if cntdown >= 0 then insidelo[1]
 else na;

plot zinhi = if test_inside_lines then insidehi else na;
zinhi.AssignValueColor(Color.WHITE);
zinhi.HideBubble();

plot zinlo = if test_inside_lines then insidelo else na;
zinlo.AssignValueColor(Color.WHITE);
zinlo.HideBubble();

#=======================================
#=======================================

# look for a future peak
# count the bars to the peak
#   are there (barz - 1) future valid bars (not inside bars) before it?

def barz = 3;

def bar3 = fold f = 0 to n
  with q = 1
  while !getvalue(peak, -f)
  do q + (if getvalue(insidebar, -f) then 0 else 1);

def big = 99999;

# find lowest low
def lolo = if bn == 1 then na
  else if bar3 == bar3[-1] then lolo[1]
  else if bar3 == barz and bar3 != bar3[-1] then (
    fold g = 0 to bar3
    with r = big
    do min(r, getvalue(low,-g))
  ) else lolo[1];

plot z1 = lolo;
z1.SetPaintingStrategy(PaintingStrategy.horizontal);
z1.AssignValueColor(Color.magenta);
z1.HideBubble();

# show bar #s
def upcnt = if bar3 == barz and !insidebar then barz
else if !insidebar then upcnt[1] - 1
else upcnt[1];

plot zupcnt = if upcnt > 0 and upcnt != upcnt[1] then upcnt else na;
zupcnt.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE); 
#x.SetPaintingStrategy(PaintingStrategy.VALUES_below);
zupcnt.AssignValueColor(Color.white);

#=======================================
#=======================================


input inside_bar_count_bubble = no;
addchartbubble(inside_bar_count_bubble and ismother, low,
 inside_qty
,color.yellow, no);


# inside bars count down
addchartbubble(0, low,
cntdown
, color.cyan, no);


def t = 0;
addchartbubble(bar3 == barz and t, low,
bar3
#bar3 + " b3\n" +
#insidebar + " in\n" +
#(getvalue(peak, - bar3)) + " pk\n" +
#bar3_low
#" "
, (if lolo then color.cyan else color.gray), no);
#, (if bar3_low then color.cyan else color.gray), no);


addchartbubble(0,low,
 cntdown
, color.magenta, no);
#
I put this on a Daily chart (20Y) and if you have a strategy to buy at the low dots, scale out at the mid, and sell at the high dots this turn into a nice little scalper.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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