Don't override Close array, was: Filter = Close>10

Friends,
I have noticed that when i use filter in exploration, there are a few tickers that make it through the criteria. For instance, if I apply a simple filter= Close>10 and run an exploration on all symbols. Most of the symbols under $10 are filtered out but there are a few that make it through, enough that its a distraction when I am seeing the final results. I have tried Filter= MA(Close,90)>10, Filter=Ref(Close, -1)>10 etc. also tried with High, low, open etc. But in all cases a few symbols make it through.

Does anyone know why? what am I doing wrong? I have scanned the search but didn't see this topic. The symbols that are making it through are: ABEO, ACHV, ACER, ABIO, etc. just to name a few.

I get paid data from Tiingo and graph clearly shows these symbols are below 10. just not sure why they are not getting filtered out.

Majority do get filtered out...

thanks
NR

Have you seen that the graph for e.g. ABIO clearly shows values greater 10.

So if you apply

Filter = C > 10;

for e.g. Range: "All Quotes" then of course it will output all those elements of array where ABIO was greater 10.

You don't mention which range you have set in analysis but if you want to output only at last bar of range then you have to set different range in analysis.

14

Alternatively you may add LastBarInRange flag via code:

Filter = C > 10 AND Status("LastBarInRange");

As aside make sure that Pad&align of Analysis settings - General tab is disabled or if you need Pad&align setting then make sure that the reference symbol's data is up-to-date.


Please also read here before next posts. Another mandatory read to be found here.


Final note:

AmiBroker works perfectly fine.

I have uploaded my code and output per your guidance: it is awaiting approval.
in that post, apologize: "f" got deleted - meant to start with "fxshrat". thank you - you are very helpful!

Fxshrat, thank you for taking your time! appreciate that a lot.
I have read the 2 links and let me attach the code and give more details on what I am trying to do.
btw, the recent bar didn't fix it and pad&align was disabled. I would also kindly state, this has nothing to do with working of amibroker - I completely understand this is something I am doing wrong and trying to figure it out with your help :slight_smile:

  1. I have data from Tiingo.
  2. I am running the attached exploration.
//Generic
Chg = ROC(C,1); //One bar yield.
AddTextColumn( FullName(), "Company Name",1,1,-1);
AddColumn(C, "Close", 1.2, IIf(C > Ref(C,-1), colorGreen, colorRed),-1); 
AddColumn(Chg, "Change", 1.2, IIf(Chg > Ref(Chg,-1), colorGreen, colorRed),-1);
AddColumn(MA(Ref(V,-1),90), "90_MA_Vol", 1, IIf(MA(Ref(V,-1),5)>MA(Ref(V,-1),90), colorGreen, colorRed),-1);
//50x200
MA3buy = Cross(MA(C,50), MA(C,200));
MA3sell= Cross(MA(C,200),MA(C,50));
Buy = MA3buy;
Sell = MA3sell;
dt = DateTime();
nth_recent = 1;// 1 == most recent, 2 == second to most recent, etc...
// lookup recent historical buy/sell date
GCDC_dt = Lookup(dt, LastValue(ValueWhen(Buy OR Sell, dt, nth_recent)));
MA5_Col=AddColumn( GCDC_dt, "50x200 Signal", formatDateTime,IIF( MA(C,50)>MA(C,200), colorGreen, colorRed ));
//50x200

//Pring's special k
p1 = EMA(ROC(Close,10), 10);
p2 = EMA(ROC( Close, 15), 10);
p3 = EMA(ROC( Close, 20), 10);
p4 = EMA(ROC( Close, 30), 15);
p5 = EMA(ROC( Close, 40), 50);
p6 = EMA(ROC( Close, 65), 65);
p7 = EMA(ROC( Close, 75), 75);
p8 = EMA(ROC (Close, 100), 100);
p9 = EMA(ROC (Close, 195), 130);
p10 =EMA(ROC (Close, 265), 130);
p11 =EMA(ROC (Close, 390), 130);
p12 =EMA(ROC (Close, 530), 195);
  kst0 = p1 + 2 * p2 + 3 * p3 + 4 * p4; 
  kst1 = p5 + 2 * p6 + 3 * p7 + 4 * p8;
  kst2 = p9 + 2 * p10 + 3 * p11 + 4 * p12;
if( BarCount < 500 ) // check first if you have enough bars
{
   {
    kST = kst0 + kst1;
   }
}
  else
  {
   KST = kst0 + kst1 + kst2;
   }

BuyKST=Cross(KST,EMA(KST,265));
SellKST=Cross(EMA(KST,265),KST);
dt_kst = DateTime();
nth_recent = 1;
SpecialK_dt = Lookup(dt_kst, LastValue(ValueWhen(BuyKST OR SellKST, dt_kst, nth_recent)));
MA6_Col=AddColumn(KST, "KST",1,1,IIf(KST<0, colorRed, colorGreen),-1); 
MA7_Col=AddColumn(Specialk_dt, "SpecialK", formatDateTime, IIf(KST>EMA(KST,265), colorGreen, colorRed));
//Pring's special k

// Livermore Trend
// General Graphic Control
BBtop = DEMA(BBandTop(Close,30,2),90);
BBbot = DEMA(BBandBot(Close,30,2),90);
BBwidth = BBtop - BBbot;
BBPct = BBwidth*100/Close;
trigger = 10;//Close/abc;//Param("trigger", 1, 1, 50, 1);
BBPct1 = (trigger*BBPct)/15;
ThresholdPercentValue = BBPct1;
num1 = 1; //Param("num1",1, 0.9, 1.0, 0.1);
num2 = 2.5; //Param("num2",3, 1, 3.1, 0.1);
num3 = 1; //Param("num3",1, 0.1, 3, 0.1);

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

	if(i==0)
	{	//Initialization
		//var:
		StateNo[i]=1;
		InUpTrend[i]=True;
		InDnTrend[i]=False;

		SecRally[i] = NatRally[i] = UpTrend[i] = Close[i];
		SecReact[i] = NatReact[i] = DnTrend[i] =Close[i];

		NatRallyReset[i]=True;
       NatReactReset[i]=True;

		UpTrendPP[i]=C[0];
       NatRallyPP[i]=C[0];
		NatReactPP[i]=C[0];
		DnTrendPP[i]=C[0];

    }  //end;

else  //{Main}
{  //begin  //{calc current Threshold if required}

	//  Memory Refresh Manually... Work like refreshing the D-Ram.
	//  This is the fastest trick to handle the issue with AMI-AFL. (KH Tang)
	//  With this, one can program anything in a flowchart. :-)

	StateNo[i]=StateNo[i-1];
	InUpTrend[i]=InUpTrend[i-1];
	InDnTrend[i]=InDnTrend[i-1];

	UpTrend[i] = UpTrend[i-1];
	NatRally[i] = NatRally[i-1];
	SecRally[i] = SecRally[i-1];
	SecReact[i] = SecReact[i-1];
	NatReact[i] = NatReact[i-1];
	DnTrend[i] = DnTrend[i-1];

	NatRallyReset[i]=NatRallyReset[i-1];
 	NatReactReset[i]=NatReactReset[i-1];

	UpTrendPP[i]=UpTrendPP[i-1];
	NatRallyPP[i]=NatRallyPP[i-1];
	NatReactPP[i]=NatReactPP[i-1];
	DnTrendPP[i]=DnTrendPP[i-1];

	ThresholdPct[i]=ThresholdPercentValue[i]/100; 
    //ThresholdPct[i]=ThresholdPercentValue[i]; 


//
//111111111111111111111111111111111111111111111111111111111111111111111111111111
//
    //State No 1: In Up Trend Column
	if(StateNo[i-1]==1)//
	{//UpTrend Routine
		if(C[i]>=C[i-1])
		{//Price Move Up
			if(C[i]>UpTrend[i])
			{
				StateNo[i]=1;//Remain in UpTrend - 1111111111111111111111111111111
				InUpTrend[i]=True;
				InDnTrend[i]=False;
				UpTrend[i]=C[i];
			}
		}//End of Price Move Up
		else
		{//Price Move Dn
			if((InDnTrend[i] AND C[i]<DnTrendPP[i]) OR   //PivotPoint Check
				(InUpTrend[i] AND C[i]< UpTrend[i]/(num1+num2*ThresholdPct[i])) )
			{//Drop to DnTrend
				StateNo[i]=6;//Dn Trend - 6666666666666666666666666666666666666666	
				InDnTrend[i]=True;	
				InUpTrend[i]=False;
				DnTrend[i]=C[i];
				UpTrendPP[i]=UpTrend[i];
			}// End of Drop to DnTrend			
			else
			{
				if(C[i]<(UpTrend[i]/(num1+num3*ThresholdPct[i])))
				{//Drop Below Current State React 
					if(NatReactReset[i] OR C[i] < NatReact[i])
					{//First Time or Below NatReact
						StateNo[i]=5;//Nat React - 55555555555555555555555555555555				
						NatReactReset[i]=False;
						NatReact[i]=C[i];
						UpTrendPP[i]=UpTrend[i];
					}//End of First Time or Below NatReact
					else
					{//Drop to SecReact 
						StateNo[i]=4;//SecReact - 444444444444444444444444444444444
						SecReact[i]=C[i];
						UpTrendPP[i]=UpTrend[i];
					}//End of Drop to SecReact
				}
			}//End of Drop Below Current Price React
		}//End of Price Move Dn		
	}//End of UpTrend Routine
	
//
//222222222222222222222222222222222222222222222222222222222222222222222222222222
//
	//State No 2: In Nat Rally Column
	else if(StateNo[i-1]==2)//
	{//NatRally Routine
		//NatRallyReset=False;

		if(C[i]>C[i-1])
		{//Price Move Up
			if(	(InUpTrend[i] AND C[i]>UpTrendPP[i]) OR
				(InDnTrend[i] AND C[i]> DnTrend[i]*(num1+num2*ThresholdPct[i])) )
			{//Price move to UpTrend - 1111111111111111111111111111111111111111111
				StateNo[i]=1;
				InUpTrend[i]=True;
				InDnTrend[i]=False;
				UpTrend[i]=C[i];
			}//End of Price Move to UpTrend
			else
			{
				if(C[i]>NatRally[i])
				{//Price Continue to move to higher NatRally 
					StateNo[i]=2;//Remain in NatRally - 222222222222222222222222222
					NatRally[i]=C[i];
					NatRallyReset[i]=False;
				}//End of Price Continue to move to higher NatRally
			}
		}//End of Price Move Up
		else //of(C[i]>C[i-1]) 
		{//Price Move Dn
			if((InDnTrend[i] AND C[i]<DnTrendPP[i]) OR
				(InUpTrend[i] AND C[i]< UpTrend[i]/(num1+num2*ThresholdPct[i])) )
			{//Drop to DnTrend
				StateNo[i]=6;//Dn Trend - 6666666666666666666666666666666666666666
				InDnTrend[i]=True;	
				InUpTrend[i]=False;
				DnTrend[i]=C[i];
				NatRallyPP[i]=NatRally[i];
			}// End of Drop to DnTrend			
			else
			{
				if(C[i]<(NatRally[i]/(num1+num3*ThresholdPct[i])))
				{//Drop Below Current State React 
					if(NatReactReset[i] OR C[i] < NatReact[i])
					{//First Time or Below NatReact
						StateNo[i]=5;//Nat React - 55555555555555555555555555555555					
						NatReactReset[i]=False;
						NatReact[i]=C[i];
						NatRallyPP[i]=NatRally[i];
					}//End of First Time or Below NatReact
					else
					{//Drop to SecReact 
						StateNo[i]=4;//SecReact - 444444444444444444444444444444444
						SecReact[i]=C[i];
						NatRallyPP[i]=NatRally[i];
					}//End of Drop to SecReact
				}
			}//End of Drop Below Current Price React
		}//End of Price Move Dn
	}//End of NatRally Routine

//
//333333333333333333333333333333333333333333333333333333333333333333333333333333
//
	//State No 3: In Sec Rally Column 
	else if(StateNo[i-1]==3) //
	{//SecRally Routine
		if(C[i]>C[i-1])
		{//Price Move Up
			if(	(InUpTrend[i] AND C[i]>UpTrendPP[i]) OR
				(InDnTrend[i] AND C[i]> DnTrend[i]*(num1+num2*ThresholdPct[i])) )
			{//Price move to UpTrend - 1111111111111111111111111111111111111111111
				StateNo[i]=1;
				InUpTrend[i]=True;
				InDnTrend[i]=False;
				UpTrend[i]=C[i];
			}//End of Price Move to UpTrend
			else
			{
				if(C[i]>NatRally[i])
				{//Price Continue to move to higher NatRally 
					StateNo[i]=2;//Remain in NatRally - 222222222222222222222222222
					NatRally[i]=C[i];
					NatRallyReset[i]=False;

				}//End of Price Continue to move to higher NatRally
				else
				{//Remain at SecRally State
					if(C[i]>SecRally[i])
					{//New Higher Sec Price - 3333333333333333333333333333333333333
						StateNo[i]=3;//Remain in SecRally State
						SecRally[i]=C[i];//Update new higher price
					}//End of New Higher Sec Price
				}//End of Remain at Sec State
			}
		}//End of Price Move Up
		else //of(C[i]>C[i-1]) 
		{//Price Move Dn
			if((InDnTrend[i] AND C[i]<DnTrendPP[i]) OR
				(InUpTrend[i] AND C[i]< UpTrend[i]/(num1+num2*ThresholdPct[i])) )
			{//Drop to DnTrend
				StateNo[i]=6;//Dn Trend - 666666666666666666666666666666666666666	6	
				InDnTrend[i]=True;	
				InUpTrend[i]=False;
				DnTrend[i]=C[i];
			}// End of Drop to DnTrend			
			else
			{
				if(C[i]<(SecRally[i]/(num1+num3*ThresholdPct[i])))
				{//Drop Below Current State React 
					if(C[i] < NatReact[i])
					{//First Time or Below NatReact
						StateNo[i]=5;//Nat React - 55555555555555555555555555555555				
						NatReact[i]=C[i];
					}//End of First Time or Below NatReact
					else
					{//Drop to SecReact 
						StateNo[i]=4;//SecReact - 444444444444444444444444444444444
						SecReact[i]=C[i];
					}//End of Drop to SecReact
				}
			}//End of Drop Below Current Price React
		}//End of Price Move Dn
	}//End of SecRally Routine

//
//444444444444444444444444444444444444444444444444444444444444444444444444444444
//
	//State No 4: In Sec React Column  
	//Note that these two state are sharing the same processing routine
	else if(StateNo[i-1]==4)//
	{//SecReact Routine

		if(C[i]>C[i-1])
		{//Price Move Up
			if(	(InUpTrend[i] AND C[i]>UpTrendPP[i]) OR
				(InDnTrend[i] AND C[i]> DnTrend[i]*(num1+num2*ThresholdPct[i])) )
			{//Price move to UpTrend - 1111111111111111111111111111111111111111111
				StateNo[i]=1;
				InUpTrend[i]=True;
				InDnTrend[i]=False;
				UpTrend[i]=C[i];
			}//End of Price Move to UpTrend
			else
			{
				if(C[i]>(SecReact[i]*(num1+num3*ThresholdPct[i])))
				{//Raise Above Current State React 
					if(C[i]>NatRally[i])
						{
							StateNo[i]=2;//Move to NatRally - 2222222222222222222222
							NatRally[i]=C[i];
							NatRallyReset[i]=False;
						}
					else
						{//Raise to SeconaryRally
							StateNo[i]=3;//Raise to SecRally - 333333333333333333333
							SecRally[i]=C[i];
						}//End of Raise to SecRally
				}// End of Raise Above Current State React
			}
		}//End of Price Move Up
		else //of(C[i]>C[i-1]) 
		{//Price Move Dn
			if((InDnTrend[i] AND C[i]<DnTrendPP[i]) OR
				(InUpTrend[i] AND C[i]< UpTrend[i]/(num1+num2*ThresholdPct[i])) )
			{//Drop to DnTrend
				StateNo[i]=6;//Dn Trend - 6666666666666666666666666666666666666666		
				InDnTrend[i]=True;	
				InUpTrend[i]=False;
				DnTrend[i]=C[i];
			}// End of Drop to DnTrend			
			else
			{
				if(C[i]<NatReact[i])
				{//Raise Above NatReact 				
					StateNo[i]=5;//NatReact - 5555555555555555555555555555555555555
					NatReact[i]=C[i];
				}//Raise Above NatReact 
				else
				{//Remain at SecReact
					if(C[i]<SecReact[i])
					{//Lower SecReact
						SecReact[i]=C[i];
					}//End of Lower SecReact
				}//End of Remain at SecReact
			}
		}//End of Price Move Dn
	}//End of Sec React Routine

//
//555555555555555555555555555555555555555555555555555555555555555555555555555555
//
	//State No 5: In Nat React Column
	else if(StateNo[i-1]==5)//
	{//NatReact Routine
		//NatReactReset=False;
		if(C[i]>C[i-1])
		{//Price Move Up
			if(	(InUpTrend[i] AND C[i]>UpTrendPP[i]) OR
				(InDnTrend[i] AND C[i]> DnTrend[i]*(num1+num2*ThresholdPct[i])) )
			{//Price move to UpTrend - 1111111111111111111111111111111111111111111
				StateNo[i]=1;
				InUpTrend[i]=True;
				InDnTrend[i]=False;
				UpTrend[i]=C[i];
				NatReactPP[i]=NatReact[i];
			}//End of Price Move to UpTrend
			else
			{
				if(C[i]>(NatReact[i]*(num1+num3*ThresholdPct[i])))
				{//Raise Above Current State React 
					if(NatRallyReset[i] OR C[i]>NatRally[i])
						{
							StateNo[i]=2;//Move to NatRally - 2222222222222222222222
							NatRallyReset[i]=False;
							NatRally[i]=C[i];
							NatReactPP[i]=NatReact[i];
						}
					else
						{//Raise to SeconaryRally
							StateNo[i]=3;//Raise to SecRally - 333333333333333333333
							SecRally[i]=C[i];
							NatReactPP[i]=NatReact[i];
						}//End of Raise to SecRally
				}// End of Raise Above Current State React
			}
		}//End of Price Move Up
		else //of(C[i]>C[i-1]) - Common with State 1
		{//Price Move Dn
			if((InDnTrend[i] AND C[i]<DnTrendPP[i]) OR
				(InUpTrend[i] AND C[i]< UpTrend[i]/(num1+num2*ThresholdPct[i])) )
			{//Drop to DnTrend
				StateNo[i]=6;//Dn Trend - 6666666666666666666666666666666666666666		
				InDnTrend[i]=True;	
				InUpTrend[i]=False;
				DnTrend[i]=C[i];
			}// End of Drop to DnTrend			
			else
			{
				if(C[i]<NatReact[i])
				{//Raise Above NatReact 				
					StateNo[i]=5;//NatReact - 5555555555555555555555555555555555555
					NatReact[i]=C[i];
				}//Raise Above NatReact 
			}
		}//End of Price Move Dn
	}//End of NatReact Routine
//
//666666666666666666666666666666666666666666666666666666666666666666666666666666
//
	//State No 6: In Dn Trend Column
	else if(StateNo[i-1]==6)//
	// Must be in State No 6
	{//DnTrend Routine
		if(C[i]>C[i-1])
		{//Price Move Up
			if(	(InUpTrend[i] AND C[i]>UpTrendPP[i]) OR
				(InDnTrend[i] AND C[i]> DnTrend[i]*(num1+num2*ThresholdPct[i])) )
			{//Price move to UpTrend - 1111111111111111111111111111111111111111111
				StateNo[i]=1;
				InUpTrend[i]=True;
				InDnTrend[i]=False;
				UpTrend[i]=C[i];
				DnTrendPP[i]=DnTrend[i];
			}//End of Price Move to UpTrend
			else
			{
				if(C[i]>(DnTrend[i]*(num1+num3*ThresholdPct[i])))
				{//Raise Above Current State React 
					if(NatRallyReset[i] OR C[i]>NatRally[i])
						{
							StateNo[i]=2;//Move to NatRally - 2222222222222222222222
							NatRallyReset[i]=False;
							NatRally[i]=C[i];
							DnTrendPP[i]=DnTrend[i];
						}
					else
						{//Raise to SeconaryRally
							StateNo[i]=3;//Raise to SecRally - 333333333333333333333
							SecRally[i]=C[i];
							DnTrendPP[i]=DnTrend[i];
						}//End of Raise to SecRally
				}// End of Raise Above Current State React
			}
		}//End of Price Move Up
		else //of(C[i]>C[i-1]) - Common with State 1
		{//Price Move Dn
			if(C[i]<DnTrend[i])
			{//Price move futher Dn
				StateNo[i]=6;//Dn Trend - 6666666666666666666666666666666666666666		
				InDnTrend[i]=True;	
				InUpTrend[i]=False;
				DnTrend[i]=C[i];
			}//End of Price move Futher Dn			
		}//End of Price Move Dn
	}//End of DnTrend Routine

//

	//Checking and Processing Parameters here... 
	//Reset Value of Rally and React Values if needed
	
	// React Values become Obseleted Price moved to high up. Reset them.
   if(InUpTrend[i] AND NatReact[i] < UpTrend[i]/(num1+num2*ThresholdPct[i]) )
	{
		NatReactReset[i]=True;
	}
	// Rally Values become Obaseleted as Price move to low Dn. Reset them
	if(InDnTrend[i] AND NatRally[i] > DnTrend[i]*(num1+num2*ThresholdPct[i]) )   
	{
		NatRallyReset[i]=True;
	}

  }  //end; //{main}
} //End of For i Loop!

//Plotting Section - Just for testing

//InUpTrend
WeightNo= IIf(StateNo==1,5,                // UpTrend
			IIf(InUpTrend AND StateNo==5,1,  // and NatReact
			IIf(InUpTrend AND StateNo==2,4,  // and NatRally
			IIf(InUpTrend AND StateNo==4,2,  // and SecReact
			IIf(InUpTrend AND StateNo==3,3,  // and SecRally
			IIf(StateNo==6,-5,               // DownTrend
			IIf(InDnTrend AND StateNo==2,-1, // and NatRally         
			IIf(InDnTrend AND StateNo==5,-4, // and NatReact
			IIf(InDnTrend AND StateNo==3,-2, // and SecRally
			                             -3  // and SecReact
			)))))))));

Buylivermore = Cross(WeightNo,0);
Selllivermore = Cross(0,WeightNo);
dt_livermore = DateTime();
nth_recent = 1;
livermore_dt = Lookup(dt_livermore, LastValue(ValueWhen(Buylivermore OR Selllivermore, dt_livermore, nth_recent)));
MAlivermore_Col=AddColumn(livermore_dt, "Livermore", formatDateTime, IIf(WeightNo>0, colorGreen, colorRed));
//End of Livermore Market Key Section


SetBarsRequired(200, 0);
 
// Ehlers formulas
// from Ehlers, John F. Cybernetic Analysis for Stocks and Futures. Wiley. 2004. 
// Chapter 14, p. 213. Code on p. 221.
 
function LRSI(array, gamma)
// Figure 14.8 on p. 221.
{
  L0 = array;  // Initialize as array
  L1 = array;
  L2 = array;
  L3 = array;
  LRSIValue = array;
 
  for(i = 1; i < BarCount; i++)
  {
     //gamma = Param("gamma",0.8,0.2,1.0,0.01);
     L0[i] = (1 - gamma)*array[i] + gamma*L0[i-1];
     L1[i] = - gamma * L0[i] + L0[i-1] + gamma * L1[i-1];
     L2[i] = - gamma * L1[i] + L1[i-1] + gamma * L2[i-1];
     L3[i] = - gamma * L2[i] + L2[i-1] + gamma * L3[i-1];
 
     CU = 0;
     CD = 0;
     if (L0[i] >= L1[i]) CU = L0[i] - L1[i]; else (CD = L1[i] - L0[i]);
     if (L1[i] >= L2[i]) CU = CU + L1[i] - L2[i]; else CD = CD + L2[i] - L1[i];
     if (L2[i] >= L3[i]) CU = CU + L2[i] - L3[i]; else CD = CD + L3[i] - L2[i];
 
     if (CU + CD != 0) LRSIValue[i] = CU / (CU + CD);
  }
  return LRSIValue;
}
LI=LRSI(C, 0.95);
BuyLRSI=LI>0.5;
SellLRSI=LI<0.5;
BuyLRSI1=ExRem(BuyLRSI, SellLRSI);
SellLRSI1=ExRem(SellLRSI, BuyLRSI);
dt_LI=DateTime();
nth_recentLI=1;
LI_dt=Lookup(dt_LI,LastValue(ValueWhen(BuyLRSI1 OR SellLRSI1, dt_LI, nth_recentLI)));
LI_col=AddColumn(LI_dt,"LRSI",formatDateTime, IIf(LI>0.5,colorGreen,colorRed));

//IBD RS RANKING
RC = 0.001*RelStrength("vfisx", fixup = 1);
Period1 = Param("Period1",12,8,12,1);
Period2 = Param("Period2",28,28,34,1);
Period3 = Param("Period3",60,55,65,1);
Period4 = Param("Period4",100,100,120,1);
Period5 = Param("Period5",150,185,210,1);
tr03 = (RC - Ref(RC, -Period1)) / Ref(RC, -Period1) * 100;
tr13 = (RC - Ref(RC, -Period2)) / Ref(RC, -Period2) * 100;
tr26 = (RC - Ref(RC, -Period3)) / Ref(RC, -Period3) * 100;
tr52 = (RC - Ref(RC, -Period4)) / Ref(RC, -Period4) * 100;
tr62 = (RC - Ref(RC, -Period5)) / Ref(RC, -Period5) * 100;
RSW1 = (tr03+tr13+tr26+tr52+tr62)/5;
RC1 = 0.001*RelStrength("SPY", fixup = 1);
tr031 = (RC1 - Ref(RC1, -12)) / Ref(RC1, -12) * 100;
tr131 = (RC1 - Ref(RC1, -28)) / Ref(RC1, -28) * 100;
tr261 = (RC1 - Ref(RC1, -60)) / Ref(RC1, -60) * 100;
tr521 = (RC1 - Ref(RC1, -108)) / Ref(RC1, -108) * 100;
tr1000= (RC1 - Ref(RC1, -192)) / Ref(RC1, -192) * 100;
RSW2 = (tr031+tr131 + tr261 + tr521+tr1000)/5;
RSW3 = IIf(RSW1>0.1,RSW1,0.1);
BuyIBD=EMA(RSW1,3)>0;
SellIBD=EMA(RSW1,3)<0;
BuyIBD1=ExRem(BuyIBD, SellIBD);
SellIBD1=ExRem(SellIBD, BuyIBD);
dt_IBD = DateTime();
nth_recentIBD = 1;
IBD_dt= Lookup(dt_IBD, LastValue(ValueWhen(BuyIBD1 OR SellIBD1, dt_IBD, nth_recentIBD)));
MA8_Col=AddColumn(IBD_dt, "IBD RS", formatDateTime, IIf(EMA(RSW1,3)>0, colorGreen, colorRed));
//OverallRank = 0;
//result = IIF( MA(C,50)>MA(C,200), 1, -2);
//OverallRank = OverallRank+result;
//result1 = IIf(Hull > EMA(Ref(Hull,-1),10), 1,-1);
//OverallRank = OverallRank+result1;
//result2 = IIf(WeightNo>0, 1,-1);
//OverallRank = OverallRank+result2;
//result3 = IIf(KST>0, 1,-5);
//OverallRank = OverallRank+result3;
//result4 = IIf(IFTStoch>50, 1,-1);
//OverallRank = OverallRank+result4;
//AddColumn(OverallRank, "OverallRank",1,1);
Rank = RSW1;
AddColumn(Rank, "Rank",1,1,IIf(Rank<0, colorRed, colorGreen),-1); 
//HI = Ref(HHV(High,260),-1);
//LW = Ref(LLV(Low,260),-1);
//AddColumn(GetFnData("QtrlyRevenueGrowth" ) , "Qtr Rev Growth"); 
IBDrank=AddColumn(EMA(RSW2,5), "IBD Strength", 1.2);

// Modified Renko Chart with custom date axis and high/low winks 
function FillRun( dir, num, changedir ) 
{ 
global i, j, modified, dt, RKC, RKO, RKD, RKH, RKL; 
for ( x = 1; x <= num AND j < BarCount - 1; x++ ) 
{ 
j++; 
extra = ( changedir AND x == 1 ) * dir; 
RKC[ j ] = RKC[ j - 1 ] + dir + extra; 
RKO[ j ] = RKC[ j - 1 ] + IIf( modified, 0, extra ); 
RKD[ j ] = dt[ i ]; 
RKH[ j ] = High[ i - 1 ]; 
RKL[ j ] = Low[ i - 1 ]; 
} 
} 
SetBarsRequired( sbrAll, sbrAll ); 
a = LastValue(Ref(HHV(High,2000),-1));
Brick0 = 0.01*a;//LastValue( MA(Close,200) );
Brick = IIf(Brick0<0.5, 0.5,Brick0);
revert = 1; 
intra = ParamToggle( "Intraday", "No|Yes", 0 ); 
modified = ParamToggle( "Modified", "No|Yes", 0 ); 
// Convert the closing price to rising and falling rounded bricks 
CF = ceil( C / Brick ); 
CR = floor( C / Brick ); 
// initialize first element 
j = 0; 
RKC[j] = CF[0]; 
RKO[j] = CF[0] + 1; 
RKD = 0; 
RKH = 0; 
RKL = 0; 
dt = IIf( intra, floor( TimeNum() / 100 ), DateNum() ); 
dir = -1; // 1 is up, -1 is down 
// Loop to produce the Renko values in number of bricks 
for ( i = 1; i < BarCount - 1; i++ ) 
{ 
if ( j >= BarCount ) 
break; // no more room -> finish 
if ( CF[i] <= RKC[j] - 1 AND dir < 0 ) // Continue down 
{ 
num = RKC[j] - CF[i]; 
FillRun( dir, num, False ); 
} 
else 
if ( CR[i] >= RKC[j] + revert AND dir < 0 ) // Change down to up 
{ 
num = CR[i] - RKC[j]; 
dir = 1; 
FillRun( dir, num, True ); 
} 
else 
if ( CR[i] >= RKC[j] + 1 AND dir > 0 ) // Continue Up 
{ 
num = CR[i] - RKC[j]; 
FillRun( dir, num, False ); 
} 
else 
if ( CF[i] <= RKC[j] - revert AND dir > 0 ) // Change up to down 
{ 
num = RKC[j] - CF[i]; 
dir = -1; 
FillRun( dir, num, True ); 
} 
} 
// move the chart to right end of chart space, ie last brick on last bar position 
delta =  BarCount - 1 - j; 
RKC = Ref( RKC, -delta ); 
RKO = Ref( RKO, -delta ); 
RKD = Ref( RKD, -delta ); 
RKH = Ref( RKH, -delta ); 
RKL = Ref( RKL, -delta ); 
C = RKC * Brick; 
O = RKO * Brick; 
H = IIf( modified, RKH, Max( C, O ) ); 
L = IIf( modified, RKL, Min( C, O ) ); 
//Plot( C, "", IIf( C > O, colorGreen, colorRed ), styleCandle ); 
time = IIf(LastValue(Close)<20,100,200);//Param( "time", 1, 1, 500, 1 );
m1 = HMA( C, time); 
//Plot( m1, "SMA Type", colorBlue ); 
//SellR = m1>C; 
//BuyR = m1<C; 
//PlotShapes( shapeUpArrow * Buy, colorGreen, 0, m1); 
//PlotShapes( shapeDownArrow * Sell, colorRed, 0, m1 );   
//Title = Name() + StrFormat( " - 20%06.0f", RKD % 1000000 ) + " - Renko Chart : Last Value = " + RKC * Brick + " H: " + RKH + " L: " + RKL + ", Brick Size = " + Brick; 
//GraphXSpace = 5;
//END renko

//AddColumn( GetFnData( "EPS" ) , "EPS" ); 
//AddColumn( GetFnData( "OperatingCashFlow" ) , "Next Qtr EPS" ); 
//AddColumn((GetFnData("DividendPerShare")/Close*100), "Dividend Yield" );

AddSummaryRows(16,1);
a = Ref(HHV(High,260),-1);
//a = "+GetRTData("52weekhigh");
//a = Highest(Close); 
b = ((a / Close) - 1) * 100;
MinVal = LLV(Close,260);
AddColumn(SectorID(), "Sector number", 1.0);
AddTextColumn( SectorID( 1 ), "Sector name" );
AddColumn(IndustryID( 0 ), "Industry ID", 1.0);
AddTextColumn( IndustryID( 1 ), "Industry name" );
//Filter = SectorID()>0 AND SectorID()<13 AND ATR(5)>0.25 AND MinVal>10 AND Rank>0.1 AND RANK<100 AND RSW1>0 AND Close>10 AND Close>MA(Close,200) AND MA(Volume,265)>1000000 AND b<20;// AND BarsSince(Cross(Rank,0))<30;// GetFnData("EPS")>0 AND GetFnData("QtrlyRevenueGrowth")>AND Close > 0.7 * HHV(Close, 260); 
//SetSortColumns(-9);
MktCap = GetFnData("Sharesout")*Close;
//Filter = BarsSince(Cross(EMA(RSW2,5),0))<10 AND MktCap>5000000000 AND EMA(RSW2,5)>0 AND WeightNo>0 AND LI>0.5 AND Rank>0.1 AND RANK<100 AND RSW1>0 AND Close>10 AND Close>MA(Close,200) AND MA(Volume,265)>1000000 AND b<10 AND SectorID()>0 AND SectorID()<13 AND MinVal>10 AND ATR(5)>0.25;// AND BarsSince(Cross(Rank,0))<30;// GetFnData("EPS")>0 AND GetFnData("QtrlyRevenueGrowth")>AND Close > 0.7 * HHV(Close, 260); 
//Filter = m1<C AND MktCap>5000000000 AND EMA(RSW2,5)>0 AND WeightNo>0 AND LI>0.3 AND Rank>0.1 AND RANK<100 AND RSW1>0 AND Close>10 AND Close>MA(Close,200) AND MA(Volume,265)>1000000 AND b<20 AND SectorID()>0 AND SectorID()<13 AND MinVal>10 AND ATR(5)>0.25;// AND BarsSince(Cross(Rank,0))<30;// GetFnData("EPS")>0 AND GetFnData("QtrlyRevenueGrowth")>AND Close > 0.7 * HHV(Close, 260); 
//Filter = m1>C AND MktCap>10000000000 AND LI<0.5 AND Close>10 AND MA(Volume,265)>1000000 AND SectorID()>0 AND SectorID()<13 AND MinVal>10 AND ATR(5)>0.25;// AND BarsSince(Cross(Rank,0))<30;// GetFnData("EPS")>0 AND GetFnData("QtrlyRevenueGrowth")>AND Close > 0.7 * HHV(Close, 260); 
//Filter= Close>10 AND MA(Volume,265)>500000 AND RSW2>0 AND RANK<90 AND RANK>-15 AND MktCap>4000000000 AND KST>50;// AND GetFnData("DividendPerShare")/Close*100>3;
//Filter= Close>10 AND MA(Volume,265)>1000000 AND RANK>0 AND RANK<90 AND EMA(RSW2,5)>0 AND KST>0;// MktCap>50000000000 AND GetFnData("DividendPerShare")/Close*100>3;
Filter= Close>10 AND Status("LastBarInRange") AND MA(Volume,265)>1000000 AND RANK>0 AND RANK<90 AND EMA(RSW1,5)>0 AND EMA(RSW2,5)>0;
SetSortColumns(18, -13);
  1. I run this code on "All" symbols , but range is "1 recent bar".
  2. The output looks like following:
    image
  3. In the output, you can see there are some tickers that are <10.
    I am sure I am doing something wrong, if its a quick obvious item, appreciate your help.

Yes, you are doing something incorrectly (leading to your undesired outcome).

In line 673 "you" are overriding (!) Close array like this

C = RKC * Brick; 

That is the reason that AddColumn of line 4 (!)

AddColumn(C, "Close", 1.2, IIf(C > Ref(C,-1), colorGreen, colorRed),-1); 

will lead to output of Close values lower than 10 because that line is placed before you override default Close array and Filter being placed after both lines. So Filter will use overridden Close array for filtering decision.

Apparently you want to filter by Renko Close (?) so rather put all Addcolumn lines at one place instead creating problematic clutter.

In general it's good idea to go by the rule set

1. INPUT
2. PROCESSING
3. OUTPUT

That's how code should be structured ideally.

Things like yours happen because of copy&pasting multiple codes made by other people and mixing them together just like that and as such not knowing/understanding consequence of "toxic" mix.

BTW, if you copy code then you actually should add link to original creator source. For example the Renko code looks like @Tomasz code.

And to find out what is going on in a code please read here.

2 Likes

Thank you "fxshrat" - very informative! Good inputs there and it makes sense!
have a great weekend!