I want to use the ValueWhen function to compare the value of a condition at the time of the most recent Buy to the current bar (for a sell signal). I know how to use ValueWhen but my problem is that if there are other Buy signals between my actual Buy and the current bar then it references the wrong bar.
That way the Buy will only be true on the bar that the two RSIs cross, and your ValueWhen will then work as expected.
If you want to preserve the multiple Buy signals for all bars the criteria are true (known as a state signals), then if the exit is dependent on a value when the trade is entered at the initial Buy, you’ll have to resort to a loop for the Sell. Such as in this example: http://www.amibroker.com/kb/2007/03/24/how-to-plot-a-trailing-stop-in-the-price-chart/