PureBytes Links
Trading Reference Links
|
I use the procedure I mentioned and I have no trouble displaying trade arrows. Once you use LastValue it screws everything up. The up and down arrows blink on and off or you lose them all together.
Depending on how you have the bar presentation preferences set in Tools > Preferences > Intraday, the close time of the bar changes. So you will have to pick one that produces the results you need. Mine is set to first tick in bar.
To find out when the bar really closes you can detect the time the bar changes and capture the system time when the bar changes. You can try this:
barChange = TimeNum() > Ref(TimeNum(), -1);
barChangetime = IIf(barChange , Now(4), 0);
barChangeDelay = IIf(barChange, Now(4) - TimeNum(), 0);
if(LastValue(barChangeDelay) == 0) StaticVarSet("ChangeTime", LastValue(Now(4)));
printf("barTime= %6.0f sysTime= %6.0f\n", TimeNum(), Now(4));
printf("barChange= %1.0f, change time= %6.0f \ndelay= %4.0f delta= %4.0f",
barChange, barChangetime, barChangeDelay, StaticVarGet("ChangeTime") );
fMA = MA(C, 2);
Plot(C, "Close", colorBlack, ParamStyle( "Price Style", styleBar, maskPrice ) );
PlotShapes(IIf(fMA > Ref(fMA, -1), shapeUpArrow, 0), colorGreen);
PlotShapes(IIf(fMA < Ref(fMA, -1), shapeDownArrow, 0), colorRed);
The above works with arrows. I didn't try other charting stuff. The problem is that during the day the ticks come so often I don't know if the above will capture times if the bar close is delayed waiting on ticks. Another problem is it gives wrong results if you move you cursor to a bar.
Hope this helps.
Barry
--- In amibroker@xxxxxxxxxxxxxxx, reinsley <reinsley@xxx> wrote:
>
>
> Thank you Barry.
>
> As usual your tips are useful.
>
> To permanently display the trading arrows and keep a visual history of
> the previous trades, I am still searching to calculate automatically the
> closing time on the last close related to the interval() displayed. For
> intraday backtesting and real trading as well.
>
> I keep your excellent idea to define the param step as 100 to jump one
> minute and it does not matter if the minute is 61 to 99. It's more simple.
>
> Best regards
>
> Barry Scarborough a écrit :
> >
> >
> > I suggest you don't use timenum(). If the market volume goes down there
> > is no guarantee you will send the order before the market closes. Miss a
> > tick it will not close when you think it will. Besides unless you use
> > LastValue(TimeNum()) when you move your cursor onto a bar then that is
> > what is returned by timenum. If you use the lastValue then it is safe to
> > move your cursor.
> >
> > This is the way my program does it:
> >
> > // trading time parameters in hhmmss, step is one minute intervals
> >
> > OpenTime = Param("Open time", 93000, 0, 235959, 100);
> > CloseTime = Param("Close time",155800, 0, 235959, 100); // set early
> >
> > // set closeTime early so your trades will have time to close that day.
> > I suggest you use MKT GTC orders so they will close during the night if
> > they do not close before the close time. Some folks think a MKT order
> > will fill immediately. Not so. It will not close until someone buys it
> > and that can be seconds, minutes or hours later. If you want to be flat
> > before the real close time pay close attention to the volume and set
> > closeTime even earlier, especially if the volume is low for that ticker
> > and it does not trade after hours.
> >
> > Set you system clock to the same time your data provider either manually
> > or with a clock program so it is close to real time. My system clock can
> > get off TWS 30 seconds during the day, or more.
> >
> > Then do the following:
> >
> > sysTime = now(4); // this is your system clock not bar time
> > tradeTime = sysTime >= OpenTime AND sysTime <= CloseTime;
> > CloseTime = sysTime > CloseTime + 10;
> >
> > The closeTime + 10 will close your positions 10 seconds after the time
> > you specify as the close time. If also stops collisions when you send an
> > order seconds before the close time and immediately try to cancel or
> > close it.
> >
> > // your logic will only send orders during your trading time
> > Buy = tradeTime AND yourBuyLogic;
> > Sell = tradeTime and yourSellLogic;.
> > ditto with short and cover.
> >
> > if(CloseTime) cancel all unfilled orders.
> >
> > if(CloseTime + 5) close all positions
> > The 5 second delay gives TWS or your broker time to cancel the orders
> >
> > if(CloseTime + 10) close all positions again to make sure it happens
> > If you monitor status and the position number = 0 you don't have to do
> > this but it won't hurt.
> >
> > If you are using IBs TWS then there are functions that will cancel or
> > close all orders.
> >
> > Barry
> >
> > --- In amibroker@xxxxxxxxxxxxxxx <mailto:amibroker%40yahoogroups.com>,
> > reinsley <reinsley@> wrote:
> > >
> > >
> > >
> > > Hi,
> > >
> > > I do that way. Not the best code as I did not find yet how to deal with
> > > interval().
> > > I code manually 205500 to close at 210000 in 5 minutes time period.
> > > I code manually 213000 to close at 220000 in 30 minutes time period...
> > >
> > > Regards
> > >
> > > // Defines market hours
> > > MarketOpen = 080000;
> > > MarketClose = 205500;// in 5 minute interval
> > > MArketON = TimeNum() >= MarketOpen;
> > > MarketOFF = TimeNum() >= MarketClose ;
> > > MArketON = IIf( MArketOFF == 1, 0, 1 );
> > >
> > > Buy = [ your conditions] AND MArketON;
> > > Sell = [ your conditions] OR MarketOFF;
> > > Short = [ your conditions] AND MarketON;
> > > Cover = [ your conditions] OR MArketOFF;
> > >
> > > shape = IIf( Buy , ExRem( Buy, Sell ) * shapeUpArrow, ExRem( Sell, Buy )
> > > * shapeDownArrow );
> > > PlotShapes( shape, IIf( Buy, colorDarkGreen, colorDarkRed ), 0, IIf(
> > > Buy, Low, High ) );
> > > shape2 = IIf( Cover , ExRem( Cover, Short ) * shapeUpArrow, ExRem(
> > > Short, Cover ) * shapeDownArrow );
> > > PlotShapes( shape2, IIf( Cover, colorDarkGreen, colorDarkRed ), 0, IIf(
> > > Cover, Low, High ) );
> > >
> > > zeek ing a écrit :
> > > >
> > > >
> > > > hello,
> > > >
> > > > anyone know the code for a system to close all open positions when the
> > > > market closes for that day.
> > > >
> > > > Basically a day trading position?????
> > > >
> > > > Then at the open of the next days sessions the system start again.....
> > > >
> > > >
> > > > thanks
> > > > zeek
> > > >
> > > >
> > > >
> > >
> >
> >
>
------------------------------------
**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|