How to modify exploration output such that each symbol is only listed once?

Hi all,

let's assume I have a simple exploration such as Filter = C > MA(C,200); that runs over a long watchlist and multiple bars. My goal is to modify the output such that for each symbol only the first Filter occurence is shown in the list. In the below screenshot for example, for AABA there should be only one row with Date/Time equal to 04.01.2017.

show_each_symbol_only_once

How to achieve this?

Best, Axel

For example change Filter to

/// Show first occurrence of analysis range only
/// @link http://forum.amibroker.com/t/how-to-modify-exploration-output-such-that-each-symbol-is-only-listed-once/4461/2
condition = C > MA(C, 200);
Filter = Cum(condition AND Status( "barinrange" )) == 1;
1 Like

Thanks for your quick reply!
Unfortunately, your code does not quite work. Please, check the attached screenshot for an example where it fails:

too_many_ones

Wrong. The Filter of 2nd post works for any condition.
You have not used the same filter line as shown in 2nd post! Your line misses equality check.

Use this one (again it is the same line as in 2nd post).

Filter = Cum(condition AND Status( "barinrange" )) == 1;

Apply your condition in Analysis and post screen.

1 Like

If I set the From-To range from 01.01.2017 to 31.01.2017 your code will definitely not work, because cumFilter is 1 eight times in this time frame. Thus, your equality check will fail.

Then do like so

/// Show first occurrence of analysis range only
/// @link http://forum.amibroker.com/t/how-to-modify-exploration-output-such-that-each-symbol-is-only-listed-once/4461/5
condition = C > MA(C, 200) AND Status( "barinrange" );
cumcond = Cum(condition);
Filter = cumcond == 1 AND Nz(Ref(cumcond, -1)) == 0;
4 Likes

Great! You taught me three new functions (cum, Status and Nz). Thank you very much!

Hello, nice answer from @fxshrat
I would like to achieve the same. However, instead of selecting From-To dates, can we do the same but by selecting # recent day(s) in Range option (or # recent bar(s)) ?

Found a solution for my inquiry above. Again, thanks to @fxshrat

My original code below will produce multiple results for a symbol if it meets the requirement multiple times in the previous 10 days (as I set in the Analysis Range option):

HI = Close > Ref(HHV(High,260),-1);
LW = Close < Ref(LLV(Low,260),-1);

Filter = HI OR LW;

AddColumn( High > Ref(HHV(High,260),-1), "52 Week High", 1 );
AddColumn( Low < Ref(LLV(Low,260),-1), "52 Week Low", 1 );

The corrected code below will only list the first occurrence for each symbol, which is what I intended:

HI = Close > Ref(HHV(High,260),-1);
LW = Close < Ref(LLV(Low,260),-1);

condition = (HI OR LW) AND Status( "barinrange" );
cumcond = Cum(condition);

Filter = cumcond == 1 AND Nz(Ref(cumcond, -1)) == 0;

AddColumn(Hi, "52 Week High", 1 );
AddColumn(LW, "52 Week Low", 1 );

3 Likes