@carlosrodrgueznieto,
Please listen, the code (snippet) I've posted does give you exactly the values of that range you were asking in 1st post.
This is your quote
"I need to store only the values that are between the green and red lines."
That is what the code snippet I've posted above is doing exactly (without loop) to original quote of yours. (FYI zeroes/Nulls(-1e10) are values too).
And you are the one who added -80
to SelectedValue(BarIndex)
in first post. So I kept it also (BTW variable bi
of my snippet is defined as bi = BarIndex()
). If you remove -80
then it will look like in the following one picutre (red line being selected value). Please look at the picture carefully.

So indeed stored values are the ones of between red and green lines (again).
So long story short please do create a detailed post in the first place which leaves no room for misunderstanding and missing info.
And just saying
"I have tried your code but it does not give me the result I want."
is not useful at all (besides of being wrong one considering 1st post of this thread).
Now as for the updated info, if you want to remove zeroes (or Nulls) then you can do that via sorting. But you did not say anything about removing zeroes or Nulls originally. You added updated info later when responses were overlapping.
So here is with removing Nulls.
function MxArrayConditionBlock(array_condition, array, start_idx) {
/// @link https://forum.amibroker.com/t/values-that-are-between-the-green-and-red-lines/12049/8
/// by fxshrat@gmail.com
/// Commercial use prohibited!
local arr_block, mat, mat_sort, matsort_block, null_cnt, rownum, rows;
mat = Matrix(BarCount, 2, Null);
rownum = MxGetSize(mat, 0);
mat = MxSetBlock(mat, 0, rownum-1, 0, 0, IIf(array_condition, array, Null));
mat = MxSetBlock(mat, 0, rownum-1, 1, 1, BarIndex());
start_idx = Max(0, Min(start_idx, rownum-1));
mat_sort = MxSortRows(MxGetBlock(mat, start_idx, rownum-1, 0, 1 ), 1, 0);
arr_block = MxGetBlock(mat_sort, 0, rows = MxGetSize(mat_sort,0)-1, 0, 0, True);
null_cnt = Min(NullCount(arr_block), rows);
matsort_block = MxSortRows(MxGetBlock(mat_sort, null_cnt, rows, 0, 1 ), 1, 1);
result = MxGetBlock(matsort_block, 0, MxGetSize(matsort_block, 0)-1, 0, 0);
return result;
}
DPO7 = C - MA( C, 7 );
Plot( DPO7,_DEFAULT_NAME(),ParamColor("Color", ColorCycle ) );
Plot(0, "", colorWhite, styleLine | styleNoLabel);
//Title = StrFormat( "{{NAME}} - %s DPO (7) %s = %1.2f", EncodeColor(colorLightOrange), EncodeColor(colorWhite), DPO7);
// VerticalLine --> LastBar y -80 Bars
bi = BarIndex();
start_idx = Max(0, SelectedValue(bi)/*-80*/);
Last_Bar = bi == LastValue( bi );
Start_Bar = bi == start_idx;
Plot( Last_Bar, "", colorGreen, styleHistogram | styleOwnScale | styleDashed | styleNoLabel | styleThick, 0, 1 );
Plot( Start_Bar, "", colorRed, styleHistogram | styleOwnScale | styleDashed | styleNoLabel | styleThick, 0, 1 );
// Calculate Positive Values > 0
DndPO = DPO7;
Crucealc = Cross(DndPO,0);
Alto = HighestSince (Crucealc,DndPO,1);
MaxV = Ref(HHV(DndPO,1),1);
Buy = DndPO==Alto;
Buy1 = DndPO>MaxV;
DndPO_block = MxArrayConditionBlock( Buy AND Buy1, DndPO, start_idx );
printf(MxToString(MxTranspose(DndPO_block)));
for( i = 0; i < BarCount; i++ )
{
if( (Buy[i] AND Buy1[i]) )
{
PlotText( NumToStr(DndPO[ i ],1.6) , i , DndPO[ i ]+1, colorTurquoise, bkcolor = colorDefault);
}
}
//for( i = 0; i < colnum; i++ )
//{
// printf( "DPO = %g\n ", mat[0][i] );
//}
Please watch carefully again.
