Code Market Trading Hours

Forums ProRealTime English forum ProOrder support Code Market Trading Hours

Currently, there are 0 users and 1 guest visiting this topic.
View all attachments
Viewing 11 posts - 1 through 11 (of 11 total)
  • #185378 Report

    Hi all, I’m a newbie to PRT (hopefully posting in the correct place) and was wondering whether anyone can help me with a simple (for you 🙂 line of code to specify market trading hours for a trade? With my limited knowledge, I’ve been able to write code for a very basic auto-trade that simply opens a long CFD share position with a market order as soon as the market opens:

    I don’t need to specify the date of entry, because I run a separate auto-trade for each position, before the market opens on the day of entry (I’m located in Australia, so I don’t want to wake in the middle of the night, when US exchanges open, to place my trade/s). My strategy only buys S&P 500 shares, so liquidity is usually good, and spreads narrow – when the market is open. But I noticed with one of my trades using the above simple code that the trade opened during pre-market trading, which I don’t want. So, presumably, I need to specify market hours within the code to prevent this happening? I’d greatly appreciate if any of you could advise on the following:

    1. What line/s of code will restrict my trade to open immediately when the market opens, not before? (Note, my PRT system’s time is set to local Australian time, ie UTC/GMT +11 hours; and the US market hours in this time-zone are currently 01:30 – 08:00 (am)); and
    2. It’s important for my strategy for the trade to execute as soon as possible – preferably within seconds after the market opens. To this end, is it better for me to set the timeframe for the auto-trade to 1-second, rather than my current setting of 1-minute? Will this potentially make the auto-trade open more quickly? (I noticed for some other trades I placed with my simplified code above – for stocks that IG doesn’t allow pre-market trading in, so they executed as desired after the market opened – that they didn’t execute until exactly 01:31, ie 1 minute after opening time, and consequently my buy price was around 1% higher than the open price).

    Thanks in advance,


    #185389 Report

    Hi there Andy,

    See below at the mouse pointer. I assume you have this set the same as I have, meaning that you can trade with PRT outside of regular trading hours. Switch that to the first option and retry.
    N.b.: NYSE = S&P500. ETH = Extended Trading Hours.

    Yes, a 1 second TimeFrame would be faster, as your code is called after the bars close. With a 1 second TF this is thus after each second, also the first. 🙂

    Good luck !

    PS: I am not 100% sure that the setting I showed helps for (block) trading. What it at least does is show you the charts live during ETH. If this doesn’t help, you’d have to look for BUY / SELLSHORT arguments that allow buying during RTH only. In PRT itself (graphical environment) this exists. I actually never saw that for program code. Maybe others know ?
    And regarding this … you wouldn’t need an autotrade program to accomplish what you want …
    Also, while referring to IG … I hope you know that AutoTrading only works with IG ?


    1 user thanked author for this post.
    #185392 Report

    Here you see the settings for Manual Trading.
    I think you would want the Market on Open (MOO).

    Watch out : these are the possibilities for PRT-IB (Interactive Brokers). For PRT-IG the possibilities are not the same. See the 2nd attachment for those.

    1 user thanked author for this post.
    #185531 Report

    Hi Peter, I appreciate you taking the time to look at this.

    Thanks for the advice on on the 1-second timeframe.

    In relation to the trading hours setting, I assume you mean the place at the end of the following pathway: Settings > Platform > Time zones & Trading Hours. I wasn’t sure if this setting defined only which data are displayed and which data are used for backtesting, rather than defining paramaters for auto-trading? But I’d be happy to give it a try. Unfortunately though, my window for this setting looks a little different to yours; more specifically, it’s missing the “Regular/extended hours” section that you’re suggesting I change, and mine doesn’t have any “ETH” versions of markets in the side menu. Please see my side-by-side comparison in the attachment below (could it be because we’re running different versions of PRT? mine is V11.1).

    In your second reply, you’re saying that I should be able to set up my desired trade using manual trading through PRT?  Thanks for pointing this out; I didn’t explore manual trading initially because I assumed that I’d need to use an auto trade to achieve the desired entry. I just had a quick look at the manual trading window and it looks like it may be suitable – essentially, I just need to be able to place a market order prior to market trading hours, that executes as soon as the market opens, but not during pre-trading (because the IG platform doesn’t appear to allow you to do this). So, I’ll have a closer look in the coming days.

    At the moment I’m only trading through IG; and therefore using PRT exclusively through it. What I didn’t actually know until I read your reply though, was that I could use PRT with Interactive Brokers as well. I also have an account with them, that I haven’t used yet, so this is very useful information.

    Thanks again Peter

    #185560 Report

    Hi again Andy,

    From a tweet, this text :

    It is now possible to trade during extended hours for the Nasdaq, Nyse and Nyse American markets if you have ProRealTime Trading account with Interactive Brokers. To enable this, go to Settings > Time zones and choose Extended Trading Hours.

    Also see the attachment. So you would need the IB version for that (my IG version shows the same as yours). Well, sort of, because *that* you could already do for IG. It’s the inverse you’d need (be able to block it). Anyway, with the order-buttons I showed (available in the IB version only) you should be able to do what you want (manually, which now seems to be what you need).

    I realise that it could be easier for me to try whether it works as intended than you getting your IB version to work (which also requires an IB subscription and more hoopla). Now if you could give me a stock that will rise after the weekend’s gap …




    1 user thanked author for this post.
    #185562 Report

    In advance of some possible testing, this is a FYI :

    It is not even easy to predict what will happen (when ETH is switched off) because prior to the ETH possibility (for me about a year ago) I already worked with orders during ETH for a couple of years, via TWS (IB’s Trader Workstation). Point is : these orders are (already were back then) nicely accepted in PRT (all is fully synced). All which did not want to work was move them (for price or limit) from within PRT while TWS initiated. But also : it is IB (or TWS) which allows for this type of orders (and many more than PRT supports) … I am not even sure what I am trying to bring across …

    All right – When ETH was not supported by PRT, something like a year earlier the ETC price movement already was visible (back then the yellow ball (meaning after-market / pre-open). This did not require the ETH setting which came about later. And because PRT just supports the ETH graphing (when switched on – that’s what the setting is for), this exactly doesn’t tell a thing about the possibility for trading (which thus already worked via IB even prior to the price movement being visible).

    Still, if you’d place that MOO order and NOT a regular Market order (this latter may go through during ETH anyway), it should work.

    Something else (you are not asking for) is that there’s also a small pre-market for Futures. I know that those do exactly what you want by means of normal Market orders (the order label stays grey until the market opens). I use it quite often, guided by again another future which opens earlier but behaves similar. 😉
    And this can explicitly not be done by AutoTrading (until someone finally gives us insight in other instruments from within the one we try to trade 😉 😉 😉 ).


    1 user thanked author for this post.
    #185642 Report

    Hi Peter, thanks again for outlining the possibilities. Unfortunately, I can’t provide a stock for testing that is certain to increase in value lol. Although, if I was Elon Musk I could issue a casual complementary tweet about something to achieve that outcome – oh, to have that much power :-). In any case, it’s my intention to start experimenting with my IB account, in order to compare their performance and transaction/holding/currency-conversion costs against IG’s; and also even run some simultaneous identical trades with both brokers to see if there are differences in execution times and prices, so I will also look at whether my desired trades can be set up more easily through IB-PRT as well. At this stage though, I’ll have a closer look at the manual trading facility of PRT (for IG) to see if I can achieve the desired order.

    So, you seem to be saying that the IB (TWS) platform may be able to implement this kind of MOO order on its own, but if it doesn’t then the IB version of PRT appears to do so, right?

    Thanks again mate.

    #185675 Report

    So, you seem to be saying that the IB (TWS) platform may be able to implement this kind of MOO order on its own

    Hi again Andy,

    Not sure whether I said exactly that because I think my example was the other way around (didn’t look back). But see 1st attachment, which is how I would fill the order form. Especially observe those two checkboxes.
    Compare with the 2nd attachment where I changed the MKT order to LMT, enabling them both checkboxes, me still being able to let it work out (fill) at RTH only. I never use(d) that, but it should work. … I always have the first checkbox checked.

    I can’t even test it with Tesla today because today all USA stocks are closed – also pre-market. Haha.

    My main message is that both IB/TWS and PRT are working synchronised, but that it is not always visible how to utilise that.

    1 user thanked author for this post.
    #185678 Report

    So today all is closed. I put a Limit order according the 2nd attachment in the previous post.
    See 1st attachment (open in new window to browse its width).
    The left-most window is a TWS chart. The middle is PRT (notice the RTH tag) and see the TWS-message in the right-most window.

    Would I have done that with what you see in the 2nd attachment – via PRT, exactly the same happens, with the notice this is a Market order (so, market for me means RTH indeed, no matter I have switched on ETH in Settings. Also, the way I gave the order in TWS implies a Market order after all (see the same error message in either case).

    Now see 3rd attachment. A Limit order via PRT. This shows as the 4th attachment (I left the Market order be). This has
    a. the ETH tag
    b. it is grey. This means that it’s not at the exchange (but is at the broker AFAIK).

    Last one is in the 4th attachment. This time I checked “allow to be filled ETH”. Notice what the TWS-message now tells … “4am USA” – this means Pre-market.
    I think I will be able to show the same via PRT (somehow) but I’m running out of attachment space. 😉
    The real message : it is quite tedious to make the examples and that it is clear a little. Hint for you : watch the 1044, 1043 and 1042 prices so you can match what happened with the emerging orders.

    It is totally obvious that tomorrow I am out for a party with some Tesla shares. But just in case I rather kill them (the cross on the tabs or even using the TWS main screen, or use the labels on the (black) charts you saw left-most). So again, all is nicely synchronised and I never ran into real problems using either (though PRT certainly does not advise to use all at random).



    1 user thanked author for this post.
    #185683 Report

    It is a good idea to get acquainted with what those colours mean.
    IBKR has extensive web pages for that.

    1 user thanked author for this post.
    #185819 Report

    Hi Peter, thanks heaps for going to the trouble of exploring these options. So the bottom line is that it appears that the IB TWS platform will allow you to place market orders prior to the start of either ETH or RTH, and to execute at the start of either ETH or RTH, as desired. The only thing I will make sure of with a test trade, when I activate the CFD facility in my IB account, is that the the RTH version of the order executes at the implied time. Unfortunately, it appears that IG simply won’t allow you to place this type of MOO order.

    And yes, as much as I appreciate you setting up these trades to show me the possibilities, I recommend that you kill the trade – I’d hate to be responsible for an adverse outcome lol (Tesla is whipsawing so much atm it’s probably a 50/50 proposition of losing big or winning big) 🙂

    I’m just reading up on manual trading in PRT (for IG) to see if there’s a suitable option. The “At market order” option looks promising, if it executes (or can be made to execute) at the desired time; I’ll let you know how I go.

    Thanks again mate

Viewing 11 posts - 1 through 11 (of 11 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login