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 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;
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.
/// 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;
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 );