Graham (or anyone), one more quick question if you don't mind. 

What is the easiest way to ensure that when I already have an open
Long position, that I don't open a Short and vice versa? Should I
place SetPositionSize inside the loop? 

Or is there some other way to specify in the original Buy and Short
rules not to Buy or Short if it's opposite is already true? I can't
test the inBuy or inShort variables because those only get defined
lower down:


SetTradeDelays( 1, 1, 1, 1 );
SetPositionSize(1,spsShares);

Sell = Cover = 0;
BuyPrice = SellPrice = ShortPrice = CoverPrice = O;

myMA1 = MA(C,4);
MyMA2 = MA(C,15);

Buy = (myMA1 > MyMA2);
Short = (myMA1 < MyMA2);
                
inBuy = inShort = 0;
ValueAtBuy = ValueAtShort = Null;


for( i = 0; i < BarCount; i++ )
{ //various trade rules here 
}




--- In [email protected], Graham <[EMAIL PROTECTED]> wrote:
>
> 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);
> >
> >
> >
>


Reply via email to