NEWBIE – support needed creating a trading strategy based on time of day

Forums ProRealTime English forum General trading discussions NEWBIE – support needed creating a trading strategy based on time of day

Viewing 15 posts - 1 through 15 (of 20 total)
  • #198337

    Hello,

    Firstly, I’m totally new to this so any support would be much appreciated.

    The reason why I’m here is because I’d like to create and test a trading strategy based on the time of day.

    E.g.

    Execute a buy position on the FTSE100 at 8:00am irrespective of the market position.

    Then execute a sell of that position at 8:10am.

    Over time, I’d like to evolve this to be based on other factors e.g. buy IF previous close saw the market go up in the last 10 minutes of trading.

    I would very much appreciate any help on how to construct this.

    I’ve taken a look and I couldn’t find any parameters/indicators/variables.

    Thanks,

    R

    #198340

    Try this on 10 min, 5 min, 2 min or 1 min or less TF …

     

    #198341

    Not 100% sure about this : I think that Buy at (If Time =) 080000 may not work because the 08:00 is UK (normal FTSE100) opening time, and no candle/bar is active at 07:59 and thus nothing can happen at the end of the previous bar which would normally trip the If  (to become True) as proposed. And thus no Entry will ever happen.

    Assumed I am correct, the best thing to achieve is use a chart with 1second as timeframe and make the If

    or a 5 second chart and

    etc.

    #198344

    I just tried and my code works in backtest.

    If OP is with IG they make a 24 hour market in FTSE 100 anyway.

    #198346

    If OP is with IG they make a 24 hour market in FTSE 100 anyway.

     

    That’s why I tried to say : with Normal FTSE.

    But  I tested it too and it does not work. I don’t know how to find Normal indexes within IG (they all trade 24/7 ?) but below attached is the proof with the help of this code :

    I took care to capture the beginnings of the week (Sunday at 00:00) and as you can see those Sundays do not show a time of 00:00 at 00:00. The other days of the weeks do (because of the 24/7 thing).
    Might it be of importance – this is Amsterdam time (UK + 1) and it is Tech100 (Nasdaq).

    The 2nd attachment shows that the 00:00 time nicely shows as I expected : at bar 23:59 (this is a 1 minute chart). Thus indeed, once you have a bar prior to the opening, the opening can be captured because it is the closing of the prior bar triggering that. On Sundays no prior bar and in any normal index situation, also no prior bar at the opening (occurring each day).

    To be clear : the OP can use it as proposed also on Sundays, because with the 24/7 index trading starts at 00:00 and so a bar for 07:59:00 would exist. As long as the OP understands that there is no opening at all at 08:00 and / but that he could rely on related markets opening (Europe main land at 09:00 Amsterdam time); Related markets openings will surely influence the FTSE.
    🙂

     

    PS: I now see that the second vertical line in attachment #1 shows 22:00 instead of 00:00, but it is a bit hard to position on the correct “pixel”. But you will get the gist. But see 3rd attachment. Can’t make it better.

    #198369

    Thank you both for the quick response.

    This is super helfpful.

    However, I can’t seem to get any results when I run the backtest. I’ve set the timeframe from 3rd Jan 2022 to today and no results.

    Is it because I haven’t set the amount of the purchase e.g. £1 ?

    Where would I set that?

    Currently code looks like this:

     

    #198375

    What timeframe are you running on ?

    Timeframe is the setting as shown at red arrowhead on attached

    #198377

    I was running on 30 minutes but should that matter?

    Essentially, I’m trying to understand how to set the lot size.

    See attachment. When I hit the backtest button, nothing happens.

     

    #198380

    OK, I’ve found this and it seems to work allbeit some strange things I can’t explain.

    TradeON = (DayOfWeek >= 0 AND DayOfWeek <= 5)
    IF time = 080000 AND TradeON AND Not OnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    IF TIME = 080500 AND OnMarket THEN
    SELL AT MARKET
    ENDIF

     

    I “think” this is saying, for any business day i.e. monday to friday, open a buy trade at 08:00 and exit at 08:05. Is this right?

    The thing is that the backtest time frame doesn’t go back beyond 22nd June (i was hoping to test further back) and its not clear to me that the test has executed this trade every day.

     

    #198381

    30 minutes but should that matter?

    Yes it matters a lot … how can the code meet a condition at 08:10 (your exit) when only 1 bar appears every 30 mins … 1 bar at 08:00 and next bar at 08:30 so your exit at 08:10 gets missed altogether, hence no exit.

    Above is why I said below …

    Try this on 10 min, 5 min, 2 min or 1 min or less TF …

     

     

    1 user thanked author for this post.
    #198382

    I don’t follow.

    The code should just run on the backtest data set no? Irrespective of bar interval. I’m essentially asking the system to run a test on historical data so shouldn’t I expect it to simply “run” and give me the answer e.g.

    I’m asking the system to test every single trading day to see if the market rose between 8am and 8.10am.

    Surely, I should be able to get a result which shows how many days passed vs. failed and based on a particular lot size, what the PnL was?

     

    #198384

    I’m asking the system to test every single trading day to see if the market rose between 8am and 8.10am.

    Where is your code to satisfy above?

    In your OP – you specified to Buy at 08:00 and Sell at 08:10 – this is what my code provided on the link below does (but only works using TF’s 10 min, 5 min, 2 min or 1 min or less)

    https://www.prorealcode.com/topic/newbie-support-needed-creating-a-trading-strategy-based-on-time-of-day/#post-198340

    #198385

    Sorry I should have been more clear.

    Essentially:

    Buy and sell at set times in the trading day.

    Have this repeat every trading day (Mon – Fri).

    #198386

    Try my code as instructed – for example on 5 min TF – and you will see it works.

    My code will do what you ask above, but NOT on 30 min TF.

     

    1 user thanked author for this post.
    #198388

    Thanks I did that but then the backtest range is only 2 days. I wanted to see how the trade would fare over at least the past 6 months.

Viewing 15 posts - 1 through 15 (of 20 total)

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