Because AB AFL goes through each line if you define something later then it will override previous results.
When you use a loop it interupts this normal flow as well I find that if I am defining or changing trade signals with a loop it is best to incorporate the other exits within the loop. ie define them as conditions. This may be just because I have not found another way to do it. In this case add the actual price conditions to the loop and remove the applystop Sorry I do not think I explained this very well, so hope you get my meaning. -- Cheers Graham Kav AFL Writing Service http://www.aflwriting.com 2008/7/12 ozzyapeman <[EMAIL PROTECTED]>: > Hello, would appreciate if anyone could help me with fixing this stop > problem. > > I want to apply a stop on either a Buy or Short, should the price move > against me by 20 pips on a Forex trade. I am able to code it (see below) and > run it in the backtester. The trades correctly get stopped out at 20 pips > against. However, new Buys and Shorts do not happen until the original, and > now "phantom", Buy or Short runs it's course. So as far as entering new > positions is concerned, it's as if the stop command is not even there! I > want to enter a new Buy or Short immediately after a stop, so long as the > Buy or Short rules are currently true. > > This quirk leads me to believe that some variable is not being reset > correctly. But whether I place the stop command inside the loop or out, I > get the same result in the backtester. How do I reset the variables > correctly so that the program is ready to Buy or Sell again as soon as a > stop has occured? > > > Sell = Cover = 0; > BuyPrice = SellPrice = ShortPrice = CoverPrice = O; > > myMA1 = MA(C,4); > MyMA2 = MA(C,15); > > Buy = (myMA1 > MyMA2); > Short = (myMA1 < MyMA2); > ApplyStop(0,2,.0020,1); > > > inBuy = inShort = 0; > ValueAtBuy = ValueAtShort = Null; > > for( i = 0; i < BarCount; i++ ) > > { //various sell and cover rules > > } > > Buy = ExRem(Buy, Sell); > Sell = ExRem(Sell, Buy); > Short = ExRem(Short, Cover); > Cover = ExRem(Cover, Short); > SetPositionSize(2,spsShares); > > >
