Repaints Ants — Momentum, Volume and Price (MVP)

Repaints

petech

Member
I saw this very interesting custom indicator on TradingView.
https://www.tradingview.com/script/uEaFv7tm-Ants-Momentum-Volume-and-Price-MVP/

2xK3Vsa.jpg


I haven't got the slightest clue how to code this myself in TOS, but I think it is generally understood that we want to buy stocks that are under institutional accumulation. This indicator from TV seems to attempt to spot stocks that likely being accumulated by institutions. So I hope someone here who knows how to code would also find this concept of interest and want to code a script based upon the logic below.

Also I've already done a search on this site to see if something similar already existed, if it does, I missed finding it.

From the original author on TV....

The Ants indicator is based on the research of David Ryan, three-time winner of the U.S. Investing Championship. David came up with the idea for the indicator while managing the New USA Growth Fund at William O’Neil + Company. David was interested to understand what drove some stocks higher once they were extended from their most recent base, while others had only moderate moves up.

What David found during his research was that stocks making the biggest moves often had consistent buying on volume over a period of 12 to 15 trading days. Stocks with these characteristics may be under institutional accumulation, where it may take days to weeks to fill a position.

Momentum, Volume And Price ( MVP )

The Ants indicator looks for the following:

‎ ‎ ‎ ‎■ Momentum - The stock is up at least 12 of the past 15 days.
‎ ‎ ‎ ‎■ Volume - The volume has increased over the past 15 days by 20% to 25%.
‎ ‎ ‎ ‎■ Price - The price is up at least 20% over the past 15 days.
 
Solution
here is my version of MVP
it draws squares above the candles, depending on 3 conditions.

momentum up is when close is > previous close, for the min bars, within a max series.
volume up is determined when volume average(15) > (volume average(50) * 20%)
price up is determined when price average(15) > (price average(50) * 6%). ( i changed it from 20% to 6%, because price rarely rose 20%, )

can show a color legend to the right of last candle.
a gray horizontal line is drawn when the momentum condition is true.

test data,
...can draw colored squares below the candles, for each condition.
...can show price average lines
...a separate study will show volume average lines

Ruby:
# mvp_01

# -----------------
# halcyonguy
# 21-08-25
#...
I saw this very interesting custom indicator on TradingView.
https://www.tradingview.com/script/uEaFv7tm-Ants-Momentum-Volume-and-Price-MVP/

View attachment 11566

I haven't got the slightest clue how to code this myself in TOS, but I think it is generally understood that we want to buy stocks that are under institutional accumulation. This indicator from TV seems to attempt to spot stocks that likely being accumulated by institutions. So I hope someone here who knows how to code would also find this concept of interest and want to code a script based upon the logic below.

Also I've already done a search on this site to see if something similar already existed, if it does, I missed finding it.

From the original author on TV....

The Ants indicator is based on the research of David Ryan, three-time winner of the U.S. Investing Championship. David came up with the idea for the indicator while managing the New USA Growth Fund at William O’Neil + Company. David was interested to understand what drove some stocks higher once they were extended from their most recent base, while others had only moderate moves up.

What David found during his research was that stocks making the biggest moves often had consistent buying on volume over a period of 12 to 15 trading days. Stocks with these characteristics may be under institutional accumulation, where it may take days to weeks to fill a position.

Momentum, Volume And Price ( MVP )

The Ants indicator looks for the following:

‎ ‎ ‎ ‎■ Momentum - The stock is up at least 12 of the past 15 days.
‎ ‎ ‎ ‎■ Volume - The volume has increased over the past 15 days by 20% to 25%.
‎ ‎ ‎ ‎■ Price - The price is up at least 20% over the past 15 days.
think it is very useful

here is my version of MVP
it draws squares above the candles, depending on 3 conditions.

momentum up is when close is > previous close, for the min bars, within a max series.
volume up is determined when volume average(15) > (volume average(50) * 20%)
price up is determined when price average(15) > (price average(50) * 6%). ( i changed it from 20% to 6%, because price rarely rose 20%, )

can show a color legend to the right of last candle.
a gray horizontal line is drawn when the momentum condition is true.

test data,
...can draw colored squares below the candles, for each condition.
...can show price average lines
...a separate study will show volume average lines

Ruby:
# mvp_01

# -----------------
# halcyonguy
# 21-08-25
# -----------------

# Momentum, Volume and Price (MVP)
 #https://usethinkscript.com/threads/ants-%E2%80%94-momentum-volume-and-price-mvp.7497/
#I saw this very interesting custom indicator on TradingView.
#https://www.tradingview.com/script/uEaFv7tm-Ants-Momentum-Volume-and-Price-MVP/
#The Ants indicator is based on the research of David Ryan, three-time winner of the U.S. Investing Championship. David came up with the idea for the indicator while managing the New USA Growth Fund at William O’Neil + Company. David was interested to understand what drove some stocks higher once they were extended from their most recent base, while others had only moderate moves up.

#What David found during his research was that stocks making the biggest moves often had consistent buying on volume over a period of 12 to 15 trading days. Stocks with these characteristics may be under institutional accumulation, where it may take days to weeks to fill a position.

# — Momentum, Volume And Price ( MVP ) —

# The Ants indicator looks for the following:
#  1... Momentum - The stock is up at least 12 of the past 15 days.
#  2... Volume - The volume has increased over the past 15 days by 20% to 25%.
#  3... Price - The price is up at least 20% over the past 15 days.

# colored squares, above the candles:
#  Gray - Momen requirement met.
#  Blue - Momen and price requirement met.
#  Yellow - Momen and vol requirement met.
#  Green - Momen and vol and price requirement met.

#/////////////////////////////////////

def na = Double.NaN;
def bn = barnumber();

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

input OOOOOO_Momentum_OOOOOOO = yes;
# MVP
# 1... Momentum - The stock is up at least 12 of the past 15 days.
#  it tests if current bar close > previous close

input series_max = 15;
input series_min = 12;
def momen_max = series_max;
def momen_min = series_min;
#input momentum_qty = 15;
#input momentum_min = 12;

def chgup = close > close[1];

def squares_price_offset = 0.02;
def vert = squares_price_offset;

#  min series , when there are 'min' quantity of bars or greater, within a 'qty' set of bars.
#   ex. if there are 12 min bars, within 15 qty bars.

AddLabel(1, "MVP qtys " + momen_min + "/" + momen_max, Color.cyan);

# --------------------------------
# nested fold.
#  test if  x min bars, or more, are true , out of  y qty bars
#  loop1 , start at current bar, loops to future bars.
#  loop2 , on each bar of loop1, it looks back at 'momentum_qty' quantity of bars and counts the times chgup is true.
#    when done, if the count is > momentum_min, then a 1 is passed on to loop1.
#    if momupx > 0, then at least 1 valid series was found, to go across the bar.

#   add this to remove errors on last few bars, when bar is within (min-1) bars to the last bar,
#     while  !isnan( getvalue(close, -loop1) )

def momupx = fold loop1 = 0 to momen_max
with one
while  !isnan( getvalue(close, -loop1) )
do one + if (fold loop2 = 0 to momen_max
         with two
         do two + if GetValue(chgup , (-loop1 + loop2) ) then 1 else 0) >= momen_min then 1 else 0;

# was there at least 1 min series found ?
def momup = if momupx > 0 then 1 else 0;

# line under bars
#def offset1 = 0.999;
def offset1 = 1.0;
def htper = 0.2;
def cldht = round( (htper/100) * close, 1 );
def cldtop = if !momup[1] and momup then (low * offset1) else if momup then cldtop[1] else na;
def cldbot = cldtop - cldht;
# addcloud(cldtop, cldbot, color.cyan, color.cyan);

input momen_series_horz_line = yes;
plot ddd = if momen_series_horz_line then cldtop else na;
ddd.setlineweight(2);
ddd.SetDefaultColor(Color.light_gray);


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

input OOOOOO_Volume_OOOOOOO = yes;

# 2... Volume - The volume has increased over the past 15 days by 20% to 25%.
#  the 15 day average daily volume is 20% or greater than the 50 day average.

input volume_increase_percent = 20.0;
def vip = volume_increase_percent/100;

#input vol_qty = 15;
#input vol_min = 12;
#def vol_max = series_max;
#def vol_min = series_min;

input vol_avg_short_len = 15;
input vol_avg_long_len = 50;
def vol_avgshort = average(volume, vol_avg_short_len);
def vol_avglong = average(volume, vol_avg_long_len);


# compare vol15avg to (vol50avg * x%)
def volupx = if ( vol_avgshort > (vol_avglong * (1 + vip)) ) then 1 else 0;
def volup = volupx;

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

input OOOOOO_Price_OOOOOOO = yes;

# 3... Price - The price is up at least 20% over the past 15 days.

#input price_increase_percent = 20.0;
input price_increase_percent = 6.0;
def prp = price_increase_percent/100;


#input pr_max = 15;
#input pr_min = 12;
def pr_max = series_max;
def pr_min = series_min;

input price_avg_short_len = 15;
input price_avg_long_len = 50;
def pr_avgshort = average(close, price_avg_short_len);
def pr_avglong = average(close, price_avg_long_len);

def prupx =  if ( pr_avgshort > (pr_avglong * (1 + prp)) ) then 1 else 0;
def prup = prupx;

# //////////////////////////////////////
# //////////////////////////////////////

# draw squares, above candles, when a cond is true
#  -- when candle is part of a min momen series

# colored squares, above the candles:
#  Gray - Momen requirement met.
#  Blue - Momen and price requirement met.
#  Yellow - Momen and vol requirement met.
#  Green  - Momen and vol and price requirement met.



def mom = (momup and !volup and !prup);
def mompr = (momup and !volup and prup);
def momvol = (momup and volup and !prup);
def momvolpr = (momup and volup and prup);

#def sqr = (momup or volup or prup);
def sqr = (mom or mompr or momvol or momvolpr);

# //////////////////////////////////////

# plot a square above candles
plot t = if sqr then (high * (1 + (1*vert))) else na;
t.DefineColor("cmom", color.light_gray);
t.DefineColor("cmompr", color.blue);
t.DefineColor("cmomvol", color.yellow);
t.DefineColor("cmomvolpr", color.green);
t.DefineColor("cnon", color.current);
t.AssignValueColor(
      if momvolpr then t.color("cmomvolpr")
 else if momvol then t.color("cmomvol")
 else if mompr then t.color("cmompr")
 else if mom then t.color("cmom")
 else t.color("cnon"));
t.SetPaintingStrategy(PaintingStrategy.SQUARES);
t.SetLineWeight(4);

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


# legend
input show_color_legend = yes;
input legend_bar_offset = 4;
input legend_vert_percent = 97;
def v = (legend_vert_percent/100) * (close[legend_bar_offset]);

def k = !isnan(close[legend_bar_offset]) and isnan(close[(legend_bar_offset-1)]);
addchartbubble(show_color_legend and k, v, "Gray - Momen", color.light_gray, yes);
addchartbubble(show_color_legend and k, v, "Blue - Momen, price", color.blue, yes);
addchartbubble(show_color_legend and k, v, "Yellow - Momen, vol", color.yellow, yes);
addchartbubble(show_color_legend and k, v, "Green - Momen, vol, price", color.green, yes);



# test data , show test squares below the candles
input test_momen_series_quantities = no;
# show counts of momen min series
plot mx = if test_momen_series_quantities then momupx else na;
mx.SetPaintingStrategy(PaintingStrategy.VALUES_below);
mx.SetDefaultColor(Color.WHITE);

input test_momen_up_lower_gray = no;
plot my = if (test_momen_up_lower_gray and momup) then (low * (1 - (1*vert))) else na;
my.SetDefaultColor(Color.light_gray);
my.SetPaintingStrategy(PaintingStrategy.SQUARES);
my.SetLineWeight(4);

input test_volume_up_lower_purple = no;
plot vy = if (test_volume_up_lower_purple and volup) then (low * (1 - (2*vert))) else na;
vy.SetDefaultColor(Color.magenta);
vy.SetPaintingStrategy(PaintingStrategy.SQUARES);
vy.SetLineWeight(4);

input test_price_up_lower_blue = no;
plot py = if (test_price_up_lower_blue and prup) then (low * (1 - (3*vert))) else na;
py.SetDefaultColor(Color.blue);
py.SetPaintingStrategy(PaintingStrategy.SQUARES);
py.SetLineWeight(4);

input test_all_up = no;
plot all = if (test_all_up and momvolpr) then (low * (1 - (4*vert))) else na;
all.SetDefaultColor(Color.green);
all.SetPaintingStrategy(PaintingStrategy.SQUARES);
all.SetLineWeight(4);


input test_price_average_lines = no;
plot prs = if test_price_average_lines then pr_avgshort else na;
plot prl = if test_price_average_lines then pr_avglong else na;
prs.SetDefaultColor(Color.green);
prl.SetDefaultColor(Color.magenta);
#

volume average lines, for testing
Code:
# volavg_01
input vol_avgshortlen = 15;
input vol_avglonglen = 50;
def vol_avgshort = average(volume, vol_avgshortlen);
def vol_avglong = average(volume, vol_avglonglen);
plot z1 = vol_avgshort;
plot z2 = vol_avglong;
z1.SetDefaultColor(Color.yellow);
z2.SetDefaultColor(Color.cyan);
#

View attachment 11702
hal_mvp hal_fold
so smart, thank you
 

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

here is my version of MVP
it draws squares above the candles, depending on 3 conditions.

momentum up is when close is > previous close, for the min bars, within a max series.
volume up is determined when volume average(15) > (volume average(50) * 20%)
price up is determined when price average(15) > (price average(50) * 6%). ( i changed it from 20% to 6%, because price rarely rose 20%, )

can show a color legend to the right of last candle.
a gray horizontal line is drawn when the momentum condition is true.

test data,
...can draw colored squares below the candles, for each condition.
...can show price average lines
...a separate study will show volume average lines

Ruby:
# mvp_01

# -----------------
# halcyonguy
# 21-08-25
# -----------------

# Momentum, Volume and Price (MVP)
 #https://usethinkscript.com/threads/ants-%E2%80%94-momentum-volume-and-price-mvp.7497/
#I saw this very interesting custom indicator on TradingView.
#https://www.tradingview.com/script/uEaFv7tm-Ants-Momentum-Volume-and-Price-MVP/
#The Ants indicator is based on the research of David Ryan, three-time winner of the U.S. Investing Championship. David came up with the idea for the indicator while managing the New USA Growth Fund at William O’Neil + Company. David was interested to understand what drove some stocks higher once they were extended from their most recent base, while others had only moderate moves up.

#What David found during his research was that stocks making the biggest moves often had consistent buying on volume over a period of 12 to 15 trading days. Stocks with these characteristics may be under institutional accumulation, where it may take days to weeks to fill a position.

# — Momentum, Volume And Price ( MVP ) —

# The Ants indicator looks for the following:
#  1... Momentum - The stock is up at least 12 of the past 15 days.
#  2... Volume - The volume has increased over the past 15 days by 20% to 25%.
#  3... Price - The price is up at least 20% over the past 15 days.

# colored squares, above the candles:
#  Gray - Momen requirement met.
#  Blue - Momen and price requirement met.
#  Yellow - Momen and vol requirement met.
#  Green - Momen and vol and price requirement met.

#/////////////////////////////////////

def na = Double.NaN;
def bn = barnumber();

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

input OOOOOO_Momentum_OOOOOOO = yes;
# MVP
# 1... Momentum - The stock is up at least 12 of the past 15 days.
#  it tests if current bar close > previous close

input series_max = 15;
input series_min = 12;
def momen_max = series_max;
def momen_min = series_min;
#input momentum_qty = 15;
#input momentum_min = 12;

def chgup = close > close[1];

def squares_price_offset = 0.02;
def vert = squares_price_offset;

#  min series , when there are 'min' quantity of bars or greater, within a 'qty' set of bars.
#   ex. if there are 12 min bars, within 15 qty bars.

AddLabel(1, "MVP qtys " + momen_min + "/" + momen_max, Color.cyan);

# --------------------------------
# nested fold.
#  test if  x min bars, or more, are true , out of  y qty bars
#  loop1 , start at current bar, loops to future bars.
#  loop2 , on each bar of loop1, it looks back at 'momentum_qty' quantity of bars and counts the times chgup is true.
#    when done, if the count is > momentum_min, then a 1 is passed on to loop1.
#    if momupx > 0, then at least 1 valid series was found, to go across the bar.

#   add this to remove errors on last few bars, when bar is within (min-1) bars to the last bar,
#     while  !isnan( getvalue(close, -loop1) )

def momupx = fold loop1 = 0 to momen_max
with one
while  !isnan( getvalue(close, -loop1) )
do one + if (fold loop2 = 0 to momen_max
         with two
         do two + if GetValue(chgup , (-loop1 + loop2) ) then 1 else 0) >= momen_min then 1 else 0;

# was there at least 1 min series found ?
def momup = if momupx > 0 then 1 else 0;

# line under bars
#def offset1 = 0.999;
def offset1 = 1.0;
def htper = 0.2;
def cldht = round( (htper/100) * close, 1 );
def cldtop = if !momup[1] and momup then (low * offset1) else if momup then cldtop[1] else na;
def cldbot = cldtop - cldht;
# addcloud(cldtop, cldbot, color.cyan, color.cyan);

input momen_series_horz_line = yes;
plot ddd = if momen_series_horz_line then cldtop else na;
ddd.setlineweight(2);
ddd.SetDefaultColor(Color.light_gray);


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

input OOOOOO_Volume_OOOOOOO = yes;

# 2... Volume - The volume has increased over the past 15 days by 20% to 25%.
#  the 15 day average daily volume is 20% or greater than the 50 day average.

input volume_increase_percent = 20.0;
def vip = volume_increase_percent/100;

#input vol_qty = 15;
#input vol_min = 12;
#def vol_max = series_max;
#def vol_min = series_min;

input vol_avg_short_len = 15;
input vol_avg_long_len = 50;
def vol_avgshort = average(volume, vol_avg_short_len);
def vol_avglong = average(volume, vol_avg_long_len);


# compare vol15avg to (vol50avg * x%)
def volupx = if ( vol_avgshort > (vol_avglong * (1 + vip)) ) then 1 else 0;
def volup = volupx;

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

input OOOOOO_Price_OOOOOOO = yes;

# 3... Price - The price is up at least 20% over the past 15 days.

#input price_increase_percent = 20.0;
input price_increase_percent = 6.0;
def prp = price_increase_percent/100;


#input pr_max = 15;
#input pr_min = 12;
def pr_max = series_max;
def pr_min = series_min;

input price_avg_short_len = 15;
input price_avg_long_len = 50;
def pr_avgshort = average(close, price_avg_short_len);
def pr_avglong = average(close, price_avg_long_len);

def prupx =  if ( pr_avgshort > (pr_avglong * (1 + prp)) ) then 1 else 0;
def prup = prupx;

# //////////////////////////////////////
# //////////////////////////////////////

# draw squares, above candles, when a cond is true
#  -- when candle is part of a min momen series

# colored squares, above the candles:
#  Gray - Momen requirement met.
#  Blue - Momen and price requirement met.
#  Yellow - Momen and vol requirement met.
#  Green  - Momen and vol and price requirement met.



def mom = (momup and !volup and !prup);
def mompr = (momup and !volup and prup);
def momvol = (momup and volup and !prup);
def momvolpr = (momup and volup and prup);

#def sqr = (momup or volup or prup);
def sqr = (mom or mompr or momvol or momvolpr);

# //////////////////////////////////////

# plot a square above candles
plot t = if sqr then (high * (1 + (1*vert))) else na;
t.DefineColor("cmom", color.light_gray);
t.DefineColor("cmompr", color.blue);
t.DefineColor("cmomvol", color.yellow);
t.DefineColor("cmomvolpr", color.green);
t.DefineColor("cnon", color.current);
t.AssignValueColor(
      if momvolpr then t.color("cmomvolpr")
 else if momvol then t.color("cmomvol")
 else if mompr then t.color("cmompr")
 else if mom then t.color("cmom")
 else t.color("cnon"));
t.SetPaintingStrategy(PaintingStrategy.SQUARES);
t.SetLineWeight(4);

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


# legend
input show_color_legend = yes;
input legend_bar_offset = 4;
input legend_vert_percent = 97;
def v = (legend_vert_percent/100) * (close[legend_bar_offset]);

def k = !isnan(close[legend_bar_offset]) and isnan(close[(legend_bar_offset-1)]);
addchartbubble(show_color_legend and k, v, "Gray - Momen", color.light_gray, yes);
addchartbubble(show_color_legend and k, v, "Blue - Momen, price", color.blue, yes);
addchartbubble(show_color_legend and k, v, "Yellow - Momen, vol", color.yellow, yes);
addchartbubble(show_color_legend and k, v, "Green - Momen, vol, price", color.green, yes);



# test data , show test squares below the candles
input test_momen_series_quantities = no;
# show counts of momen min series
plot mx = if test_momen_series_quantities then momupx else na;
mx.SetPaintingStrategy(PaintingStrategy.VALUES_below);
mx.SetDefaultColor(Color.WHITE);

input test_momen_up_lower_gray = no;
plot my = if (test_momen_up_lower_gray and momup) then (low * (1 - (1*vert))) else na;
my.SetDefaultColor(Color.light_gray);
my.SetPaintingStrategy(PaintingStrategy.SQUARES);
my.SetLineWeight(4);

input test_volume_up_lower_purple = no;
plot vy = if (test_volume_up_lower_purple and volup) then (low * (1 - (2*vert))) else na;
vy.SetDefaultColor(Color.magenta);
vy.SetPaintingStrategy(PaintingStrategy.SQUARES);
vy.SetLineWeight(4);

input test_price_up_lower_blue = no;
plot py = if (test_price_up_lower_blue and prup) then (low * (1 - (3*vert))) else na;
py.SetDefaultColor(Color.blue);
py.SetPaintingStrategy(PaintingStrategy.SQUARES);
py.SetLineWeight(4);

input test_all_up = no;
plot all = if (test_all_up and momvolpr) then (low * (1 - (4*vert))) else na;
all.SetDefaultColor(Color.green);
all.SetPaintingStrategy(PaintingStrategy.SQUARES);
all.SetLineWeight(4);


input test_price_average_lines = no;
plot prs = if test_price_average_lines then pr_avgshort else na;
plot prl = if test_price_average_lines then pr_avglong else na;
prs.SetDefaultColor(Color.green);
prl.SetDefaultColor(Color.magenta);
#

volume average lines, for testing
Code:
# volavg_01
input vol_avgshortlen = 15;
input vol_avglonglen = 50;
def vol_avgshort = average(volume, vol_avgshortlen);
def vol_avglong = average(volume, vol_avglonglen);
plot z1 = vol_avgshort;
plot z2 = vol_avglong;
z1.SetDefaultColor(Color.yellow);
z2.SetDefaultColor(Color.cyan);
#

View attachment 11702
hal_mvp hal_fold
Can someone help to modify the above script by @halcyonguy to draw a line to find the lowest low when the square begins, and draw a line on the highest high on the candle when the square ends? and then draw a line between the range 25%, 50% ,75% like the fibonacci retracement? Thank you!

https://usethinkscript.com/threads/ants-—-momentum-volume-and-price-mvp.7497/#post-74080
 
Last edited by a moderator:
Can someone help to modify the above script by @halcyonguy to draw a line to find the lowest low when the square begins, and draw a line on the highest high on the candle when the square ends? and then draw a line between the range 25%, 50% ,75% like the fibonacci retracement? Thank you!

https://usethinkscript.com/threads/ants-—-momentum-volume-and-price-mvp.7497/#post-74080

MVP fib lines

this looks at the bars during a series of squares,
.finds the lowest low and highest high,
..then draws a diagonal line between them.
then draws up to 4 horizontal lines, based on 4 inputs.
.set % to 0 to ignore it


Code:
#mvp_ants_01_sqr_fibs

#https://usethinkscript.com/threads/add-range-lines-to-script.20319/
#Add Range Lines To Script

#halcyonguy said:
#here is my version of MVP
#https://usethinkscript.com/threads/ants-—-momentum-volume-and-price-mvp.7497/#post-74080

#-------------------------------
#here is my version of MVP
#it draws squares above the candles, depending on 3 conditions.

#momentum up is when close is > previous close, for the min bars, within a max series.
#volume up is determined when volume average(15) > (volume average(50) * 20%)
#price up is determined when price average(15) > (price average(50) * 6%). ( i changed it from 20% to 6%, because price rarely rose 20%, )

#can show a color legend to the right of last candle.
#a gray horizontal line is drawn when the momentum condition is true.

#test data,
#...can draw colored squares below the candles, for each condition.
#...can show price average lines
#...a separate study will show volume average lines


# — Momentum, Volume And Price ( MVP ) —

# The Ants indicator looks for the following:
#  1... Momentum - The stock is up at least 12 of the past 15 days.
#  2... Volume - The volume has increased over the past 15 days by 20% to 25%.
#  3... Price - The price is up at least 20% over the past 15 days.

# colored squares, above the candles:
#  Gray - Momen requirement met.
#  Blue - Momen and price requirement met.
#  Yellow - Momen and vol requirement met.
#  Green - Momen and vol and price requirement met.

#/////////////////////////////////////

def na = Double.NaN;
def bn = BarNumber();

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

input OOOOOO_Momentum_OOOOOOO = yes;
# MVP
# 1... Momentum - The stock is up at least 12 of the past 15 days.
#  it tests if current bar close > previous close

input series_max = 15;
input series_min = 12;
def momen_max = series_max;
def momen_min = series_min;
#input momentum_qty = 15;
#input momentum_min = 12;

def chgup = close > close[1];

def squares_price_offset = 0.02;
def vert = squares_price_offset;

#  min series , when there are 'min' quantity of bars or greater, within a 'qty' set of bars.
#   ex. if there are 12 min bars, within 15 qty bars.

AddLabel(1, "MVP qtys " + momen_min + "/" + momen_max, Color.CYAN);

# --------------------------------
# nested fold.
#  test if  x min bars, or more, are true , out of  y qty bars
#  loop1 , start at current bar, loops to future bars.
#  loop2 , on each bar of loop1, it looks back at 'momentum_qty' quantity of bars and counts the times chgup is true.
#    when done, if the count is > momentum_min, then a 1 is passed on to loop1.
#    if momupx > 0, then at least 1 valid series was found, to go across the bar.

#   add this to remove errors on last few bars, when bar is within (min-1) bars to the last bar,
#     while  !isnan( getvalue(close, -loop1) )

def momupx = fold loop1 = 0 to momen_max
with one
while  !IsNaN( GetValue(close, -loop1) )
do one + if (fold loop2 = 0 to momen_max
         with two
         do two + if GetValue(chgup , (-loop1 + loop2) ) then 1 else 0) >= momen_min then 1 else 0;

# was there at least 1 min series found ?
def momup = if momupx > 0 then 1 else 0;

# line under bars
#def offset1 = 0.999;
def offset1 = 1.0;
def htper = 0.2;
def cldht = Round( (htper / 100) * close, 1 );
def cldtop = if !momup[1] and momup then (low * offset1) else if momup then cldtop[1] else na;
def cldbot = cldtop - cldht;
# addcloud(cldtop, cldbot, color.cyan, color.cyan);

input series_horz_line = no;
plot sqr_horz = if series_horz_line then cldtop else na;
# chg  ddd to sqr_horz
sqr_horz.SetLineWeight(2);
sqr_horz.SetDefaultColor(Color.LIGHT_GRAY);
#sqr_horz.SetDefaultColor(Color.yellow);

# true during a series of squares
def sqrs = if !isnan(cldtop) then 1 else 0;

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

input OOOOOO_Volume_OOOOOOO = yes;

# 2... Volume - The volume has increased over the past 15 days by 20% to 25%.
#  the 15 day average daily volume is 20% or greater than the 50 day average.

input volume_increase_percent = 20.0;
def vip = volume_increase_percent / 100;

#input vol_qty = 15;
#input vol_min = 12;
#def vol_max = series_max;
#def vol_min = series_min;

input vol_avg_short_len = 15;
input vol_avg_long_len = 50;
def vol_avgshort = Average(volume, vol_avg_short_len);
def vol_avglong = Average(volume, vol_avg_long_len);


# compare vol15avg to (vol50avg * x%)
def volupx = if ( vol_avgshort > (vol_avglong * (1 + vip)) ) then 1 else 0;
def volup = volupx;

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

input OOOOOO_Price_OOOOOOO = yes;

# 3... Price - The price is up at least 20% over the past 15 days.

#input price_increase_percent = 20.0;
input price_increase_percent = 6.0;
def prp = price_increase_percent / 100;


#input pr_max = 15;
#input pr_min = 12;
def pr_max = series_max;
def pr_min = series_min;

input price_avg_short_len = 15;
input price_avg_long_len = 50;
def pr_avgshort = Average(close, price_avg_short_len);
def pr_avglong = Average(close, price_avg_long_len);

def prupx =  if ( pr_avgshort > (pr_avglong * (1 + prp)) ) then 1 else 0;
def prup = prupx;

# //////////////////////////////////////
# //////////////////////////////////////

# draw squares, above candles, when a cond is true
#  -- when candle is part of a min momen series

# colored squares, above the candles:
#  Gray - Momen requirement met.
#  Blue - Momen and price requirement met.
#  Yellow - Momen and vol requirement met.
#  Green  - Momen and vol and price requirement met.



def mom = (momup and !volup and !prup);
def mompr = (momup and !volup and prup);
def momvol = (momup and volup and !prup);
def momvolpr = (momup and volup and prup);

#def sqr = (momup or volup or prup);
def sqr = (mom or mompr or momvol or momvolpr);

# //////////////////////////////////////

# plot a square above candles
plot t = if sqr then (high * (1 + (1 * vert))) else na;
t.DefineColor("cmom", Color.LIGHT_GRAY);
t.DefineColor("cmompr", Color.BLUE);
t.DefineColor("cmomvol", Color.YELLOW);
t.DefineColor("cmomvolpr", Color.GREEN);
t.DefineColor("cnon", Color.CURRENT);
t.AssignValueColor(
      if momvolpr then t.Color("cmomvolpr")
 else if momvol then t.Color("cmomvol")
 else if mompr then t.Color("cmompr")
 else if mom then t.Color("cmom")
 else t.Color("cnon"));
t.SetPaintingStrategy(PaintingStrategy.SQUARES);
t.SetLineWeight(4);

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


# legend
input show_color_legend = yes;
input legend_bar_offset = 4;
input legend_vert_percent = 97;
def v = (legend_vert_percent / 100) * (close[legend_bar_offset]);

def k = !IsNaN(close[legend_bar_offset]) and IsNaN(close[(legend_bar_offset - 1)]);
AddChartBubble(show_color_legend and k, v, "Gray - Momen", Color.LIGHT_GRAY, yes);
AddChartBubble(show_color_legend and k, v, "Blue - Momen, price", Color.BLUE, yes);
AddChartBubble(show_color_legend and k, v, "Yellow - Momen, vol", Color.YELLOW, yes);
AddChartBubble(show_color_legend and k, v, "Green - Momen, vol, price", Color.GREEN, yes);


# test data , show test squares below the candles
input test_momen_series_quantities = no;
# show counts of momen min series
plot mx = if test_momen_series_quantities then momupx else na;
mx.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
mx.SetDefaultColor(Color.WHITE);

input test_momen_up_lower_gray = no;
plot my = if (test_momen_up_lower_gray and momup) then (low * (1 - (1 * vert))) else na;
my.SetDefaultColor(Color.LIGHT_GRAY);
my.SetPaintingStrategy(PaintingStrategy.SQUARES);
my.SetLineWeight(4);

input test_volume_up_lower_purple = no;
plot vy = if (test_volume_up_lower_purple and volup) then (low * (1 - (2 * vert))) else na;
vy.SetDefaultColor(Color.MAGENTA);
vy.SetPaintingStrategy(PaintingStrategy.SQUARES);
vy.SetLineWeight(4);

input test_price_up_lower_blue = no;
plot py = if (test_price_up_lower_blue and prup) then (low * (1 - (3 * vert))) else na;
py.SetDefaultColor(Color.BLUE);
py.SetPaintingStrategy(PaintingStrategy.SQUARES);
py.SetLineWeight(4);

input test_all_up = no;
plot all = if (test_all_up and momvolpr) then (low * (1 - (4 * vert))) else na;
all.SetDefaultColor(Color.GREEN);
all.SetPaintingStrategy(PaintingStrategy.SQUARES);
all.SetLineWeight(4);


input test_price_average_lines = no;
plot prs = if test_price_average_lines then pr_avgshort else na;
plot prl = if test_price_average_lines then pr_avglong else na;
prs.SetDefaultColor(Color.GREEN);
prl.SetDefaultColor(Color.MAGENTA);

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

# true during , horz line during squares , sqr_horz
#def sqrs = if !isnan(sqr_horz) then 1 else 0;
def sqr_first = (sqrs and !sqrs[1]);
def sqr_last = (sqrs and !sqrs[-1]);
def n = 200;

# find lowest , highest, during sqrs
# look for uptrends. low will be before high
def sqrhibn;
def sqrlobn;
def sqrhi;
def sqrlo;
def slope;
if bn == 1 then {
 sqrhibn = 0;
 sqrlobn = 0;
 sqrhi = 0;
 sqrlo = 0;
 slope = 0;
} else if sqr_first then {
# 1st bar in sqr seq. run loops to find hi and lo

 sqrhi = fold a = 0 to n
  with b = high
  while getvalue(sqrs, -a)
  do max(b,getvalue(high,-a));

 sqrlo =  fold c = 0 to n
  with d = low
  while getvalue(sqrs, -c)
  do min(d,getvalue(low,-c));

 sqrhibn = bn + (fold e = 0 to n
  with f
  while (getvalue(high,-e) != sqrhi)
  do f + 1);

 sqrlobn = bn + (fold g = 0 to n
  with h
  while (getvalue(low,-g) != sqrlo)
  do h + 1);

 slope = (sqrhi - sqrlo)/(sqrhibn - sqrlobn);

} else if sqrs then {
 sqrhibn = sqrhibn[1];
 sqrlobn = sqrlobn[1];
 sqrhi = sqrhi[1];
 sqrlo = sqrlo[1];
 slope = slope[1];

} else {
 sqrhibn = 0;
 sqrlobn = 0;
 sqrhi = 0;
 sqrlo = 0;
 slope = 0;
}

input diag_level1_per = 25.0;
input diag_level2_per = 50.0;
input diag_level3_per = 75.0;
input diag_level4_per = 0.0;

def sqr_diag = if bn == sqrlobn then low
 else if bn >= sqrlobn and bn <= sqrhibn then sqr_diag[1] + slope
 else na;

input show_diag_line_and_levels = yes;
plot z1 = if show_diag_line_and_levels then sqr_diag else na;
z1.SetDefaultColor(Color.cyan);


def level0 = if bn == 1 or isnan(close) then na
 else if sqr_first then sqrlo
 else level0[1];
plot zl0 = if show_diag_line_and_levels then level0 else na;
zl0.AssignValueColor(if sqrs then color.cyan else color.magenta);

def level5 = if bn == 1 or isnan(close) then na
 else if sqr_first then sqrhi
 else level5[1];
plot zl5 = level5;
zl5.AssignValueColor(if sqrs then color.cyan else color.magenta);

def level1 = if bn == 1 or isnan(close) or diag_level1_per == 0 then na
 else if sqr_first then (sqrlo + ((sqrhi-sqrlo)*(diag_level1_per/100)))
 else level1[1];
plot zl1 = if show_diag_line_and_levels then level1 else na;
zl1.AssignValueColor(if sqrs then color.cyan else color.magenta);

def level2 = if bn == 1 or isnan(close) or diag_level1_per == 0 then na
 else if sqr_first then (sqrlo + ((sqrhi-sqrlo)*(diag_level2_per/100)))
 else level2[1];
plot zl2 = if show_diag_line_and_levels then level2 else na;
zl2.AssignValueColor(if sqrs then color.cyan else color.magenta);

def level3 = if bn == 1 or isnan(close) or diag_level1_per == 0 then na
 else if sqr_first then (sqrlo + ((sqrhi-sqrlo)*(diag_level3_per/100)))
 else level3[1];
plot zl3 = if show_diag_line_and_levels then level3 else na;
zl3.AssignValueColor(if sqrs then color.cyan else color.magenta);

def level4 = if bn == 1 or isnan(close) or diag_level1_per == 0 then na
 else if sqr_first then (sqrlo + ((sqrhi-sqrlo)*(diag_level4_per/100)))
 else level4[1];
plot zl4 = if show_diag_line_and_levels then level1 else na;
zl4.AssignValueColor(if sqrs then color.cyan else color.magenta);


addchartbubble(0 , low*0.995,
 bn + "\n" +
 sqrhibn + "\n" +
 sqrlobn + "\n" +
 sqrhi + "\n" +
 sqrlo + "\n" 
, (if sqr_first then color.yellow else color.gray), no);
#
#
 

Attachments

  • img2.JPG
    img2.JPG
    94.4 KB · Views: 29
Somewhat late to the party here, but I was over at TradingView reading the comments on the original developer's submission and thought I would post it here for those whom might be interested:

2025-01-13 23.26.15 www.tradingview.com a87a812b034b.png


Do the "ANTS" repaint? Apparently so...But there is nothing wrong in this case because following up after the parade has passed still means there is potential profit to be had where the Institutions led the way...

Just my two cents...

Good Luck and Good Trading :cool:
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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