# Why warunek_min returns 0 ( expect 1)

The conditions in warunek_min and PlotShapes are the same
but why warunek_min returns 0 ( expect 1) even though the graph shows the arrow where it should be?

``````E20=EMA(C,20);
E50=EMA(C,50);
E100=EMA(C,100);
E20x5=E100;
E50x5=EMA(C,350);
E100x5=EMA(C,450);

Sell=Cross(E100,E20); // DOROBIC WYJSCIE

dt = DateTime();

``````

It's because you have set Filter to `barsBuy == 13`. And at those filtered results your warunek_min variable shows zero results.

So change to

``````Filter = Buy;//barsBuy == 13;
``````

Or

``````Filter = warunek_min;//barsBuy == 13;
``````

BTW these ones

Can be written

``````EMA_cond = E50x5<E100x5;
EMA_result = E50x5*EMA_cond + E100X5*(NOT EMA_cond);

warunek_min=IIf(EMA_DOLNA>E50 AND Buy AND C<EMA_DOLNA, 1, 0);
PlotShapes(warunek_min * shapeSmallUpTriangle, colorWhite, 0,L, -25);

``````

(so reduced from 8 ValueWhen calls to 1 ValueWhen call) and it will have same result.

ValueWhen is costly (time consuming) function.

Thank you, only barsBuy == 13; it is also needed, because I calculate min and max from the next 13 candles
And now barsBuy is just a comment on how to make both filters work and return the results i need.

``````dt = DateTime();
``````

When you enter a condition or in a filter, it gets two records. If they meet the conditions. I need this information in one record.
How to write a filter to get the right information.

``````Filter = warunek_min OR barsBuy == 13;
``````

I am not quite sure what you are looking for exactly.
Your thread subject was asking for why `warunek_min` was zero.
It was explained to you in post #2 why that is the case with exploration code of post #1.

`warunek_min` is dependent on `Buy` status (and others) and `barsBuy == 13` is a status after `True` Buy signal.
So `warunek_min` and `barsBuy == 13` can not be `true` (1) at same bar.

But if you want to have the status of `warunek_min` at Filter `barsBuy == 13` then in AddColumn you may use `ValueWhen(Buy,warunek_min)`, for example.

``````Buy = /*insert Buy condition*/;

warunek_min = /*insert your code line here*/;

dt = DateTime();