Hi guys,
I've been away from Amibroker for quite a while, and I’ve decided to get back into it. I see that I’ve forgotten much more than I initially thought because I’m getting stuck on something that seems trivial.
I’m trying to apply a sample of code from a book by Howard Bandy, focusing mainly on closing an open trade after a predetermined number of bars. An example of this was already discussed in the following post: https://forum.amibroker.com/t/fixed-holding-period/11560
I have the following question: Is it really appropriate to use 'BarsSince(Buy)' for the trade exit?
I’m testing with the following code, and I see that if I set the exit at 10 bars, it seems to work fine.
SetTradeDelays(0,0,0,0);
BuyPrice = C;
SellPrice = C;
MA1 = MA(C,3);
MA2 = MA(C, 16);
Buy = Cross(MA1, MA2) AND Status("BarInRange");
Sell = BarsSince(Buy) >= 10;
//Buy = ExRem(Buy, Sell);
//Sell = ExRem(Sell, Buy);
Filter=1;
AddColumn(C,"C",1.4);
AddColumn(Buy,"Buy",1);
AddColumn(Sell,"Sell",1);
AddColumn(BarsSince(Buy),"BarsSince(Buy)",1);
However, if I set it up to 15 bars, SELL remains at 0, and the exit doesn’t occur.
I’m aware that I have a lot to review and that it’s possible to set up the exit using a stop-loss defined with a fixed number of bars, but I would want to know how to do it directly with SELL. I’d really appreciate it if someone could give me a hint as to what I might be approaching incorrectly.
Thank you very much!