Code trailing stop like “set stop ptrailing x”

Forums ProRealTime English forum ProOrder support Code trailing stop like “set stop ptrailing x”

Viewing 13 posts - 1 through 13 (of 13 total)
  • #215760

    Is it actually possible to somehow combine the “set stop ptrailing x” function and a coded trailing stop (e.g. Nicolas coded trailing stop)? The advantage of the “set stop ptrailing x” variant is that it follows the price at a distance when it makes big jumps in the right direction. The coded version doesn’t do that. The advantage of the coded variant is that when the price stagnates above a certain level, it still secures profits and closes the sack.
    Is it possible to code a coded trailing stop that secures large price jumps faster and still secures profits when the price stagnates? Only then just slower and time-based?

    Or is there something like this already and I haven’t found it yet?

    #215762

    I found this “trailing stop IG style” in my snippets chest:

    #215767

    Oh, interesting code. Thanks, I will test the function tonight.

    #215870

    I have to say it works great. 👍🏼 Can this code be supplemented with another trailing code? For example, that at a certain point when the price stagnates, steps will continue to be secured? For example, if 40 points are in profit but the price is going in the opposite direction, the code closes the sack by still securing more steps.

    #215879

    Maybe hard to put into words… Let’s take an example:

    buy at 1000

    the price goes up to 1050

    the IG trail with setting 25 saves 25 pips

    a normal trail that gradually saves 1 pip from 25 has at 1050 depending on the time, a few points secured

     

    Now the price drops back down to 1000 and we have a few points on the normal trail and 25 on the IG trail as a win.

    But if, and that’s my point, the price fluctuates around 1050, the IG trail always remains at 25 secured points, but the normal trail gradually secures up to 50 points at best. Now the question… is there any way to combine the benefits of both codes?

    #221394
    Wim

    I might be wrong @Nicolas, but this IG style trailing stop could surprise you. Suppose a strategy that enters into position long after a serious gap down. The last candle with status NOT ONMARKET will assign a value to ibuystoploss of e.g. 110. The entry at the open of the next candle (with gap down) is at 90, and the close of this candle is 100. With values of StopLoss=10 and TrailingStopStart=0, the assignment of ibuystoploss at the close of the entry candle will be 110 (the last assigned value in NOT ONMARKET status). A pending order SELL AT 110 STOP will be launched, while the actual price is around 100, lower!
    Second, small remark: the distance at which the trailing stop is following the price is not StopLoss but StopLoss+TrailingStopStart. Why is that?

    #221398

    You have to use:

    buystoploss = closeStopLoss*pointsize
    sellstoploss = close+StopLoss*pointsize
    when you enter at market, in order to anchor the first stoploss to the Close of the candlestick. Then the trailingstop code will do the rest. If you don’t want to enter on a gap, include a condition in your entry decision tree.
    #221408
    Wim

    Sorry @Nicolas, I wasn’t clear. I pointed out a situation, very particular I admit, that is not handled correctly by this code. If you enter long at the open of a bullish candle that immediately triggers the start of the trailing stop, you might end up with a pending sell order ABOVE the actual price. This will be the case if the candle immediately preceding the entry candle closed more than the starting distance above the entry candle.

    I will post alternative code that doesn’t have this problem. In my code the equivalent of TrailingStartStop is not added to the following distance.

    #221409
    Wim

    OK, here is my alternative for a trailing stop following at a fixed distance. Like the original IG version only 2 inputs: tsDistance = fixed distance at which the trailing will be done, and tsStart = number of points in profit that will activate the trailing.

     

    1 user thanked author for this post.
    #221410
    Wim

    Fun fact: you can enter a negative number as tsStart! Suppose you normally have your initial StopLoss at 20 points, you could enter tsStart = -20. The effect being that the trailing will start immediately at your initial StopLoss-level.
    Screen captures with tsStart = 0 and one with tsStart = -20

    #221527

    How does it work when

    defparam cumulateorders=true

    ???

    #221536

    If you cumulate orders, you should use POSITIONPRICE instead of TRADEPRICE to place your STOP orders.

    POSITIONPRICE returns the average open price of orders.

    #221554

    Hello,
    Example:
    first buy 100, SL 70 points lower (SL set at 30).
    The price drops to 50 and you buy one Lot, gives a position price of 75.
    Now also the SL also drops 25 points down?
    How does it look if further positions are bought?

    Greets
    Suffi

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

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