Charles,

Basically the same approach, except that you would need the Sell statement to 
be conditional upon recognizing the bar as being the last bar of the day as 
opposed to an absolute.

So, instead of the absolute:

Sell = 1;

You would need:

Sell = <is this the last bar of the day>;

I don't trade intra day, so I'm not the best source of information for this. 
However, for backtesting purposes, there are a number of ways to recognize a 
date change, including looking into the future and comparing the day of year, 
day of week, etc. This will not impact your backtest results since in live 
trading you would know that it was in fact the last bar of the day without 
looking into the future.

e.g.
Sell = DayOfYear() != Ref(DayOfYear(), 1); // Look ahead one bar
SellPrice = Close;

Alternatively, you could check for the time of the bar and trade when 
recognized as the closing bar. That might depend on there actually being a new 
bar for that time of day, which for low volume stocks might not happen. Again, 
I'm out of my element on this one. But, there are a number of posts from people 
asking how to trade between time x and time y for a given trading day. You can 
search for those in the forum.

Using timeframe functions might work here too. But again, I haven't played with 
those yet either.

Mike

--- In amibroker@yahoogroups.com, "chuck_win" <ch...@...> wrote:
>
> Mike,
> 
> If I use 5-m data for intraday trading, how to sell at close on same day?
> 
> Thanks.
> 
> Charles
> 
> --- In amibroker@yahoogroups.com, Tony M <pqj100@> wrote:
> >
> > Mike,
> > Thank you very much. That works.
> > TM
> > 
> > 
> > 
> > ________________________________
> > From: Mike <sfclimbers@>
> > To: amibroker@yahoogroups.com
> > Sent: Wed, April 14, 2010 10:28:26 PM
> > Subject: [amibroker] Re: How to close at the same day?
> > 
> >   
> > Are you using end of day data, or intra day? If end of day, try something 
> > like
> > 
> > SetTradeDelays( 0, 0, 0, 0);
> > SetOption("AllowSam eBarExit" , true);
> > 
> > Buy = ...;
> > BuyPrice = Open;
> > 
> > Sell = 1;
> > SellPrice = Close;
> > 
> > Mike
> > 
> > --- In amibro...@yahoogrou ps.com, Tony M <pqj100@> wrote:
> > >
> > > Please help me with a simple exit strategy: when backtesting, I open my 
> > > positions at the open in the morning, how can I close at the close of the 
> > > same day? 
> > > 
> > > I can use ApplyStop( stopTypeNBar, stopModeBars, 1) to close at the 
> > > second day, but I can not figure out a way to close at the same day. 
> > > 
> > > Thanks,
> > > TM
> > >
> >
>


Reply via email to