You have a chicken and egg problem; You are not allowing a Buy until after a condition based on the last Sell. However, you will never have a Sell until after you've had a Buy!
You need to work on your logic before going any further. Otherwise, use LowestSince instead of LLV. e.g. LowestSince(Sell, Low); http://www.amibroker.com/guide/afl/afl_view.php?id=91 Mike --- In [email protected], "michaels_musings" <michaels_musi...@...> wrote: > > Hi All, > > I'm new to AmiBroker, but it does seem to be a very useful backtesting > package. While writing a backtesting script, I hit a snag on how to identify > when the last period the system had a SELL in. I also am not sure if the > code I pulled in for activating a Stop Loss is correct. > > Can someone give me a link to something that's been written already to fill > in "lastSellPeriod" and possibly a review if I did the "ApplyStop" correctly > to stop out at the price in the stopLoss variable? (All other comments on my > code welcome as well :) > > > Thanks, > Michael > > Code so far : > /*------------------------------------- > Buy = Buy when price has showed upward momentum by moving from flagPrice to > BuyPrice. > Sell = Sell at SellPrice. > StopLoss = Sell at stopLoss price. > > Notes: > Fixed trigger price(s), therefor only one trade open at any one time. > > -------------------------------------*/ > > flagPrice = 14.70; > BuyPrice = 15; > SellPrice = 15.3; > stopLoss = 14.70; > > // RoundLotSize = 1; > // SetOption( field, value ); > SetOption("InitialEquity", 100000 ); > SetOption("ActivateStopsImmediately", True ); > SetOption( "AllowSameBarExit", True ); > SetOption("CommissionMode", 3 ); > SetOption("CommissionAmount", .005); > SetOption("GenerateReport", 1 ); > SetOption( "ReverseSignalForcesExit", False ); > SetOption( "SeparateLongShortRank", True ); > SetOption( "RefreshWhenCompleted", True ); > SetOption( "RequireDeclarations", False ); > > SetPositionSize( 10000, spsValue ); > > // ApplyStop( stopTypeLoss, stopModePercent, 10, True ); > ApplyStop(stopTypeLoss,stopModePoint,stopLoss,ExitAtStop = 1,Volatile = > False, ReentryDelay = 1 ); > > lastSellPeriod = ????????; > lastLow = LLV( Low, lastSellPeriod ); > > okayToBuy = IIf(lastLow < flagPrice, TRUE, FALSE) > > Buy = okayToBuy AND High > BuyPrice; > Sell = Cross( High, SellPrice); > > /* ExRem is one method to remove surplus trade signals */ > Buy = ExRem(Buy, Sell); > Sell = ExRem(Sell, Buy); >
