Buy/close a position right at open

Forums ProRealTime English forum ProOrder support Buy/close a position right at open

Viewing 15 posts - 16 through 30 (of 30 total)
  • #156400
    Possibly Vonasi didn’t notice this question :

    But if I use ProOrder then I don’t have to worry if the program closes or I loose internet connection right?

    Correct.

     

    1 user thanked author for this post.
    #156414

    Possibly Vonasi didn’t notice this question :

    There were a lot of questions Vonasi noticed but didn’t answer in the hope that others would do so first. Here is possibly the answer to another one of them.

    If there is no pre-market and so no pre-market candles then looking for one at 085900 isn’t going to find one even on a minute chart. The first  candle that meets the criteria is the TIME = 090100 or OPENTIME = 090000 candle and so to try to enter as early as possible we really should be using the 1 second chart.

    You will need to set the closetradetime for as close to the market close as possible and for when you know there will likely be a candle. Then if you run it on the 1 second time frame you can enter 1 second after the market has opened and exit 1 second before the market closes – as long as there are candles! It is best to give yourself a bigger window on the exit time as on low liquidity stocks that might have lots of missing candles and so you could fail to find one to close the trade on otherwise.

    The flag condition stops the strategy from opening a trade ever again.

    Not tested.

     

    1 user thanked author for this post.
    #156432

    There were a lot of questions Vonasi noticed

    Vonasi, great stuff as I did not dare to come up with an answer myself (see below).
    Don’t forget the

     

    Why didn’t I dare to come up with an answer like this/yours ? well, because I started to wonder what therookie actually wants to achieve with this. Not that this is my business, but I got intrigued somewhat. Actually my stance is : would it work (with the suggestion of Not).

    Before I forget, we might get a better grasp of what’s at task when therookie would not use a 1 second chart, but a 1 tick chart (which obviously would be a total waste of server bandwidth for the whole day, apart from two ticks).
    Or maybe 1 tick just does not work … 😉

    See the attachment.
    N.b.: I think I read somewhere that therookie wants to trade stocks like this; Notice that this is a 1 tick chart and see that it ran into a sheer 9 ticks from the opening (08:00) till 10:00. Now :

    What would we have gained when this stock would not be in our possession at the opening ? I say : nothing. By now we actually will have lost on it. Still *I* gained 9% on it today (see the 8.20% in the right hand border). … If I only had the stock at yesterday’s last bar

    So whatever it is what therookie really wants with this strategy, I think it is applied “wrongly” (between large quotes). Only if a first tick stays out for a while, it would work (quite similar for the first second). But it won’t stay out …

    Personally I think it actually *is* a strategy to work like therookie possibly intends; Be there at the open, bail out at the close. If you only can expect what will happen … (as usual – haha).

    Might I be correct in that therookie actually wants what I propose, then the solution is simpler (and even decent, I think) : Buy at the opening of the day’s last bar, sell at the day’s one but last bar (with a 1 second chart).

    #156435

    ONCE FLAG is not needed. All variables are defaulted to equal zero until a different value is declared. ONCE is only needed if you want a variable to start with a different value than zero from the first bar of a chart.

    1 user thanked author for this post.
    #156594

    Does this seem correct to you guys as an entry? FYI I will only use daily bars.

    There is no 085900 if you use a daily chart. You will have to trade on the one minute time frame to find a bar with a time of 085900.

     

    Ok, my understanding was that it would buy the next bar at market as soon as it opens with this code but I assume this is wrong. The logic in Easylanguange would be something like “if time > 0859 then buy next bar at market”. This would make Tradestation buy the next bars open (09.00) even on daily bars and even if there is no bar at 8.59. So if I understand you correctly there is no way to do this in a simple way with daily bars on PRT?

    And also using minute bars wouldn’t really help because there is no bar at 08.59 as the first bar only appears at 09.00.

    #156598

    There were a lot of questions Vonasi noticed

    Vonasi, great stuff as I did not dare to come up with an answer myself (see below).

    Don’t forget the

    Why didn’t I dare to come up with an answer like this/yours ? well, because I started to wonder what therookie actually wants to achieve with this. Not that this is my business, but I got intrigued somewhat. Actually my stance is : would it work (with the suggestion of Not).

    Before I forget, we might get a better grasp of what’s at task when therookie would not use a 1 second chart, but a 1 tick chart (which obviously would be a total waste of server bandwidth for the whole day, apart from two ticks).

    Or maybe 1 tick just does not work … 😉

    See the attachment.

    N.b.: I think I read somewhere that therookie wants to trade stocks like this; Notice that this is a 1 tick chart and see that it ran into a sheer 9 ticks from the opening (08:00) till 10:00. Now :

    What would we have gained when this stock would not be in our possession at the opening ? I say : nothing. By now we actually will have lost on it. Still *I* gained 9% on it today (see the 8.20% in the right hand border). … If I only had the stock at yesterday’s last bar

    So whatever it is what therookie really wants with this strategy, I think it is applied “wrongly” (between large quotes). Only if a first tick stays out for a while, it would work (quite similar for the first second). But it won’t stay out …

    Personally I think it actually *is* a strategy to work like therookie possibly intends; Be there at the open, bail out at the close. If you only can expect what will happen … (as usual – haha).

    Might I be correct in that therookie actually wants what I propose, then the solution is simpler (and even decent, I think) : Buy at the opening of the day’s last bar, sell at the day’s one but last bar (with a 1 second chart).

    I am not sure I followed everything 🙂

    Just to be clear I will explain again what it is I want to do and why. Observe that it doesn’t really matter to me if I use a daily bar or 1 minute bar or tick bars, as long as it buys as close to the open as possible.

    So I have a strategy that I have run on various stocks quite successfully for some time. I get a buy signal on my trading platform (not PRT) in the evening after the market closes and I take the trade manually in the morning at the open and then I keep it for 24 hours that is to say that I then manually close the position on the open the next day. Now my problem is that I sometimes get many buy signals and then I have to manually close the previous days positions and then one by one buy the stocks. Now as you understand this can take 1 or 2 minutes and by then the entry price can be quite different from my back testing results. I know the difference will not be huge and I am still profitable but I wanted to see if I could get live results that are closer to backtesting results and quite also decrease my stress of having to take many trades during a very short period of time and maybe missing the opening.

    Hope this explains why I want to do this 🙂

     

    #156599

    And also using minute bars wouldn’t really help because there is no bar at 08.59 as the first bar only appears at 09.00

    if time = 090000

    #156600

    And also using minute bars wouldn’t really help because there is no bar at 08.59 as the first bar only appears at 09.00

    if time = 090000

    Yeah I guess this should work but since this is the CFD market then sometimes the opening can be delayed and at precisely 090000 there might not actually be a bar. Would it still work if the actual data comes in at lets say 090010?

    #156601

    Possibly Vonasi didn’t notice this question :

    There were a lot of questions Vonasi noticed but didn’t answer in the hope that others would do so first. Here is possibly the answer to another one of them.

    If there is no pre-market and so no pre-market candles then looking for one at 085900 isn’t going to find one even on a minute chart. The first candle that meets the criteria is the TIME = 090100 or OPENTIME = 090000 candle and so to try to enter as early as possible we really should be using the 1 second chart.

    You will need to set the closetradetime for as close to the market close as possible and for when you know there will likely be a candle. Then if you run it on the 1 second time frame you can enter 1 second after the market has opened and exit 1 second before the market closes – as long as there are candles! It is best to give yourself a bigger window on the exit time as on low liquidity stocks that might have lots of missing candles and so you could fail to find one to close the trade on otherwise.

    The flag condition stops the strategy from opening a trade ever again.

    Not tested.

    Thank you I try this and play around with this code!

    #156602

    Each candle on a chart has two times. OPENTIME which is the opening time of the candle and TIME which is the closing time of the candle. So a daily candle cannot have an OPENTIME or TIME of 085900 because it does not open or closeat this time.

    This is why I told you to use a 1 second time frame. If there are no pre-market candles then there is also no candle with with a time of 085900 but you can get in damned close to the opening price by sending an order to open a trade on any candle with an OPENTIME greater than 085959. So if the first candle is OPENTIME = 090000 then the order will be sent and the trade opened at the next candle. This would be at 090001 or later if there is not a candle at 090001. This is as close as you will get to buying at the open.

    As someone else said you could just send an order at the close of the daily candle that would open at the open of the next time which will be fine if the open time is the open of the market.

    Put the following indicator on your daily chart to see what TIME and OPENTIMES your chosen instrument has.

    If you want to close mid daily candle then you have no choice but to use MTF but as I said there is a risk that if you choose to exit at say TIME = 213000 and there is no one second candle at 213000 and then there is not another candle until the next day then you will stay on the market overnight. So it is better to start looking for candles that are perhaps greater than 212930 and then you will get out as soon as there is a candle in the last 30 seconds before the market closes. Less liquid instruments might need a longer period to look for a candle and so perhaps result in an earlier exit.

    2 users thanked author for this post.
    #156606

    therookie – Please try to use quote a little less – it is making the topic very hard to read.

    • Be careful when quoting others in your posts. Only use the quote option when you need to highlight a particular bit of text that you are referring to or to highlight that you are replying to a particular member if there are several involved in a conversation. Do not include large amounts of code in your quotes. Just highlight the text you want to quote and then click on ‘Quote’.
    #156622

    I am not sure I followed everything 🙂

    Possibly the most crucial thing you must try to wrap your head around is :

    Your code (the whole sequence from top to bottom) will be called (executed) at each new candle. Thus suppose I have a 1 minute chart, then each new minute your code will be called (executed). If you have a 1 second chart, then each new second your code will be called. If you have a one day, chart then ….

    And what I said earlier, is that you should not have called your code the first thing of the next day, because most of the profit will have vanished already. Thus :
    Investigate Market Orders at the opening of the market. Look at the last closing price and try to follow the opening price; you will see a gap (in 99% of cases). This is because the price changes when the market is closed (very briefly said : because outside the market there’s also influence from buyers and sellers). And thus :

    You should buy at the last candle right before the market closes.

    Of course your signalling should match this;

    I get a buy signal on my trading platform (not PRT) in the evening after the market closes

    Thus that would be wrong. You should obtain the signal so early that you are still able to program your autotrade code. Like 17:20 for a market which closes at 17:30. Or as more early as you need the time to make your code(s).

    If not clear, just ask. And if this does not fit your ideas about your strategy, then fine ! Also, if in your opinion this can not work because your signalling can only work after-market, then let us know.

    1 user thanked author for this post.
    #156625

    OPENTIME which is the opening time of the candle and TIME which is the closing time of the candle

    thanks for that Vonasi, I hadn’t realised. But are the two terms used in the same way?

    I have a 1 minute algo that I had thought was trading at the opening of the FTSE with ‘time = 080000’

    In tests, ‘time = 075900’ is slightly worse, but still turning a decent profit, whereas ‘opentime = 080000’ bombs spectacularly – more than could be explained by any slippage between open and close.

    Is something else required?

    #156632

    Think of OPENTIME and TIME as just a label for each candle.

    If there is a candle every second then if you send an order at the close of the OPENTIME = 075959 candle then the order will be filled at the open of the next candle which will be at 080000.

    If you send the same order at the close of the TIME = 080000 candle then it will be filled at the open of the next candle which will be at 080000 (plus whatever microseconds of slippage there is!)

    I have a 1 minute algo that I had thought was trading at the opening of the FTSE with ‘time = 080000’

    Your trade will open at 080000.

    2 users thanked author for this post.
    #157618

    I just wanted to thank you all for your help. At the end I decided to use alerts with an associated trigger like another member suggested. That seems to be the simplest way to achieve what I want. I will run ProRealTime on my VPS  which hopefully is powerful enough to runt both Tradestation and PRT without affecting Tradestation automatic trading.

    had one more question but it doens’t belong in this thread so I will open another thread for that question.

    Once again, thank you!

Viewing 15 posts - 16 through 30 (of 30 total)

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