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?

please help :wink:

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

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

dt = DateTime();
barsBuy = BarsSince(Buy)+1;
MaxBuy = HighestSince(Buy, c);                          //value Max Buy
MinBuy = LowestSince(Buy, c);                           // value Min Buy
barsOstatni = BarsSince(C)+1;


EMA_DOLNA=IIf(ValueWhen(Buy, E50x5)<ValueWhen(Buy, E100x5), ValueWhen(Buy, E50x5), ValueWhen(Buy, E100X5));
warunek_min=IIf(ValueWhen(Buy, EMA_DOLNA)>ValueWhen(Buy,E50) AND Buy AND C<EMA_DOLNA, 1, 0);
PlotShapes(IIf(ValueWhen(Buy, EMA_DOLNA)>ValueWhen(Buy,E50) AND Buy AND C<EMA_DOLNA, shapeSmallUpTriangle, shapeNone),colorWhite, 0,L, Offset=-25); 
AddColumn(ValueWhen(Buy,dt), "date up cross", formatDateTime);
AddColumn(warunek_min, "warunek minima");

Filter = barsBuy == 13;

image

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);
EMA_DOLNA = ValueWhen(Buy, EMA_result);

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();
barsBuy = BarsSince(Buy)+1;
MaxBuy = HighestSince(Buy, c);                          //value Max Buy
MinBuy = LowestSince(Buy, c);                           // value Min Buy
barsOstatni = BarsSince(C)+13;
AddColumn(barsOstatni, "bar Ostatni");
AddColumn(MaxBuy, "MaxBuy");
AddColumn(MinBuy, "MinBuy");
AddColumn(ValueWhen(Buy,dt), "date up cross", formatDateTime);
Filter = warunek_min;//barsBuy == 13;

image

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;

image

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();
barsBuy = BarsSince(Buy)+1;
MaxBuy = HighestSince(Buy, c);                          //value Max Buy
MinBuy = LowestSince(Buy, c);                           // value Min Buy

AddColumn(MaxBuy, "MaxBuy");
AddColumn(MinBuy, "MinBuy");
AddColumn(ValueWhen(Buy,dt), "date up cross", formatDateTime);
AddColumn(ValueWhen(Buy,warunek_min), "warunek_min@Buy", 1);
Filter = barsBuy == 13;

This is not properly code as BarSince rather expects true/false array.
Price rather is always greater zero.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.