Sell at stop and set stop loss not working as intended

Forums ProRealTime English forum ProOrder support Sell at stop and set stop loss not working as intended

Viewing 6 posts - 1 through 6 (of 6 total)
  • #149762

    Hi there,

    I am having a problem with a set of “sell at stop” and “set stop loss” commands that I am trying to use to manage my losing positions.

    I know what they both do and how to use them (let’s just go with that for a minute) – but I seem to be getting an inconsistent response from the the following set of commands:

    Now, the problem is, is that sometimes I am getting a “set stop loss 300” response, which would be correct if the C1 value is from 7 to 2 inclusive (C1<8 and C1>1); but what I am seeing when I go through my backtest trade records, is that I am taking a 300  point stop loss when the C1 values seem to be 8 (loss should be 240 – sell at positionprice-240 stop) or when C1 = 1 (loss should be 10 – sell at positionprice-10 stop).

    I found this problem because I was trying to turn the “set stop loss 300” into a “sell at positionprice-300 stop”, but I seemed to be losing money by doing this – and through investigation why into this I uncovered this problem.

    There is only 1 variable at play, C1, and it can only take a value from 1 to 8.

    The obvious consequence is that I am taking losses larger than intended – the thing that concerns me more is that I don’t know why this is happening and I’ve lost control of the process.

    I have attached some pics to show when it seems to be working as planned, and when I am having the problem as described above.

    Picture 1, or “P1” seems to show this problem – the closing C1 value of the bar before was 8. Now, this closing value of 8, should have meant that when the trade was opened, because C1=8, the stop for the trade should have been “sell at positionprice-240 stop”, or 240 points under the open. However, the stop was a 300 point loss, which would have meant that the “set stop loss 300” value was triggered – even though C1 had a value of 8.

    Picture 2, or “P2” shows where this problem wasn’t evident and the code worked as planned – the closing value of C2 the value the bar before was 7, and the “set stop loss 300” for a 300 point loss was correctly triggered.

    Picture 3, or “P3” seems to show the problem in action again – the last closing value for C1 the bar before was 1, so the stop should have been 10, “sell at positionprice-10 stop”, however the “set stop loss 300” came into play, and a 300 point loss was taken.

    I was thinking that “hang on, is the C1 value of the last close, or is it from the current bar?” Should be from the last close… but if it wasn’t, in Picture 1 P1, the C1 value on the close of the trade bar is 1, so that would mean the loss should have been 240 or 10, and not 300.

    Have also tried putting:

    on all 3 IF lines, and it didn’t change anything.

    I was also thinking that it might of been a time sync issue – the market, DJI A$1, has a time of UTC+00. I have all of my markets set to this UTC+00 time… was wondering if something was amiss there but that seems to line up.

    Any ideas what I’ve done wrong, or what has gone wrong?

    Thanks for your time and help,

    Finning.

    #149768

    You seem to be accumulating positions.

    SET STOP [p]LOSS and SET TARGET [p]PROFIT are orders sent initially to the broker (IG), anytime a new position is added, to keep track of WHEN that positions needs to be closed, either at TP or SL. If you accumulate 3 positions, since IG receives 3 different orders at different times, it lets them go their own individually, so one may stop erlier, another one later and so on. So it may happen to have partially closed positions, even if ProOrder doesn’t support this. It’s because IG takes over those orders and manages them by its own.

    If you use a PENDING STOP order, this is managed by PROORDER, which will close ALL open positions when that price is hit.

    SET STOP [p]LOSS and a STOP pending order may coexist, since the first one is managed by the broker at the real entry price, while the latter by ProOrder at the average price (POSITIONPRICE).

    In your case if C1 never changes, then the stop loss will be set always at the same level, but if C1 changes candle after candle, the your SL will change accordingly, if it’s 2-8 the first time, 300 will be sent to the broker and it will be kept till the end, if, at a later moment, C1 changes to 1, the initial 300-pip SL will be kept by the broker but ProOrder will place also a STOP pending order at POSITIONPRICE-12 to exit, whichever comes first, the same if C1 changes to 8.

    SET STOP [p]LOSS/SET TARGET [p]PROFIT are commands sent to the broker, who will manage them accordingly (with no expiration).

    SELL/EXITSHORT AT…. are pending orders managed by ProOrder that expire each bar (and need to be placed again and again, if needed).

     

     

    #149771

    Hi Roberto, thanks for the reply, I’ll have to read it a couple of times to fully digest it. Just wanted to say that I am using defparam cumulateorders=false , so 1 position at a time, only 1 buy in as a single event, and not adding to it. Thank you for your reply, I will have to study it. Finning.

    #150437

    Hi Roberto,

    finally back in front of the computer, sorry about the delayed response.

    I have re-read your comments, and I am pretty sure I understand what you are saying. “set stop loss X” is an order sent to the broker, and remains while the position is on/current, and “sell at positionprice X stop” is an order sent to the broker by prorealtime after the condition is triggered – and this is reevaluated bar by bar.

    Now that I have read that I thought that that was pretty much what was going on (though I thought the broker had both orders, not just the set stop loss) but I am still having a problem – as shown below.

    For simplicity, I have partially re-written the stops, and still get the same trading result, which is a good thing.

    Attached is a pic, P4, showing the problem that I am seeing again.

    Now, my understanding of what is going on is this:

    The trade conditions are met, and a long trade is placed as a “buy at x stop” order – not a buy at market order.

    There is a 300 point stop loss, that is sent to the broker. So, the broker has this 300 point failsafe at the time the order is initiated – that is fine – so, get out 300 points from the entry.

    Now, the last value of C1 was 1… so, I was expecting that

    would have come into play – that prorealtime would of sent this positionprice-10 stop order to market after being triggered, and I would be looking at a ~10 point loss, and not a 300 point stop loss?

    I understand that the 300 point stop loss is there – and that is a good thing for me – that part I don’t want to change.

    Why has the last C1 value of 1 not been recognised, and the positionprice-10 stop order been triggered?

    I graphed the positionprice function, and it came up as positionprice=0 – which it seems to be for all open and closes on the same bar.

    I guess that is the reason then – it’s not seeing the right value for positionprice, so it’s reverting back to the 300 point stop loss.

    Better than nothing, but it’s not doing what I want it to do.

    For a same bar open and close, how could I get the “sell at positionprice-10 stop” functionality to work then – is that the real question??

    I have tried to substitute positionprice with tradeprice, but I’m still getting the same problem.

    Thanks,

    Finning.

     

    #150442

    will be triggered if, at the moment you place it, your current price (close) is HIGHER than POSITIONPRICE-10 (accounting for minimum distance required by the broker, if any). So if your broker requires a 7-pip distance, CLOSE should be no lower than POSITIONPRICE-2, otherwise it will be rejected. If your broker requires no minimum distance, then CLOSE should be no lower than POSITIONPRICE-9.

    You can easily use IF…. to check this. If it’s not HIGHER than above said well… you enter it at market or lower the exit price until it reaches a correct price, so if CLOSE = POSITIONPRICE-8 you could sell at CLOSE-8 or lower.

    It’s a bit awkward to get used to this and will take some time, but you’ll manage to do it!

     

     

     

    #150446

    Hi Roberto,

    shouldn’t that be if it’s 10 points lower than the positionprice?

    So, if I enter long at 600, if the price is less than 590, then it sell out with an order sent from prorealtime?

    The

    works intrabar/tick by tick, and not on the close of bar, right?

    Prorealtime should send my order to exit at 10 points under the positionprice, and not the close of the bar?

    If my minimum market stop distance is 10, I shouldn’t have a problem then either, right? Lets just say I make it positionprice-11 for arguments sake.

    I have changed to 10 to an 11 in my code, and I am still having the same problem.

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

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