Stop loss only during set trading hours

Forums ProRealTime English forum ProOrder support Stop loss only during set trading hours

Viewing 15 posts - 1 through 15 (of 17 total)
  • #199012

    Hello!

    I’m working on a system that’s only active during US trading hours. That is, I’ve set the trading hours in PRT and have added a set trade time to my partial close.

    An issue I’m trying to solve is how to make the stop loss only active during the trading hours the system is restricted to. What happens is that the stop loss is set during trading hours, but if the prices closes beneath/above the stop outside trading hours, it still triggers.

    I figured I might add the following to mittigate the issue

    However, I reckon this will set the stop loss to a new level when US trading resumes the next day.

    Any ideas how I could set it to the original stop loss, or another way to solve this?

    Thanks!

    #199032
    JS

    Hi @ProRealPierre

    You can use a (pending) STOP order…

    If LongOnMarket and Close > mySL then

    Sell at mySL STOP

    EndIf

    (If Close does not touch the pending stop order, it will be placed again every next bar)

    #199033

    I figured I might add the following to mittigate the issue

    Yes, that would be the solution.

     

    However, I reckon this will set the stop loss to a new level when US trading resumes the next day.

     

    What JS mentions may also do jobs, but it requires some imagination to let it do what you want. Still it will do about what you want, but change it to this :

    It is different to the sense that this operates at the bar level (each time again), while the Set Stop Loss is set once (or twice in your case 😉 ). The Set Stop Loss will therefore be more efficient, generally.

     

    Not if you set up the sl variable properly;
    If you only assign that a value at your Buy (or SellShort) command and leave it unchanged while OnMarket, the next day after market open you can just let this part go again :

    (which means it is just always active)
    and it will set the same StopLoss level as it did the previous day. Of course meanwhile the price can have dropped through that SL level (your sl variable) and don’t ask me what happens then. Possibly your position is not exited because probably (?) the price must drop through that SL level, while at the moment it did, your StopLoss was not active.
    Anyway, something like this :

    (not tested)

    #199068

    @JS

    Thanks! I can’t seem to get the same results with a limit stop though. Is it because the stop is reset each bar, so it works almost like a trailing?


    @PeterSt

    So adding ” and Close > SL” to what JS wrote? In your other two examples you write exactly the same as what I did?

    Appreciate the help!

    #199069
    JS

    @ProRealPierre

    I thought your question was about “Stop loss only during set trading hours”?

    A (pending) STOP order is placed again every next bar and will only change if your “SL” is changed every bar, otherwise it will be fixed.

     

    #199077

    So adding ” and Close > SL” to what JS wrote? In your other two examples you write exactly the same as what I did?

    No … I added “and TradeTime” to JS’s example – the thing what it is about for you.

    #199221

    Neither idea works. The stoploss is still fixed outside of the trading hours of the system. @nicolas, or @robertogozzi any ideas?

    #199223

    There you go (tested on DAX, 1h TF):

    beware that this will set the SL pending oders at the end of your trading time and this pending order will expire at the closing of the next candle, so you may occasionlly experience and exit outside your time range.

     

     

    1 user thanked author for this post.
    #200319

    Thank you, Roberto!

    I’ve added your suggestion to my system, but the issue seems to remain. I’m sure the reason is what you stated that I may occasionally experience an exit outside the time range, but it seems to happen frequently. Any other ideas as how to mitigate it entirely? What would the difference be technically if say I had something like

    Would this interfere with your code?

    #200331

    The odd and quite frustrating thing is that in back test with your code it works. With add set stop loss 0 it works in back test. Without adding either and only specifying the trade times for the system it works in back test, but the actual results are not the same. Would be swell if there was a function to paus the system outside of the trading hours, sort of like how you wouldn’t be able to sell stock when the market isn’t open..

    #200346

    What is the symbol plotted on chart? an X is a close by code action or a pending STOP/LIMIT order while a square is a SET STOP LOSS.

    #201462

    I’m having some trouble testing it as my system doesn’t run on a very low timeframe. Is there some way I can see it without the stop triggering? Doesn’t show up on backtest as it doesn’t look the same as live.

    #201511

    @Nicolas
    Was able to confirm now that it’s plotted with an X.

    Backtest stopped at 15:30.
    Active system stopped at 08:18

    #201867

    @robertogozzi Any ideas how to solve this?

    Appreciate any help.

    #202814

    The pending order way doesn’t work more then 50% of the time so far, so it’s not really usable. I don’t understand why I can’t use a set stop loss when ok and set stop loss 0 when not ok, or the like. Any other ideas? Would really appreciate the help as this is the only limitation on an otherwise great system. Not to mention it works in backtest, but not when running..

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

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