Hi, I'm new to Amibroker, I've looked around the site, FAQ and AFL coding section and can't see an answer to my question below. If my question has already been answered previously, my apologies and a link to the previous answer would be great.
I am trying to write a simple trading system to buy a stock if the close price is greater than the close price in the last 200 days. "Buy = C>=HHV(C,200);" and sell the stock 50 trading days later.
I've tried the formula "Sell = BarsSince(Buy)==50;" but this formula is affected by any subsequent buy signals and will actually sell 50 days after the last time the buy signal was triggered not when I may have physically entered the trade. This becomes an issue if there are multiple buy signals before the sell trigger.
I've tried to add Buy=EXRem(Buy,Sell); and Sell = ExRem(Sell, Buy); but this doesn't help.
Ideally I would like it to pick up all the buy signals and then attach a corresponding sell trigger to each buy signal.
Any help would be greatly appreciated.