Donchian Stop Loss

Forums ProRealTime English forum ProOrder support Donchian Stop Loss

  • This topic has 28 replies, 3 voices, and was last updated 7 years ago by avatarMark.
Viewing 15 posts - 1 through 15 (of 29 total)
  • #12839

    Hi all,

    I’m sure this is really simple, and I have been trying lots of different ways to produce this…. I want to add in a stop loss that trails my order by following a donchian channel – and as soon as the price hits it, the order is closed.

    I’ve tried this approach

    DC=20
    a=5

    but it doesn’t actually close the order, just buys or sells.

    Also, this gets me out at the low of the bar after it’s breached the stop loss – I want a stop loss that closes the order immediately when the price touches the donchian channel value.

    Any help would be greatly appreciated!

    Thanks,

    #12859

    Have I put this in the wrong category? I’m new to the site so apologies if this is not the right place to ask the question.

    #12861

    No worry, I have moved your topic to the correct section of the forum.

    You are stuck like many other people with the correct highest high and lowest low value in real time! 🙂

    Because when the current low of the actual candlestick breach the lowest low over the last x periods, it becomes the new lowest low, so you can’t test the [0] value of your donchian channel to make your condition, you need to test the value of at least one bar in the past. You also made a mistake about closure of the sell positions, you need to use EXITSHORT to close them:

     

    #12864

    Thank you very much Nicolas, and apologies for putting the request in the wrong place!

    Does this mean that the price will automatically now trigger the stop immediately, and not at the end of the bar (in live mode)? For example, if a donchian channel low is at 99, and the price falls below this during the bar and closes the bar at 97 – will the order be executed at 99 or 97?

    Also (maybe a newbie question), do I need to use “exitlong” rather than sell?

    I’ll add my total system code once I get this bit working 🙂

    #12865

    SELL close buy orders.

    Yes trades will close at the exact price you put your pending stop orders at.

    #12867

    Fanstastic, thank you Nicolas – I look forward to testing this and learning!

    #12880

    It worked perfectly, thank you Nicolas!

    Is there away to turn the trailling off overnight – so that the stop loss stays at the value it was at 9pm until 7am (then it begins to trail the donchian again?)

    I’m trying to reproduce a manual system that I have traded for a long time, but only when I come to code it do I realise exactly what I do!

    Thanks

    #12882

    Write a time condition like this:

    and add this true condition in the trailing stop function.

     

    #12952

    Hi Nicolas,

    Hope you had a good weekend! I’ve been testing the system and it is getting a lot closer to my actual performance – which is great.

    However, the way I have programmed the stop loss meana that it turns off the stop loss at 9pm, rather than freezing the value at the 9pm value until 7am.

    What I would like to achieve is a stop loss that trails the donchian channel 7am-9pm, and at 9pm stays at that level until the next morning.

    Here is how I have coded it:

    Can this be done?

    Many thanks

    #12961

    Hi, thanks have a good weekend, done some coding jobs 🙂

    Glad to hear that you have successfully coded your manual trading to an automated one. Please tell us on what instrument and timeframe you are trading it, it would be of interest of other traders here.

    So if you want to fix your stoploss when you are not in the ‘donchtime’ period, you first need to save your last stop positions:

    Then you can set your stop orders when you are not ‘donchtime’ at this level:

     

    #13019

    Hi Nicolas, my code gets ever closer to being finished! Once it’s ready I look forward to uploading on to the site.

    I have 1 part of my system which is proving difficult, but currently it is missing and appears to be a big part of the profitability!

    My active trading day is 7am-9pm – overnight my stop loss is active but I would not close trades for any other reason. This system uses 3 moving averages, and crosses trigger both the entry and exits during the trading day. Basically, if the fast MA is above the slow MA I’m long, and if it crosses below I’m short. The middle EMA is used for exits with the same logic (if long, and the fast MA crosses below the middle MA I close).

    My issue is that, for example – if I was long overnight and the fast MA crosses back between the middle and slow MA’s at 6.30am for example, PRT will not close the trade at 7am as the cross happened outside of trading hours – this is causing some large losses as nothing closes the trade until the stop loss is hit.

    What I need is for the programme to do this (using long as example):

    If longonmarket at 7am open:

    Immediately close long trade if fast MA is below middle MA but above slow MA

    Immediately close long trade if fast MA is below slow MA and open short position

    Opposite for short trades – Is this possible?

    Many thanks

     

     

    #13021

    Also, if flat overnight and there is a crossover of the fast and slow MA then I’d like to open a position at 7am.

    For example, if I’m flat at 9pm (no position), but at 4am the fast MA crosses over the Slow MA – in this situation I’d like to go long at 7am.

    #13028

    About your first request, you need to test your moving average positions (above/below etc..) only at 7am:

    To initiate a new trade at 7am because a cross over/under occurred during the night, a solution would be to test the MA trend at last bar of your trading day and at first bar. If your test return a change (from bullish to bearish for example), then launch a trade accordingly.

    #13036

    Thank you Nicolas, I have attempted this but I have got it very wrong – the system takes a position every day at 7am!!!!

    Here is the full code so far, it will probably help for you to see it in total:

    #13037

     

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

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