Trailing stops remaining static when there are multiple positions

Forums ProRealTime English forum ProOrder support Trailing stops remaining static when there are multiple positions

Viewing 15 posts - 31 through 45 (of 48 total)
  • #98019

    The question on maximum trailing stop reminds me that we really should add a minimum stop distance to that trailing stop code that I wrote just in case there is a big price move (big high or low) that then brings the stop level too close to the close price. This would prevent us sending orders to the market that get rejected and possibly leave us with no stop loss at all.

    #98031

    I had a quick look at it and this should now prevent our stop loss getting too close. Not tested so if anyone can confirm it works as it should then please let me know.

     

    1 user thanked author for this post.
    #98034

    I’ve changed the link on here

    Snippet Link Library to the latest version immediately above.

    1 user thanked author for this post.
    #98041

    I had a quick look at it and this should now prevent our stop loss getting too close. Not tested so if anyone can confirm it works as it should then please let me know.

     

    #98082

    I spotted a error in my adjustment of the stop loss price relative to position price at the close of the first bar. I have edited the code for v3 in my previous post. If you are using it already then you might want to change to this new version or change lines 11 and 16 which are the ones I have edited.

    1 user thanked author for this post.
    #98084

    For fun (yes I know I’m sad) I decided to create a version that has a trailing take profit as well as a trailing stop loss. So as price moves against you your take profit expectations decrease. Not tested!

     

    3 users thanked author for this post.
    #98102

    Great idea Vonasi – Big Thanks!

    Added to here

    Snippet Link Library

    #98116

    Thanks Vonasi

    A question though;

    If a code takes reserve positions based on signal. How does your code handle that situation? (long goes straight short).

    In the closed positions list I got a number of trades with zero bars if I have no “not onmarket”.

    If I do as your example, with not onmarket, all is good. But doesn’t such code need to cover both  scenarios?

     

     

     

     

    #98117

    Yes as the code is it does not allow for reversing of a position. If a trade is opened it is allowed to play out until either the stop loss or the take profit is hit. I generally prefer to have separate long and short strategies. I think that by changing lines 24 and 31 to the following then it should allow for reversal of position – not tested and still on first cup of tea!

    Having a NOT ONMARKET at minimum is required otherwise if you are on market and the conditions are met again then the stop loss and take profit are adjusted to the starting trailing stop again. For this reason it is not possible to use the code as it is with cumulating positions. Maybe later if I have time I’ll try to re-work it for all possibilities.

    2 users thanked author for this post.
    #98152

    I’ve added a note of clarification (re not for cum positions) to here

    Snippet Link Library

    #98303

    For fun (yes I know I’m sad) I decided to create a version that has a trailing take profit as well as a trailing stop loss. So as price moves against you your take profit expectations decrease. Not tested!

    Thanks very much for this, Vonasi. The profit take avails better backtest results for my system on the DOW (I assume because of the volatility) but not for the DAX. I’ll watch the trades live this week and will confirm that it works as it should in real time.

    1 user thanked author for this post.
    #99862

    I’ve just attempted to activate a series of bots using some of the code in this thread and I’ve been given an error message (see attached screengrab).

    This code has worked perfectly fine in bots in the ProRealTime version that is linked to my IG demo account, but they won’t work when I use the version of ProRealTime that is linked to my “real money” platform in IG.

    Does anyone know what might be going on here?

    As a reminder, here is the code (it’s the version without the profit take)

     

    #99864

    That’s interesting. I guess that it is due to the value of SLPRICE being zero until a trade has opened. Weird that it errors only when live. Try changing the last two lines to this:

     

    #99865

    Thanks very much for the suggestion. It looks like this works (or at least, it hasn’t rejected the bot in the 5 minutes since I made it live).

    It really is very strange that this happened! Firstly, as discussed, it worked fine in demo mode. But secondly, none of the bots in question are supposed to be trading this morning, so it makes no sense that they were attempting to execute any orders.

    Crazy!

    #99881

    none of the bots in question are supposed to be trading this morning, so it makes no sense that they were attempting to execute any orders.

    Even though your code has restrictions that stop it trading at certain times it does not stop the code from being read through at every bar close. So it reads it through and acts on any necessary instructions and the only two would be to set stop losses and take profits at zero. By adding the condition IF ONMARKET we have stopped it acting on these instruction.

    The demo engine it seems has several differences compared to the live engine. It would be better if it didn’t and was in fact exactly the same as we all test on demo to build confidence that we can go live without any issues – but instead our confidence is knocked as the strategy stops when we put it live with an error that we never saw in demo.

Viewing 15 posts - 31 through 45 (of 48 total)

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