Hi,
I use the following code.
NB :
The automatic interval is correct for small TimeFrame ( under 1 hour). I
did not test it above.
If you use a 5' interval only, you can write : |MarketClose = 215500
for a market close at 220000|||
Best regards
|// Defines market hours
TimeFrame = Interval() / 60;
MarketOpen = 080000;
MarketClose = 220000 - ( ( TimeFrame * 100 ) + 4000 );// automatic interval
MArketON = TimeNum() >= MarketOpen;
MarketOFF = TimeNum() >= MarketClose ;
MArketON = IIf( MArketOFF == 1, 0, 1 );|
|*Buy* = *<your condition> **AND* MArketON;
*Sell* = ||*<your condition> *||*OR* MarketOFF;
*Short* = ||*<your condition> *||*AND* MarketON;
*Cover* = ||*<your condition> *||*OR* MArketOFF;
shape = IIf( *Buy* , ExRem( *Buy*, *Sell* ) * *shapeUpArrow*, ExRem(
*Sell*, *Buy* ) * *shapeDownArrow* );
PlotShapes( shape, IIf( *Buy*, *colorDarkGreen*, *colorDarkRed* ), 0,
IIf( *Buy*, *Low* - 2, *High* + 2 ) );
shape2 = IIf( *Cover* , ExRem( *Cover*, *Short* ) * *shapeUpArrow*,
ExRem( *Short*, *Cover* ) * *shapeDownArrow* );
PlotShapes( shape2, IIf( *Cover*, *colorDarkGreen*, *colorDarkRed* ), 0,
IIf( *Cover*, *Low* - 2, *High* + 2 ) );|
Le 04/08/2010 05:23, chuck_win a écrit :
Mike,
If I use 5-m data for intraday trading, how to sell at close on same day?
Thanks.
Charles
--- In [email protected] <mailto:amibroker%40yahoogroups.com>,
Tony M <pqj...@...> wrote:
>
> Mike,
> Thank you very much. That works.
> TM
>
>
>
> ________________________________
> From: Mike <sfclimb...@...>
> To: [email protected] <mailto:amibroker%40yahoogroups.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
> >
>