2 minute time frame in strategy

Forums ProRealTime English forum ProOrder support 2 minute time frame in strategy

Viewing 15 posts - 1 through 15 (of 31 total)
  • #138496
    nwa

    Hello, as a preamble I’ve just learned coding in the last few months.. however I wish to code a scalping strategy combining candles on the 2min, 5min and 10min charts simultaneously to determine entries and exits but it seems if I’m using the 2min chart as my base all upper time frames must be multiples of 2min, meaning I’m unable to account for the 5min chart in the same code. Is my description of the problem accurate and if so is there any way to get around this issue? Cheers

    #138499

    5 is not a multiple of 2, so you need to switch to either 1 or 5.

    Maybe you can use 2,6 and 10, but I never tried that. I am not sure if 10 is allowed not being a multiple of 6 (but it might be accepted as it is a multiple of 2, the lowest one).

     

    1 user thanked author for this post.
    avatar nwa
    #138500

    @nwa – You posted your question attached to a topic about MTF for indicators when it is a question about MTF for strategies so I have split it from that topic and created a new one in the correct place. Please re-read the forum rules before posting again.

    You cannot use a 5 minute time frame and with a default time frame of 2 minutes in a strategy because 2 does not divide equally into five.

    On a seperate note you should also be wary of using ‘unusual’ time frames as the results of any back tests can be drastically different just based on which exact hour, minute or second your strategy is first launched on.

     

    2 users thanked author for this post.
    #138575
    nwa

    Thanks guys and apologies for posting in the wrong location. I’m attempting to convert a manually traded strategy and the all historical back test data is based off the 2, 5 and 10. I get that 5 is not a multiple of 2 so it would appear this strategy cannot be coded in ProRealCode. Unless as you mentioned I think I might try using the 1min as the base time frame and then referencing the 2, 5 and 10 as these are all multiples of 1, using the 2min for order placement and cancellation. I have a large chunk of the strategy coded in Pinescript from Tradingview. Noted re when the exact time of the back test start impacting the results, cheers. Any other thoughts, comments, questions, suggestions please fire away.

    #143803
    nwa

    I tried pro-backtesting a strategy across 2m, 5m and 10m using the TIMEFRAME functions, using the 1m chart as my basis to allow it to run, however the results are inconsistent and I don’t understand why.
    The idea is to take hammers long on the 2m chart after a touch of the 2,5 and 10m bollinger bands.
    Entries are taken on the 2m as they should but there also appears to be random entries detailed inconsistent with the code as I see it i.e. entries taken where no hammers are present on the 2m.

    – Could someone review and offer guidance on where the error is or on what I’m not seeing?
    – Is there any sign of PRT11 for IG accounts?
    – Is there a possibility to incorporate running systems with timeframe values not multipiles
    of each other on future updates of PRT as opposed to having to go to the lowest time frame in an attempted workaround?

    Any questions / comments please let me know.

    #143804
    nwa

    BTW I tried setting the back test start time to 00h00m00s to try and ensure no potential interference here but the results were the same.

    #143845

    – Could someone review and offer guidance on where the error is or on what I’m not seeing?
       you should tell us details about the error, INCONSISTENCY can be anything
       Did you try adding UpdateOnClose with non-default TF’s?
       Try also adding TIMEFRAME(default) at line 13

    – Is there any sign of PRT11 for IG accounts?
       This is off topic, there are other places to ask this (please do not add unrelated questions, thank you 🙂 )

    – Is there a possibility to incorporate running systems with timeframe values not multipiles
       No

     

    #143849

    In my experience a number of factors exist. For example if you run a 4 hr program on a 5 minute chart, you can find your stop being moved every 4hrs if meeting the criteria, only to be reset after the 5 minute periods back to the initial stop loss, it essentially toggles your stop, for some programs this is actually beneficial in relation to results. So running code on lower timeframes to make MTF work can effect the trails or other code you put in. You tend to have to factor in what the code will do when it is rechecked after the LTF period as it re-runs the code criteria, I’ve not got my head around it totally yet, but assume to remove anything stating “timeframe (Default)” that may effect lower down code as well, though not applicable to your code, its possible (without having ratified it) that the code for stops at least goes to the default timeframe by default and has to await the entry code timeframe to resume itself..  Still working it out this end too, but this is certainly my experience to date without fail if running a program on a lower timeframe whether MTF or otherwise it behaves differently and can even enter slightly diferently…. .

     

    With respect to your code, I suspect the stop you set is toggling every 2 minutes but havent checked it, I don’t recall reading what pair you are trialling this on, it may help to know to test.. try observing on the demo for what the stop is doing, it could remove itself altogether until the next 2 minute bar, it can be an anomaly MTF…

    #143850

    I’ve not looked ot see if it works differently, but rather than have the system work out ATR for your stop, code in the ATR using code to work it out in the  timeframe you want, perhaps it is a quirck of the system to do some workings in the default timeframe relating to stops, who knows, but worth a try, cant really look at it more without knowing the pair to observe and try out..

    #143853

    So this code on EURUSD, not actualy too bad but needs some tweaking…..

    One issue  when I looked at your code after running and seeing all the losses is that your ATR stop is dynamic. So I simply added a 20pip stop and hey presto! However it took a drawdown on startup, so I would want to eliminate that a bit, look at the correct item to trade on, select times to trade that are optimal, and perhaps put in some other filters see if they minimise losing trades, but the main problem I see is that your stop is dynamic based on the ATR at the time and this results in multilple losses, possibly a toglging stop too, just thought I’de put that up for you – tweak the times, adjust stop management, look to add some filters to reduce losing trades… The code below is not a solution,,, just highlighting some factors to look at.. run it on eurusd 1 min – I ran it on 200,000 units which gives approx 6 or 7 months. by End of year for your broker issues.

     

    #143879

    So heres a not traded much but intersting results on DJI 1 minute timeframe.

    I wasnt aware of “mn” abreviations, however putting the usual time codes in improves results slightly. I added volume and time limitations. On £1 per pip this does not backtest with more than an £80 drawdown if starting negative over 6 or 7 months, and generally stays positive with the max in 6 months being 4 stopouts. The mean win is £68.80 so approx a little over 3:1 on average. Add some startup risk management code is possibly a useful addition. I like to risk manage programs for a 1% startup max risk to quit and review if it draws down to that, using the max consecutive losses as a divisor for risk..

    Anyway, might even give that a go live and see…

    Hope it helps.

     

    #143886
    nwa

    Roberto:

    – you should tell us details about the error: Trades being taken on the 1 minute when no hammer present on the two minute. ‘Updateonclose’ as per your suggestion and the updated code from Philstrading  looks to have solved the issue reviewing the back test entries, thanks for the input

    – Is there any sign of PRT11 for IG accounts?
    This is off topic, there are other places to ask this (please do not add unrelated questions, thank you 🙂 ): Apologies, noted 

    – Is there a possibility to incorporate running systems with timeframe values not multipiles? No : Ok, thanks anyways

    Philstrading:

    Thanks massively for the rework as it looks to have resolved my issue, it helps a great deal.

    Originally I was testing on EURUSD however as per attached screenshot since June without some mods to the bare bones code it’s a non runner..

    It seems I can only access 100,000 units on EURUSD on the 1min chart for backtesting this system, can you advise how to access 200,000? I’ve currently an a/c with IG.

    ‘Add some startup risk management code is possibly a useful addition. I like to risk manage programs for a 1% startup max risk to quit and review if it draws down to that, using the max consecutive losses as a divisor for risk..’ – I’d be interested to learn more regarding this point, could you explain or expand on your approach to this as I’m new to coding / developing systems especially with regards to more nuanced risk management?

    Any questions let me know.

     

     

     

     

    #143894

    Well its good to work through the programming learning curve to get things ingressed, but for sure, theres a lot gained from the forum so I’ll share a titbit. For 200,000 units you need premium version, what you have is likely the PRT complete version. You can ask IG for a small fee per year for premium I think, not sure, but the data and version is being improved later this year.

    I’m pretty new since May this year, but When programming, as with trading, I’m finding its better to not risk too much on any one trade, even 1% can draw you down significantly if you have strings of drawdown, so I find its better to risk fractional % and look to gain anywhere to betwen 1% to 10%, per program per year, sometimes more depending on program, that way risk is minimised and you can still breach 100% a year just runing a few programs. However there’s always a chance of failure, so risk managing that is important. So for your program lets take a £1000 account as an example. With higher amounts you can risk less percentage so I’ll add 2 codes here one for a £1K account another for a £20K account with different risk profiles, as this program looks at about 5% over 6 months for a £20K account, or 10% a year give or take using a startup amount of 5 drawdowns not breaching 0.5% and for a 1K account 5 drawdowns not breaching 2.5%, smaller account needs to risk more of course, you can risk more on larger accounts depending on your risk tolerance of course.. Codes can be tweaked to personal risk tolerances.

    The codes below increase the amount as soon as a profit level is reached to weather max drawdown experienced to date, then limits it to the maximium trade, probably have to check margin tolerances as well but this is just and example and you coul dincrease the amounts for more of a buffer. So lets say I want to risk 0.5% overall on the program trial startup, for a 20K account 1% is £200 so I want to risk £100 maximum. the program drawdown is 4 trades, so  I want to risk 5 trades drawdown on startup, therefore my risk is £100/5trades = £20 per trade. stop loss is 20pips so I need £1 per pip to start with and then increase the amount once certain profit levels are met then keep it there and reduce if the profit falls below again, there may be other ways to code it but this is practical and it works.

    If it ever fails and reaches your risk figure the program should quit only risking your set amount of risk overall, 2.5% for 1K and 0.5% for 20K which in this case is very comfortable and I tend to look for as high a percentage per year while only risking 0.5% to 1% overall program failure risk where possible, smaller account are lmited. So here’s the 2 codes according for £20K at about 10% a year and £1K at significantly more around 60 % per year… its not about large figures on each trade, its about steady financial growth compounding but thats pretty good for minimal risk and I apply this to all my programming now to limit risk.

    There’s a course here on ssome fundamental programming, the one half is free and its a modest fee for something modestly more in depth, the rest is down to knowledge and experience with some pointers from this forum I guess… hopefully you did this course..

    Hope that helps

    2 users thanked author for this post.
    #143896
    nwa

    Great thanks for that Phil, looking forward to digesting it when I get a bit of time. I’ve coded stuff up in pinescript and a small amount in PRC so I’m learning as I type

    I worked up another bit of trend following code which was calling functions from outside of the 2 minute area and calling my own user indicator functions which threw up more problems wrt stop calculation and order placement / execution so instead I just copied all the raw code into this area calling minimal external functions and the order management worked perfectly (as far as I could see) following. Makes the code a bit more untidy / unwieldy but get’s the job done in the short term anyways.

    #145013
    nwa

    A problem I am encountering is that running a 2min system on the 1min chart, the buy / sell order only stays in place for the 1st minute of the 2 minute bar owing to the nature of the of the ‘stop’ order code, i.e. it only stays in place for one bar, this being the first 1minute bar of the two minute candle. This leads to missed entries when the order evaporates after 1 minute and there is no order in place to get hit if the two minute bar breaches the prescribed level.

    Can anyone suggest a way of coding the order to remain in place for both of the two 1 minute bars of the two minute bar?

    Please see below example code below to see the order placement / cancellation in action…

     

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

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