I have a long only strategy based on Ichimoku signals and a number of filters.
I have already incorporated the following code into my strategy:
bi = BarIndex();
exitLastBar = bi == LastValue( bi );
Sell = /*your regular sell rules*/ OR exitLastBar;
however Ichimoku signals always continue for a number of bars into the future. This sometimes results in opening a position in a recently delisted stock (and holding it open) when backtesting. (And I definitely want to use a Norgate NDU 'Current and Past' WL, as I am backtesting this strategy in time slots before the GFC, right up to this week).
I have (unsuccessfully) tried:
AND NOT <Various functions including Date, Buy signal, etc > exitLastBar>
What is the function to prevent an entry on or after exitLastBar, even if the primary entry signal is true?
No need to write out the complete line(s) of code for me, just a pointer to the optimum/simplest function would be very helpful and I'll work out the syntax as a learning experience.
many thanks in advance,
If you're using Norgate NDU, then you can use the method described on Norgate's web site to correctly determine your delisting date: https://norgatedata.com/amibroker-faq.php#exitpriortodelisting
Including the coding from Norgate prevents entry after delisting and there are only a couple of positions (over 20 years of backtesting) that close out after delisting (2 and 3 days after). I played around with various modifications but no change, but I can live with it as it only has minimal influence on reported profit/drawdown/CARMaxDD metrics.
Thanks again, your input is much appreciated.
If you are using Pad & Align, you will likely need to modify the Norgate logic a bit, because a delisted stock will continue to have many days of data after it's delisted. Therefore, statements like this:
BarIndex() == (LastValue(BarIndex()) -1)
Won't really find the last bar of tradeable data. The other part of their logic:
DateTime() >= GetFnData("DelistingDate")
Will be true when you hit the delisting date, but not 2 days before.
Matt or anyone else,
So what does the norgate code need to look like if you have pad and align turned on.
I have been using the code at https://norgatedata.com/amibroker-faq.php#exitpriortodelisting, thinking I was doing the right thing.
delistedStock = DateTime() >= GetFnData("DelistingDate");
barsBeforeDelisting = (LastValue(ValueWhen(DateTime() == GetFnData("DelistingDate"),BarIndex(),1)))-BarIndex();