# Is there an Amibroker equivalent to the thinkscript fold function?

Is there a ready equivalent in afl for the fold function? I was trying to translate the following thinkscript
that uses nested folds. Or, do I just use loops etc?

``````
# 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 momentum_qty
with one
while  !isnan( getvalue(close, -loop1) )
do one + if (fold loop2 = 0 to momentum_qty
with two
do two + if GetValue(chgup , (-loop1 + loop2) ) then 1 else 0) >= momentum_min then 1 else 0;

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

``````

The thinkScript "fold" operator is used for iteration. In AFL, "for" and "while" are the iteration operators.

I haven't tried to understand the details of what this function is doing, but there's a good chance that a lot of it can be handled with AmiBroker's array processing and won't even require any looping. For example, to determine if a condition is true for X of the previous Y bars, you can do something like this:

``````condition = // your logic
isValid = Sum(condition, Y) >= X;
``````

In this case, we are checking to see if during any stretch of 15 bars, 12 or more were up days. That is, Cond1=Sum(C>Ref(C,-1),15)>=12. Note that this can refer to future bars.

Then loop back through and flag all these 15 bar sequences that met this condition. These will be flagged as momentum bars.

This is an attempt to duplicate the MarketSmith (IBD MarketSurge) ANT indicator.

I suggest reading the description and comments at the above link referenced in your post.
It seems that the indicator must also take volume and ROC into account.

For heaven's sake, I have read the post. The problematic portion of the indicator is the momentum piece, the price and volume portions are more trivial.

Per mradtke's suggestion, I made a first draft using arrays. The results still do not match the referenced thinkscript, but they overlap. I will try to reconcile the two versions.

Here is my draft of the indicator - any suggestions would be appreciated.

``````//ANTS Indicator

//\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$
/*
β 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%.
Note: thinkscript uses 6% instead of 20%
3) Price - The price is up at least 20% over the past 15 days.

Gray Ants 	- Momentum requirement met.
Blue Ants 	- Momentum and price requirements met.
Yellow Ants - Momentum and volume requirements met.
Green Ants 	- Momentum, volume and price requirements met.

*/
//\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$

//\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$
//*********************    ************************
BI=BarIndex();
Chgup=C>Ref(C,-1);
Cond1=Sum(Chgup,15)>=12;									//Momentum
Cond2=MA(Close,15)>1.20*MA(Close,50);						//Price - thinkscript uses 6% instead of 20%
Cond3=(MA(Volume,15)>1.20*MA(Volume,50));//					//Volume -

fvbi = Status( "firstvisiblebarindex" );
lvbi = Status( "lastvisiblebarindex" );
count=0;

Plot( C, "Price", colorDefault, stylecandle | styleThick );

// ***************** ITERATE THROUGH BARS  *********************************************
for( i = fvbi; i <= Min( lvbi, BarCount - 1 ) ; i++ )
{
if( cond1[i] )			//Momentum
{

Count[i]=Count[i-1]=Count[i-2]=Count[i-3]=Count[i-4]=Count[i-5]=Count[i-6]=count[i-7]=Count[i-8]=Count[i-9]=Count[i-10]=Count[i-11]=Count[i-12]=Count[i-13]=Count[i-14]=1;  // Assign 1 to all 15 bars used in calculation
}
if( cond2[i] )       //Price
{
count[i]=count[i]+2;
}
if( cond3[i] )		//Volume
{
count[i]=count[i]+3;
}

}
// 1) Gray Ants 	- Momentum requirement met. 					Count=1 (Cond1)
// 2) Blue Ants 	- Momentum and price requirements met. 			Count=3	(Cond1 & Cond2)
// 3) Yellow Ants 	- Momentum and volume requirements met.			Count=4	(Cond1 & Cond3)
// 4) Green Ants 	- Momentum, volume and price requirements met.	Count=6 (Cond1 & Cond2 & Cond3)

color1=colorRose;
color2=ColorBlend(colorblue,colorWhite,.40);
color3=colorYellow;
color4=ColorBlend(ColorRGB(0,255,0),colorWhite,.20);//lime
//color4=Colorlime;//lime

PlotShapes( IIf( Count==1, shapesmallsquare, 0 ), color1,0, High+2 );
PlotShapes( IIf( Count==3, shapesmallsquare, 0 ), color2,0, High+2 );
PlotShapes( IIf( Count==4, shapecircle, 0 ), color3,0, High+3 );
PlotShapes( IIf( Count==6, shapeCircle, 0 ), color4,0, High+3 );

``````

Sorry. Here is a minor correction.

``````//ANTS Indicator

//\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$
/*
β 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%.
Note: thinkscript uses 6% instead of 20%
3) Price - The price is up at least 20% over the past 15 days.

Gray Ants 	- Momentum requirement met.
Blue Ants 	- Momentum and price requirements met.
Yellow Ants - Momentum and volume requirements met.
Green Ants 	- Momentum, volume and price requirements met.

*/
//\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$

//\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$
//*********************    ************************
BI=BarIndex();
Chgup=C>Ref(C,-1);
Cond1=Sum(Chgup,15)>=12;									//Momentum
Cond2=MA(Close,15)>1.20*MA(Close,50);						//Price - thinkscript uses 6% instead of 20%
Cond3=(MA(Volume,15)>1.20*MA(Volume,50));//					//Volume -

fvbi = Status( "firstvisiblebarindex" );
lvbi = Status( "lastvisiblebarindex" );
count1=0;
count2=0;
count3=0;

Plot( C, "Price", colorDefault, stylecandle | styleThick );

// ***************** ITERATE THROUGH BARS  *********************************************
for( i = fvbi; i <= Min( lvbi, BarCount - 1 ) ; i++ )
{
if( cond1[i] )			//Momentum
{

count1[i]=count1[i-1]=count1[i-2]=count1[i-3]=count1[i-4]=count1[i-5]=count1[i-6]=count1[i-7]=count1[i-8]=count1[i-9]=count1[i-10]=count1[i-11]=count1[i-12]=count1[i-13]=count1[i-14]=1;  // Assign 1 to all 15 bars used in calculation
}
if( cond2[i] )       //Price
{
count2[i]=count2[i]+2;
}
if( cond3[i] )		//Volume
{
count3[i]=count3[i]+3;
}

}
// 1) Gray Ants 	- Momentum requirement met. 					Count=1 (Cond1)
// 2) Blue Ants 	- Momentum and price requirements met. 			Count=3	(Cond1 & Cond2)
// 3) Yellow Ants 	- Momentum and volume requirements met.			Count=4	(Cond1 & Cond3)
// 4) Green Ants 	- Momentum, volume and price requirements met.	Count=6 (Cond1 & Cond2 & Cond3)

color1=colorRose;
color2=ColorBlend(colorblue,colorWhite,.40);
color3=colorYellow;
color4=ColorBlend(ColorRGB(0,255,0),colorWhite,.20);//lime
//color4=Colorlime;//lime

Count4=Count1 + Count2 + Count3;

PlotShapes( IIf( Count4==1, shapesmallsquare, 0 ), color1,0, High+2 );
PlotShapes( IIf( Count4==3, shapesmallsquare, 0 ), color2,0, High+2 );
PlotShapes( IIf( Count4==4, shapecircle, 0 ), color3,0, High+3 );
PlotShapes( IIf( Count4==6, shapeCircle, 0 ), color4,0, High+3 );

``````

Here's my finalized version with an exploration.

``````//ANTS Indicator

//David Ryan: Spot Institutional Buying In Hot Stocks With The βAntsβ Indicator | IBD Live

//\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$
/*
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.
3) Volume - The volume has increased over the past 15 days by 20% to 25%.
Note: thinkscript uses 6% instead of 20%

Gray Ants 	- Momentum requirement met.
Blue Ants 	- Momentum and price requirements met.
Yellow Ants - Momentum and volume requirements met.
Green Ants 	- Momentum, volume and price requirements met.

*/
//\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$
//  *************************   Conditions   ****************************************

Chgup=C>Ref(C,-1);
Cond1=Sum(Chgup,15)>=12;									// 1) Momentum
Cond2=MA(Close,15)>1.20*MA(Close,50);						// 2) Price - thinkscript uses 6% instead of 20%
Cond3=(MA(Volume,15)>1.20*MA(Volume,50));//					// 3) Volume -
count1=count2=count3=count4=0;								// initialize counters

//\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$
// *********************** ITERATE THROUGH BARS  ************************************

for( i = 0; i < BarCount; i++ )
{

if( cond1[i] )																				//Momentum - Assign 1 to all 15 bars used in condition calculation
{
count1[i]=count1[i-1]=count1[i-2]=count1[i-3]=count1[i-4]=count1[i-5]=count1[i-6]
=count1[i-7]=count1[i-8]=count1[i-9]=count1[i-10]=count1[i-11]=count1[i-12]
=count1[i-13]=count1[i-14]=1;
}
if( cond2[i] )       																//Price -Add 2 to counter
{
count2[i]=count2[i]+2;
}
if( cond3[i] )																		//Volume - add 3 to counter
{
count3[i]=count3[i]+3;
}
count4[i]=count1[i]+count2[i]  +count3[i];												//Calculate sum
}

//\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$
//  ******************************  Plot   ******************************************

// 1) Gray Ants 	- Momentum requirement met. 					Count=1 (Cond1)
// 2) Blue Ants 	- Momentum and price requirements met. 			Count=3	(Cond1 & Cond2)
// 3) Yellow Ants 	- Momentum and volume requirements met.			Count=4	(Cond1 & Cond3)
//    Orange Ants   - Price and volume						        (Cond2 & Cond3)
// 4) Green Ants 	- Momentum, volume and price requirements met.	Count=6 (Cond1 & Cond2 & Cond3)

color1=colorlightgrey;
color2=ColorBlend(colorblue,colorWhite,.40);
color2=ColorRGB(108,172,228);
color3=colorYellow;
color4=ColorBlend(ColorRGB(0,255,0),colorWhite,.20);

Title =
encodeColor(colorwhite) +Name() + "  : "+FullName()+"   "+ Date() +"\n"+
EncodeColor(color1) +"   Gray Ants 	  	- Momentum"  +"\n"+
EncodeColor(color2) +"   Blue Ants     	- Momentum and price"  +"\n"+
EncodeColor(Color3) +"   Yellow Ants  	- Momentum and Volume"  +"\n"+
EncodeColor(Colorlightorange) +"   Orange Ants  	- Price and Volume"  +"\n"+
EncodeColor(Color4) +"   Green Ants 	- Momentum, volume and price";

Plot( C, "Price", colorDefault, stylecandle | styleThick );
PlotShapes( IIf( Count4==1, shapehollowsmallsquare, 0 ), color1,0, High,20 );
PlotShapes( IIf( Count4==3, shapehollowsmallsquare, 0 ), color2,0, High,20 );
PlotShapes( IIf( Count4==4, shapesmallsquare, 0 ), color3,0, High,20 );
plotShapes( IIf( Count4==5, shapesmallsquare, 0 ), colorlightorange,0, High,20 );
PlotShapes( IIf( Count4==6, shapesmallsquare, 0 ), color4,0, High,20 );

//\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$
//  *************************  Exploration  *****************************************

Filter=1;
//Filter=count4==6 or count4==4;

IIf(Count1==1, color1,colorWhite));
IIf(Count2==2, color2,colorWhite));
IIf(Count3==3, color3,colorWhite));
IIf(count4==1, color1,
IIf(count4==3, color2,
IIf(count4==4, color3,
IIf(count4==5, colorlightorange,
IIf(count4==6, color4, colorWhite))))));

``````

Hopefully this is behaving the way you expect. I noticed that your written description does not match the code, for example:

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

This code checks whether the 15-period MA is at least 20% above the 50-period MA. It has nothing to do with price movement over the past 15 days:

Cond2=MA(Close,15)>1.20*MA(Close,50);

The same discrepancy exists for Volume.

Good question. I was basing the calculation on the comment I saw in the usethinkscript post.

"@halcyonguy
BTW I asked the author of the tradingview indicator to clarify what he meant about the volume being 20% greater than 15 days ago, and since I wasn't sure. This is what he replied with....

You want the 15 day average daily volume to be 20% or greater than the preceding 50 day average."

He did a similar calculation on the price increase. So I am just using the usethinkscript logic.

Of course, the underlying code is not fully known so there is a degree of guessing involved.

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

//David Ryan: Spot Institutional Buying In Hot Stocks With The βAntsβ Indicator | IBD Live
//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;

/*
IIf(countmom==1, color1,colorWhite));
IIf(countpr==2, colorLightBlue,colorWhite));
IIf(countvol==5, colorlightOrange,colorWhite));
*/
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

``````

This Marketsurge indicator (If I understand it correctly) is still very curious since it references future data, so I'm unsure of its utility. However various David Ryan/IBD videos attribute its usefulness to understanding institutional accumulation in charts, although not an actual buy trigger.

The looping code can be replaced with the following ( referencing future bars)

``````
Chgup=C>Ref(C,-1);
Cond1=Sum(Chgup,15)>=12;
Condmom=IIf(Cond1==1,1,0)
OR IIf(Ref(Cond1==1,1),1,0)
OR IIf(Ref(Cond1==1,2),1,0)
OR IIf(Ref(Cond1==1,3),1,0)
OR IIf(Ref(Cond1==1,4),1,0)
OR IIf(Ref(Cond1==1,5),1,0)
OR IIf(Ref(Cond1==1,6),1,0)
OR IIf(Ref(Cond1==1,7),1,0)
OR IIf(Ref(Cond1==1,8),1,0)
OR IIf(Ref(Cond1==1,9),1,0)
OR IIf(Ref(Cond1==1,10),1,0)
OR IIf(Ref(Cond1==1,11),1,0)
OR IIf(Ref(Cond1==1,12),1,0)
OR IIf(Ref(Cond1==1,13),1,0)
OR IIf(Ref(Cond1==1,14),1,0);

Condpr=IIf(MA(Close,15)>1.06*MA(Close,50),2,0);;
Condvol=IIf((MA(Volume,15)>1.20*MA(Volume,50)),5,0);;//
Count4=condmom+condpr+condvol;``````
1 Like