I've tried looking through the forums and can't seem to find my problem asked anywhere else, although I will admit I'm not exactly sure what the problem I'm currently facing is. Essentially I've got trading strategy that are meant to generate buy/sell/short/cover signals either right when the market opens or right before the market closes. I've been trying to use the TimeNum function with AND statements to ensure the time range is in the first/last 15 seconds of the trading day so that signals are only generated at the open or close. I've tried attaching the time function to part of an If statement and also to part of the buy command but once I do signals are no longer generated (even during the proper time). I believe the issue is that no value is actually being added to my variable TN but I'm not sure how to check/fix this problem. Any suggestions would be fantastic!
Thank you for the suggestion I've now identified the problem is that TimeNum () is returning 0 (or is not actually finding the current time).
Does anyone have any ideas why this may be occurring? I'm currently using data from IB and have everything set to daily candles. I'm trying to code so that my trades either buy or sell at the open/close (using a time function I would be selling in the first/last 15 seconds of the day).
I've written some code that runs a strategy on daily bars. I want to initiate the trades at the open or close of the trading day. I wanted to use the TimeNum() function but because I'm using daily bars it returns 0. Does anyone have any possible work arounds that would allow me to get the time? I'm specifically looking for the time at my computers location (computer is in New York).
I've written some code that runs a strategy on daily bars. I want to initiate the trades at the open or close of the trading day. I wanted to use the TimeNum() function but because I'm using daily bars it returns 0. Does anyone have any possible work arounds that would allow me to get the time? I'm specifically looking for the time at my computers location (computer is in New York).
I have reviewed the manuals and I'm sorry I had not realized daily bars come without time.
Thank you for the recommendation but isn't the
BuyPrice = Open
Function only used for backtesting? This strategy I'm working on is for live/automated trading. Or can I use the BuyPrice function to automatically buy at the open/Close for live trading?
It is for backtesting. As for "live trading" it depends how do you "live trade". You did not provide that information in your posts. It is really super-difficult to answer questions that lack basic information. I don't know what is in your mind.
IF you want to trade with Interactive Brokers, you can simply place MOO (Market On Open) or MOC (Market On Close) order. You can do this manually or automatically.
If you are into automated trading, you should read IBController 1.3.8 READ ME that covers PlaceOrder function and order types including MOO and MOC.
Supported order types are listed in TWS API docs: TWS API v9.72+: Basic Orders
You just pass MOO or MOC as order type in PlaceOrder call. It does NOT require you to use TimeNum().
You might however use Now() function because it gives you current CLOCK time if you want to act only in certain moments of the day.
It is however strongly discouraged to directly jump to automated trading for absolute beginners in coding.