# How to create a filter as latest close greater than latest open +1 day ago high +one day ago close /3

hi ,

please correct me i am writing the below filter

Filter = Close>EMA(C,5) AND RSI(14)>45 AND Close>Open*1.02 AND Volume>200000 AND Close<1500 AND Close>Ref(C,-1) AND Close>Ref(C,-7) AND

the above filters are giving me the output and want to add below one

Close>Open+Ref(High,-1)+Ref(Close,-1)/3
but this is not give me the explore output please guide me to rectify and also wants to add two more filters
latest true range (14)greater than latest avg true range (14) and
latest true range(14)greater than 5

@haresh please use proper code tags when posting codes.

``````Condtion = Close > ( Open + Ref(High,-1) + Ref(Close,-1) )/ 3;
``````

``````LatestTR 	= ATR(1);
aveTR 		= ATR(14);
Condition2 	= LatestTR > aveTR ;
``````
1 Like

Created a little AFL to show you how to use Exploration to help debug. For this example best way is to set "ApplyTo - Current", "Range - All Quotes").

The reason you can't get your filter to work is because condition is never true. Below AFL is a quick example of a way to verify variables values. You'll need to rework your formula there. Your adding yesterdays high and today's open and expecting close to be greater then that, thats a huge move then your adding yesterdays close / 3 which is even bigger.

``````//https://forum.amibroker.com/t/how-to-create-a-filter-as-latest-close-greater-than-latest-open-1-day-ago-high-one-day-ago-close-3/14660

cond1 = C > EMA( C, 5 );
cond2 = RSI( 14 ) > 45;
cond3 = C > O * 1.02;
cond4 = V > 200000;
cond5 = C < 1500;
cond6 = C > Ref( C, -1 );
cond7 = C > Ref( C, -7 );
cond8 = C > ( O + Ref( H, -1 ) ) + ( Ref( C, -1 ) / 3 );

//Below filter for exploration of condition
//Filter = cond1 AND cond2 AND cond3 AND cond4 AND cond5 AND cond6 AND cond7 AND cond8;

//Below filter for debugging AFL
AddColumn( Close, " Close", 1.2 );
AddColumn( EMA( C, 5 ), " Close > EMA(C,5)", 1.2, colorDefault, IIf( cond1, colorpalegreen, colorpink ) );
AddColumn( RSI( 14 ), " RSI(14) > 45", 1.2, colorDefault, IIf( cond2, colorpalegreen, colorpink ) );
AddColumn( O * 1.02, " Close > Open*1.02", 1.2, colorDefault, IIf( cond3, colorpalegreen, colorpink ) );
AddColumn( Volume, " Volume > 200000", 1.2, colorDefault, IIf( cond4, colorpalegreen, colorpink ) );
AddColumn( Close, " Close < 1500", 1.2, colorDefault, IIf( cond5, colorpalegreen, colorpink ) );
AddColumn( Ref( C, -1 ), " Close > Ref(C,-1)", 1.2, colorDefault, IIf( cond6, colorpalegreen, colorpink ) );
AddColumn( Ref( C, -7 ), " C > Rec(C,-7)", 1.2, colorDefault, IIf( cond7, colorpalegreen, colorpink ) );
AddColumn( ( O + Ref( H, -1 ) ) + ( Ref( C, -1 ) / 3 ), "Close > O+Ref(H,-1) etc", 1.2, colorDefault, IIf( cond8, colorpalegreen, colorpink ) );

//Below filter for debugging
Filter = 1; // Comment out this line if using to scan;

``````

Another great way to troubleshoot/debug is to use the Plotshapes() function and a chart.

``````PlotShapes(shapeDigit1,colorGreen);
``````

As far as the ATR , portfoliobuilder offered something, I'm not sure what your after. If you mean today's ATR14 is greater then yesterday's.

``````cond9 = ATR(14) > Ref(ATR(14),-1);
``````
3 Likes

Thanks very much, metamega for your code but the code you made is giving the exploration result out put of total 1735 records and not filtering the required conditions.
i want only the symbols which satisfies the filters that are much more less than 1735 may be 100 or less and i t is possible if i am using the "and" filter.

thanks a lot

Thanks portfoliobilder , for your information on filter.

i trying to complete the exploration the below is the afl`Code button (use to enter/paste AFL formula)`myRSI = RSI(14);
myATR = ATR(14);

r1=H-L;
r2=abs(H-Ref(C,-1));
r3=abs(Ref(C,-1)-L);

TrueRange=Max(Max(r1,r2),r3);
tr1 = (TrueRange*13 + TrueRange );

ab = Ref(High,-1)+Ref(Close,-1);
Filter = Close>EMA(C,5) AND RSI(14)>45 AND Close>Open*1.02 AND Volume>200000 AND Close<1500 AND Close>Ref(C,-1) AND Close>Ref(C,-7) AND Close>(Open+ab)/3 AND LastValue(Close)>Ref(C,-2) AND TrueRange>5 AND TrueRange>ATR(14);

fbr = Status( "firstbarinrange" );
lbr = Status( "lastbarinrange" );

startprice = ValueWhen(fbr, C);
endprice = ValueWhen(lbr, C);

rc = (endprice - startprice) / startprice * 100;

//OR
// Filter = lbr;

please guide me and correct me if i am made any mistake while writing the formula as i am a new user of amibroker.