How to code this array switching without using a for (i==0.....) loop

Is there a way to do this without using a for(i.....barcount) loop?

up = cross(C, EMA(C,10));
dn = cross(EMA(C,10), C));

marker is an array (0 to barcount-1) that is "1" on certain bars, other bars is zero.

I want to output array to be:

0 until first up encountered - then set output to 1
1 from then on until dn==1
then output to be zero until marker==1
then output==1 until dn==1
then output to be zero until marker==1
..... and so on....

I couldnt work out how to do it not using a for...loop.

Thank you :slight_smile:

@traderuk99 , I think this is what you are looking for...

result = c>ema(c,10);

Its not - see:

marker

See Flip function
https://www.amibroker.com/guide/afl/flip.html

x = Flip(up, dn);

x = C > Ema(C,10); would do the same in your example

It would be different if dn variable would differ from the one of post #1
e.g.

up = cross(C, EMA(C,10));
dn = Cross(MACD(),Signal());

x = Flip(up, dn);

OK, after second read... it seems marker is an additional array to up and dn.

Do you mean like this?

up = cross(C, EMA(C,10));
dn = cross(EMA(C,10), C);
marker = BarIndex() % 10 == 0;

x = Flip(up OR marker, dn);
2 Likes

Thanks fxshrat - that's the one.

I love it when the plan comes together :smiley: :wink:

1 Like

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