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