Pierre, although we can’t see anything now of the partial close (which you can’t have tested either over this weekend – just saying), I think I can see that this “construction” now can’t work. Why ?
TIMEFRAME(1hour)
sl = PositionPrice + AverageTrueRange[14](close)*pipsize
timeframe(default)
Your entry will have been on a higher frequency TF. Say 5 minutes. Then the code runs into what I quoted above, and you are telling the system to register the sl the first next whole hour. Thus if the trade was entered at e.g. 15:10, then at 16:00 the sl is registered and only then for the next bar it will become active.
But also :
Because the Pending Stop commands are re-executed each 5 minutes (thus 5 minute TF assumed), it will give a price of 0n. Thus
if longonmarket and close < slpricelong then
sell at sl stop
endif
that will read as : Sell at 0 stop.
That will never happen unless some larger Wars emerge.
It will only start to work at the next whole hour and within in the next bar of 5 minutes to come.
Also this
if shortonmarket and close > slpriceshort then
exitshort at sl stop
endif
which will be read as : exitshort at 0 stop
will do unexpected things, as it will exit as a Market order because with the 0 you will be under the price (but should be above for a Short) and it will go out regardless. Thus, in the next 5 minute bar after the Trade was taken (a position emerged).
… And so what you will observe is all over the place and maybe by some coincidence it works (like the trade taken at 15:55 because the next bar will fall on the 1H TF and things will work out the next 5m bar after that).
So you see, the again-not-so-nice-message is that PRT may contain some bugs or more, but you are the buggy one to begin with. :-).
Try to get the hang of this all for 100% first before you start to work with increasing / decreasing positions.
But … I saw no conflicting Stop commands any more, so good. Maybe try to work some more from top to bottom (the code is executed from top to bottom) so it doesn’t read upside down to others (me) and yourself. In what you showed now it looks harmless (at a glance) but when things get more complex it better be readable.
Have fun now !