Sorry, Made a few clumsy coding mistakes. Chart should now mirror results from the MVP usethinkscript code.
// MVP or ANT-like Indicator
// "ANTs" Concept originated with David Ryan
// Titled MVP Indicator in usethinkscript
//https://www.tradingview.com/script/uEaFv7tm-Ants-Momentum-Volume-and-Price-MVP/
//https://usethinkscript.com/threads/ants-%E2%80%94-momentum-volume-and-price-mvp.7497/
//David Ryan: Spot Institutional Buying In Hot Stocks With The βAntsβ Indicator | IBD Live
// https://www.youtube.com/watch?v=CvPDSMuezI8
//Note: MarketSurge code for ANTS indicator is not known
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
/*
The "Ants" indicator looks for the following:
1) Momentum - The stock is up at least 12 of the past 15 days.
2) Price - The price is up at least 20% over the past 15 days.
Note: Further defined in usethinkscript as the 15 day average daily price to be 20% or greater than the preceding 50 day average.
3) Volume - The volume has increased over the past 15 days by 20% to 25%.
Note: Further defined in usethinkscript as the 15 day average daily volume to be 20% or greater than the preceding 50 day average.
Note: thinkscript uses 6% increase instead of 20% as criteria
Gray Ants - Momentum requirement met.
Blue Ants - Momentum and price requirements met.
Yellow Ants - Momentum and volume requirements met.
Not defined - Price and volume.
Green Ants - Momentum, volume and price requirements met.
*/
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
// ************************* Conditions ****************************************
Chgup=C>Ref(C,-1);
Condmom=Sum(Chgup,15)>=12; // 1) Momentum
Condpr=MA(Close,15)>1.06*MA(Close,50); // 2) Price - thinkscript uses 6% instead of 20%
Condvol=(MA(Volume,15)>1.20*MA(Volume,50));// // 3) Volume -
countmom=countpr=countvol=count4=0; // initialize counters
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
// *********************** ITERATE THROUGH BARS ************************************
for( i = 0; i < BarCount; i++ )
{
if( condmom[i] ) //Momentum - add 1 to counter for all 15 bars used in condition calculation
{
countmom[i]=countmom[i-1]=countmom[i-2]=countmom[i-3]=countmom[i-4]=countmom[i-5]=countmom[i-6]
=countmom[i-7]=countmom[i-8]=countmom[i-9]=countmom[i-10]=countmom[i-11]=countmom[i-12]
=countmom[i-13]=countmom[i-14]=1;
}
if( condpr[i] ) //Price - add 2 to counter
{
countpr[i]=countpr[i]+2;
}
if( condvol[i] ) //Volume - add 5 to counter
{
countvol[i]=countvol[i]+5;
}
}
for( i = 0; i < BarCount; i++ )
{
count4[i]=countmom[i]+countpr[i]+countvol[i]; //Calculate sum
}
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
// ****************************** Plot ******************************************
// 1) Gray Ants - Momentum requirement met. Count4=1 (condmom) (1)
// 2) Blue Ants - Momentum and price requirements met. Count4=3 (condmom & condpr) (1+2)
// 3) Yellow Ants - Momentum and volume requirements met. Count4=6 (condmom & condvol) (1+5)
// Not plotted - Price and volume Count4=7 (condpr & condvol) (2+5)
// 4) Green Ants - Momentum, volume and price requirements met. Count4=8 (condmom & condpr & condvol) (1+2+5)
color1=colorlightgrey;
color2=ColorBlend(colorblue,colorWhite,.30);
color3=colorYellow;
color4=ColorBlend(ColorRGB(0,255,0),colorWhite,.50);
Title =
encodeColor(colorwhite) +Name() + " : "+FullName()+" "+ Date() +"\n"+
EncodeColor(color1) +" Gray - Momentum" +"\n"+
EncodeColor(color2) +" Blue - Momentum and price" +"\n"+
EncodeColor(Color3) +" Yellow - Momentum and Volume" +"\n"+
//EncodeColor(Colorlightorange) +" Orange - Price and Volume" +"\n"+
EncodeColor(Color4) +" Green - Momentum, volume and price";
Plot( C, "Price", colorDefault, stylecandle | styleThick ); //Candlestick chart
PlotShapes( IIf( Count4==1, shapesmallsquare, 0 ), color1,0, High,20 ); //Gray - Momentum requirement met.
PlotShapes( IIf( Count4==3, shapesmallsquare, 0 ), color2,0, High,20 ); //Blue - Momentum and price requirements met.
PlotShapes( IIf( Count4==6, shapesmallsquare, 0 ), color3,0, High,20 ); //Yellow - Momentum and volume requirements met.
//plotShapes( IIf( Count4==7, shapehollowsmallsquare, 0 ), colorlightorange,0, High,20 ); //Not plotted - price and volume conditions met
PlotShapes( IIf( Count4==8, shapesmallsquare, 0 ), color4,0, High,20 ); //Green - Momentum, volume and price requirements met
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
// ************************* Exploration *****************************************
Filter=1;
//Filter=count4==8;
/*
AddColumn(IIf(IsTrue(condmom),1,Null),"condmom",5.0,colorBlack,colorGreen);
AddColumn(countmom,"CountMom",5.0,colorDefault,
IIf(countmom==1, color1,colorWhite));
AddColumn(countpr,"Price",5.0,colorwhite,
IIf(countpr==2, colorLightBlue,colorWhite));
//AddColumn(IIf(IsTrue(condpr),1,Null),"condpr",5.0,colorBlack,colorblue);
AddColumn(countvol,"countvol",5.0,colorDefault,
IIf(countvol==5, colorlightOrange,colorWhite));
//AddColumn(IIf(IsTrue(condvol),1,Null),"condvol",5.0,colorBlack,colororange);
*/
AddColumn(count4,"Total", 5.0,colorDefault,
IIf(count4==1, color1, //Gray - Momentum requirement met.
IIf(count4==3, color2, //Blue - Momentum and price requirements met.
IIf(count4==5, colorlightorange, //volume only condition - not plotted
IIf(count4==6, color3, //Yellow - Momentum and volume requirements met.
IIf(count4==7, colorlightOrange, //price and volume conditions - not plotted
IIf(count4==8, color4, colorWhite))))))); //Green - Momentum, volume and price requirements met