[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Help to reset ApplyStop



PureBytes Links

Trading Reference Links

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 againstHowever, 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);

 
__._,_.___

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___