I changed all the ==0 to !=1 in the loop. Meaning that the previous bar's
position(lpos or spos) can't be in the same direction to create a new buy or
short. And I went back to initializing the loop with i=1. You might want to
set the AA backtester settings to rev entry signal forces exit.

I haven't been able to solve the buy on first bar issue. An exploration
shows Buy==0 on that first bar, so I'm truly stumped about why the
backtester thinks it should assume a bogus long position right off the bat.
In addition it took a position of 48 contracts on that one position (only
time) when the first line in my code is

SetPositionSize(1,spsShares);

On Mon, Nov 17, 2008 at 8:20 PM, onelkm <[EMAIL PROTECTED]> wrote:

>   Thanks Esteban
> I will try it out. Appreciate you sharing .... Larry
>
> --- In [email protected] <amibroker%40yahoogroups.com>, Esteban
> <[EMAIL PROTECTED]> wrote:
> >
>  > Here it is Larry. Sorry I didn't check in with the group over the
> weekend,
> > thus the delay.
> >
> > BuyCnd=some code to establish buy to use in loop;
> > SellCnd=some code to establish sell to use in loop;
> > ShortCnd=some code to establish short to use in loop;
> > CoverCnd=some code to establish cover to use in loop;
> >
> > lpos=0; spos=0;
> > for( i = 26; i < BarCount; i++ )
> > {
> > //Long side evaluation
> > if(BuyCnd[i] AND lpos[i-1]==0) //original buy sig
> > {
> > Buy[i]=1;
> > lpos[i]=1;
> > }
> > if(lpos[i-1]) //continue long
> > {
> > lpos[i]=1;
> > }
> > if(SellCnd[i] AND lpos[i] AND Buy[i-1]==0)
> > {
> > Sell[i]=1;
> > lpos[i]=0;
> > }
> > //short side evaluation
> > if(ShortCnd[i] AND spos[i-1]==0) //original short sig
> > {
> > Short[i]=1;
> > spos[i]=1;
> > }
> > if(spos[i-1]) //continue short
> > {
> > spos[i]=1;
> > }
> > if(CoverCnd[i] AND spos[i] AND Short[i-1]==0)
> > {
> > Cover[i]=1;
> > spos[i]=0;
> > }
> > }
> >
> >
> > One note. The first bar becomes a buy and I don't know why. I set i
> to 26 to
> > start on barcount 26 rather than to 1 trying to avoid this. Doesn't
> have an
> > effect.
> >
> > Hope the code helps you
> >
> >
> >
> > On Sat, Nov 15, 2008 at 9:18 AM, onelkm <[EMAIL PROTECTED]> wrote:
> >
> > > Esteban
> > > Would you please post your code, I have the same issue and have
> not
> > > gotten a loop to work.
> > > Thanks
> > > Larry
> > > --- In [email protected] <amibroker%40yahoogroups.com><amibroker%
> 40yahoogroups.com>, "Esteban"
> > > <EstebanUno@> wrote:
> > > >
> > > > Thanks. I was able to model what I want using a For loop like
> you
> > > > suggested. It was easier than I thought it would be ... I was
> > > hesitant
> > > > to even try. The nice thing is that you can do all the array
> > > processing
> > > > you can before the loop, and then use the arrays in the loop.
> This
> > > kept
> > > > the loop simple and targeted to my specific problem.
> > > >
> > > > It still runs quite fast, but there's only one loop.
> > > >
> > > > --- In [email protected] 
> > > > <amibroker%40yahoogroups.com><amibroker%
> 40yahoogroups.com>, "Steve
> > > Davis" <_sdavis@> wrote:
> > > > >
> > > > > This kind of problem can be solved by writing a for loop and
> > > setting
> > > > > the buy/sell signals one bar at a time. You will have complete
> > > control
> > > > > over the signals, but it will run somewhat slower.
> > > > >
> > > > > -Steve
> > > >
> > >
> > >
> > >
> >
>
> 
>

Reply via email to