Setting up an InTrade array


I am trying to create an array that is True for every bar that is part of a trade. I find it surpringsly hard and I think I'm missing something. First I have

SetOption("AllowSameBarExit", False );

to make sure there is no exits the same bar as an entry, and then I try this

bars_since_last_entry = Nz(BarsSince( Buy ));
bars_since_last_exit = Nz(BarsSince( Sell ));
in_long_trade = Nz(bars_since_last_entry < bars_since_last_exit);

but the "in_long_trade" array seems to be always only zeros.

I want to remove duplicate Sell/Buy/short/cover signals because I plot trade arrows and detailed info about the trades in in my AFL code and it gets messy if I don't filter duplicates.

As another try I did this:

in_longtrade = IIf(Buy, 1, 0);
in_longtrade = IIf(Ref(in_longtrade, -1) == 1, 1, in_longtrade);
in_longtrade = IIf(Sell, 0, in_longtrade);

But that doesn't work either. Not sure why, and if you see why I would love to know why :smiley:

I have a feeling this problem is already solved in some neat easy way, but I just can't find it, so any advice on how to setup this type of array is highly appreciated!


See Flip function.

Wow thanks, that was spot on! :hugs: Flip() instantly worked exactly as I was hoping.

I also noticed the "ExRem" in the manual and that made it even easier.

Just for educational purposes, do you know why my initial code didn't work?

You will get more out of it if you discover why for yourself (see below) - let us know if you need further assistance.

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