Just getting started with an opening range strat, not as easy as I had imagined.

Forums ProRealTime English forum ProBuilder support Just getting started with an opening range strat, not as easy as I had imagined.

  • This topic has 11 replies, 4 voices, and was last updated 1 year ago by avatarArbu.
Viewing 12 posts - 1 through 12 (of 12 total)
  • #206417

    To get myself acquainted with ProRealCode I thought I’d write a trial strategy. I’m finding it a lot harder than I had expected. The glossary just doesn’t provide the explanations that I would expect. Anyway, my strategy is to look at the opening range of the S&P 500 for the first 30 minutes. If it stays within that for the following 30 minutes then I would set an order to buy as soon as it broke above the range and an order to sell if it goes below. There would be a stop loss at the opposite side of the range, and a take profit at two times the size of the range. Only one of the orders should be triggered. At the end of the day, any open position should be closed. I got this far:

    But it plainly won’t work because I can’t understand how to set the take profits and stop losses on my orders, I don’t know how to cancel one order once the other has been triggered, and I don’t know how to close the positions at the end of the day if they are still open (EXITSHORT exists, but EXITLONG seemingly doesn’t). Can anyone give me some help?

    Thanks.

    #206423
    • BUY   is to be used to enter Long positions
    • SELL is to be used to exit Long positions
    • SELLSHORT is to be used to enter Short positions
    • EXITSHORT is to be used to exit Short positions

    Which timeframe are you using?

     

     

     

    #206424

    like this
    after 21:30 closes in gain

    #206478
    • BUY is to be used to enter Long positions
    • SELL is to be used to exit Long positions
    • SELLSHORT is to be used to enter Short positions
    • EXITSHORT is to be used to exit Short positions

    Which timeframe are you using?

    OK, thanks. Should I be trying to place orders (if so, perhaps you can point me to where the terminology for this is), or should I just check on a tick by tick basis whether the desired price has been reached?

    I was going to use a 30 minute timeframe, so wrote my code accordingly.

     

    #206480

    Pending orders are fine:

    you should only make sure that your current price is lower than the entry price (for Long trades) or higher than the entry price (for Short trades), and that it is equal or greater than the distance required by the broker for S&P 500.

     

     

    #206522

    Thanks. I chose the 30 minute timescale so that I could refer to the Max price in the candlestick two periods before. When I run the backtest I have this selected, and I also check the box to run on a tick-by-tick basis (see attachment). But trades only ever seem to get closed out at the end of a 30 minute period. What am I doing wrong?

    Also, is there a way to save my backtests? I was expecting a save button in the backtest toolbar, but there isn’t one there.

    #206532

    Backtests cannot be saved. You can run it again.  You can export the details you need to an eXcel file by dragging them and dropping them into a spreadsheed.

    Your trades are not closed after 30 minutes as there’s no provision for that. I have added it:

    I added 4 lines at the beginning, so that every 30 minutes any open trade is closed.

     

    #206537

    It’s not the results of the backtests that I want to save, but the code that I have written. I suppose I can just copy it to a notepad and save it there, but I’m surprised that ProRealTime doesn’t seem to allow me the opportunity to save these scripts as files directly.

    I don’t want trades to be closed out at the end of 30 minute periods. I want them to be closed out as soon as the stop or take profit level is hit, as would be normal in reality. So they should be closed out during these periods. How do I manage that?

    #206538

    Also, you say that pending orders are fine. But the manual says “Limit and stop orders with specific levels are valid for one bar by default starting at the open of the
    next bar. They are canceled if not executed.” This is not how a pending order normally works. If they do get cancelled then they are useless and I have to keep testing the price at each iteration.

    #206541

    Your work is saved on PRT’s servers, but not until you sut down your platform. To overcome this, I often save my work by exporting the ITF file to my download folder as soon as I have made some major modifications/additions to my code. Even 2-3 times per hour, it’s not so time consuming.

    Pending orders are ALWAYS cancelled each bar, so you have to keep placing them again and again until you no longer need them.

     

    #206549

    Arbu said: “There would be a stop loss at the opposite side of the range, and a take profit at two times the size of the range”.

    I think the opening range should be HIGH[2] – LOW[2] . Your  calculated range  HIGH[2] – HIGH[1]  is incorrect , isnt it ?.  If so  :

    RANGE = HIGH[2] – LOW[2]

    The exit orders could be something like this:

    IF LONGONMARKET THEN
       SELL 1 CONTRACT AT (TRADEPRICE  + 2*RANGE) LIMIT
    SELL 1 CONTRACT AT (TRADEPRICE – RANGE) STOP
    ELSIF SHORTONMARKET THEN
       EXITSHORT 1 CONTRACT AT (TRADEPRICE – 2*RANGE)  LIMIT
       EXITSHORT 1 CONTRACT AT (TRADEPRICE + RANGE) STOP
    ENDIF

    Sorry for the code as text but it seems I have lost the <insert code> button !

    #206551

    Another issue is that if I want to run the backtest over a time period of a month, say, I can only do this on the 30 minute timescale or greater. Which is not a great representation of reality. I did use MT4 a few years ago, and, as I recall, it didn’t have this issue, and it also allowed me to save files as scripts. I’m thinking I might give up with this and go back to using that instead.

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

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