Hi, What is important to realize is that BuyPrice and SellPrice are arrays, with elements for each and every bar. By saying:
SellPrice = BuyPrice + 2; You are actually using *today's* BuyPrice + 2. Every day you are recalculating a new SellPrice using the new BuyPrice. To access an array value at some distinct point in the past, you can use the ValueWhen function. Just be sure to strip out redundant values (i.e. ExRem) when using it. e.g. UniqueBuys = ExRem(Buy, Sell); SellPrice = ValueWhen(UniqueBuys, BuyPrice) + 2; However, for your particular case, you would probably be well served by using ApplyStop function. I believe that a profit target stop and a maximum loss stop would accomplish what you describe. http://www.amibroker.com/guide/afl/afl_view.php?id=20 Mike --- In [email protected], "thomasoxford3rd" <thomasoxford...@...> wrote: > > hello fellow AB users! > > I'm a new user and forum-participant...amidst the various examples posted on > the website, I've seen many wherein a buy signal is entered when, say, > Cross(A, B) [ie, A > B] and you cover when Cross(B, SomethingElse). > > But surprisingly (or maybe i didn't look well enough!), I am having trouble > finding something as simple (?) as: > 1. say, you buy Apple shares prices test a support of $100. This is easy to > test: > BuyPrice = 100; > Buy = Ref(Low, -1) > Support AND Low < Support; [ie, if yesterday we were > above support and today we breached below, we enter]. > 2. a standard risk-reward ratio is say 1-to-2: ie, stoploss at $99 and take > profit at $102. So, what i'm having trouble is finding is some example to do > this common strategy. I tried: > SellPrice = BuyPrice + 2; > SellStop = BuyPrice - 1; > > Then however, i tried: > Sell = Ref(Low, 1 ) < SellStop OR SellPrice > High ; [ie, if > tomorrow's low is less than SellStop we get stopped out OR if today high is > higher than SellPrice is greater than the high, our take profit is hit] but > this does not seem to work. > > Any advise much appreciated! > thx > > ps > there is a slight subtlety on how to test if BOTH conditions are true but > first i'd like to learn how to walk before can try to run! >
