Exit trade if entry bar is against the trend

Forums ProRealTime English forum ProOrder support Exit trade if entry bar is against the trend

Viewing 9 posts - 1 through 9 (of 9 total)
  • #44160

    Hi

    I’m writing code

    to exit the trade if the entry bar is against the trend. I’ve simplified it into a price crosses SMA indicates the trend. Long side only.

    So if on entry it is a down bar then the strategy will exit the trade on the open of the next bar.

    Here’s the code:

    It’s behaving in two unexpected ways:

    1. It exits on the open of the bar of entry (not the next bar)
    2. It enters a trade even if the open is less than the SMA

    See attached image.

    Am I misunderstanding something about the code here?

    Broker is IG

    Market is XAUUSD Spot Gold A1 Contract

    Dates in the image are 14th Jan 2016 to 22nd Jan 2016

     

     

    #44171

    Cool! You just learned me a new commando. I wasn’t aware of nextbaropen. Nice! Thanks.

    Have a look at your line 6. Should you have there one < close? Now you are exiting on an upbar.

    #44196

    NEXTBAROPEN is depreciated keyword that does nothing in the recent probuilder language version. So at line 9, you are exiting your BUY order at the same moment than its open.

    For your second problem, please consider that at line 3, you are comparing the Open of the bar of when the code is read (at Close).

    #44199

    Thanks Nicholas

    The NextBarOpen is in the current user manual for probacktest I down loaded last week v5.1.2-20170404 .. no mention of it being deprecated. How do we feed this back to the PRT team?

     

    I’ll have a look at the second issue and comment.

     

    #44200

    Nicholas,

    Your comment:

    For your second problem, please consider that at line 3, you are comparing the Open of the bar of when the code is read (at Close).

     

    OK so I get it …. my code says this bar’s open>AV after the close and it will enter on the open of the next bar….

    I don’t see any way to implement what I want  “IF open crosses moving average then buy on this open”

    Unless there’s a openNextBar variable which I can’t find …. or a BUY 1 THISOPEN which seems just as rare 🙂

     

     

    #44208

    https://www.prorealtime.com/en/changelog_probacktest_10_1

    The variable “OpenOfNextBar” contained the opening price of the bar following the current one. This variable was removed because it is impossible to know this price in an automatic trading situation. This instruction should not be confused with “NextBarOpen” which is an instruction that can be used to place an order at the opening price of the next bar and is still available as shown in the last section.

    But “NextBarOpen” doesn’t help in your situation and it is useless in code since orders are always launch at the next bar open.

    #44210

    Thanks Again Nicolas. I’ll need to look at a different backtesting tool for this strategy … I’m thinking Python Backtrader https://github.com/mementum/backtrader combined with Pyfolio for basket testing.

     

    #44211

    You order is placed at some bar, which is the entry bar (conditions were met when the previous bar closed), so you’ll be able to tell the entry bar went the wrong way only when it closes.

    So if you place this code at the very beginning of your strategy it should do:

    Roberto

    1 user thanked author for this post.
    #44212

    Thanks Roberto

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

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