This kind of problem can be solved by writing a for loop and setting the buy/sell signals one bar at a time. You will have complete control over the signals, but it will run somewhat slower.
-Steve --- In [email protected], "Esteban" <[EMAIL PROTECTED]> wrote: > > I have a buy condition and a sell condition. The sell condition is > dependent on how long ago the buy was, among other things. Example: > > Buy=buyCondition; > barsAgo= barsSince(Buy)>1; > Sell = sellCondition and barsAgo; > > The problem is if a new duplicate buy signal occurs when a long > position is already held. I want the barsAgo variable to reference > the first actual signal in the series, and not show true just because > the previous bar had the same conditions as the actual original buy > signal. > > When I use exRem(Buy,Sell) to remove extra bars, it gives me a Sell > variable not initialized error, unless I place it after the Sell > statement, but that has the effect of evaluating the subsequent buys > for the barsAgo statement. Am I clear with my question? > > // I get initialized error. > Buy=buyCondition; > barsAgo= barsSince(Buy)>1; > exRem(Buy,Sell); > Sell = sellCondition and barsAgo; > > // All buys are evaluated for barsAgo, not just the original one. > Buy=buyCondition; > barsAgo= barsSince(Buy)>1; > Sell = sellCondition and barsAgo; > exRem(Buy,Sell); > > I've been going around in circles on this one for a while. Maybe > someone can help. >
