Hmmm, shall we extend the idea somewhat, to long and short trades?

Does this look sane for an exit on the first profitable close?  What
am I missing?
//////////////////////////////////////////////////////////
Buy = conditions;
Short = conditions;
Sell = Cover = 0;
inBullTrade = inBearTrade = 0;

for( bar = 1; bar < BarCount; bar++ )
{
  // LONG SIDE
  if( inBulltrade[bar-1] == 0 AND Buy[bar] )
  {
    inBulltrade[bar] = 1;
    BullHoldC[bar] = Close[bar];
  }
  else
  {
    inBulltrade[bar] = inBulltrade[bar-1];
    BullHoldC[bar] = BullHoldC[bar-1];
  }

  if( inBulltrade[bar-1] AND Close[bar] > BullHoldC[bar] )
  {
    Sell[bar] = 1;
    inBulltrade[bar] = 0;
  }
  else
  {
    Sell[bar] = 0;
  }

  // SHORT SIDE
  if( inBeartrade[bar-1] == 0 AND Short[bar] )
  {
    inBeartrade[bar] = 1;
    BearHoldC[bar] = Close[bar];
  }
  else
  {
    inBeartrade[bar] = inBeartrade[bar-1];
    BearHoldC[bar] = BearHoldC[bar-1];
  }

  if( inBeartrade[bar-1] AND Close[bar] < BearHoldC[bar] )
  {
    Cover[bar] = 1;
    inBeartrade[bar] = 0;
  }
  else
  {
    Cover[bar] = 0;
  }

}
//////////////////////////////////////////////////////////

--- In [email protected], "Fred" <[EMAIL PROTECTED]> wrote:
>
> That'll certainly work ... but it's overkill and run times will 
> expand dramatically.
> 
> --- In [email protected], Graham <[EMAIL PROTECTED]> wrote:
> > because an intital sell signal was not defined to enable the use of
> > exrem, or other methods to exclude surplus buy signals you probably
> > need to use a loop method
> > something along these lines
> > 
> > buy = conditions;
> > Sell = 0;
> > intrade = 0;
> > holdO = Null;
> > 
> > for(i=1;i<BarCount;i++)
> > {
> >  if( Buy[i] AND intrade[i-1]==0 )
> >  {
> >   intrade[i] = 1;
> >   HoldO[i] = O[i];
> >  }
> >  else
> >  {
> >   intrade[i] = intrade[i-1];
> >   HoldO[i] = HoldO[i-1];
> >  }
> >  if( O[i] > HoldO[i] AND intrade[i-1])
> >  {
> >   Sell[i] = 1;
> >   Intrade[i] = 0;
> >  }
> >  else
> >  {
> >   Sell[i] = 0;
> >  }
> > }
> > 
> > 
> > On 8/9/05, Fred <[EMAIL PROTECTED]> wrote:
> > > The example I provided would of course be for same day trading on 
> the
> > > buy side ... If what you want is delayed a bar because you are 
> buying
> > > on the Open of the following bar then it would be one bar less 
> i.e.
> > > 
> > > Sell = O > Ref(O, -(BSB - 1));
> > > 
> > > If this doesn't work for you then you need to be more specific 
> about
> > > exactly what is happening and how that compares with what you are
> > > after.
> > > 
> > > 
> > > --- In [email protected], "Peter" <[EMAIL PROTECTED]> wrote:
> > > > Fred
> > > > Thanks but been there.
> > > > As I understand it BarsSince(Buy); will return the bars to the 
> last
> > > Raw
> > > > buy signal. You may have the actual Buy entry then one or more
> > > other buy
> > > > signals which are ignored ( assuming you include the line
> > > > Buy=ExRem(Buy,Sell);) then the sell signal. BarsSince(Buy); will
> > > return
> > > > the bars to last Buy signal not the one where you entered the
> > > trade.
> > > > That's the bit I can't solve.
> > > > Peter
> > > >
> > > >
> > > > -----Original Message-----
> > > > From: [email protected] 
> [mailto:[EMAIL PROTECTED]
> > > On
> > > > Behalf Of Fred
> > > > Sent: Tuesday, 9 August 2005 7:38 a.m.
> > > > To: [email protected]
> > > > Subject: [amibroker] Re: Exit on first profitable open
> > > >
> > > > Assuming you have an impulse type buy i.e.
> > > >
> > > > Buy = Cross(X, Y);
> > > >
> > > > then ...
> > > >
> > > > BSB = BarsSince(Buy);
> > > >
> > > > ... should give you how many bars it's been since the buy
> > > occured ...
> > > >
> > > > Then assuming that you also bought at an opening ... then ...
> > > >
> > > > Sell = O > Ref(O, -BSB);
> > > >
> > > > --- In [email protected], "Peter" <[EMAIL PROTECTED]> wrote:
> > > > > Hi
> > > > > After spending a huge amount of time trying to code an `Exit 
> on
> > > the
> > > > > first profitable open' I give up.
> > > > > Is anyone willing to share the code for what should be a very
> > > simple
> > > > > exit?????
> > > > >
> > > > > Any help would be appreciated!!
> > > > > Peter
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > 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 other support material please check also:
> > > > http://www.amibroker.com/support.html
> > > >
> > > >
> > > > Yahoo! Groups Links
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 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 other support material please check also:
> > > http://www.amibroker.com/support.html
> > > 
> > > 
> > > Yahoo! Groups Links
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > 
> > 
> > -- 
> > Cheers
> > Graham
> > AB-Write >< Professional AFL Writing Service
> > Yes, I write AFL code to your requirements
> > http://e-wire.net.au/~eb_kavan/ab_write.htm
>


Reply via email to