Good Day, I am writing a strategy that opens stop orders at specific times but I want them to expire or be canceled if certain conditions are met. The defparam flatafter function will not suffice as it is a 24h strategy.
So the question is how do I cancel stop orders once placed?
The manual says set the value to zero but it does not work. Which reminds me that Nicolas was supposed to get back with the answer from PRT regarding that!
You could just put in something like:
SET Stop %Loss 100
Then the instrument would have to go to zero to hit the stop.
Pending orders expire each bar and, if needed, must be placed again and again.
So DEFPARAM FLATAFTER/FLATBEFORE do not affect them and CUMULATEORDERS=FALSE doesn’t as well.
If some conditions arise to cancel them, well… just wait the closing of the current bar (you cannot do otherwise, since any strategy is executed only at that very moment)!
I think we need to clarify whether you are placing your stop orders on the market via a SET instruction or via a SELL at x STOP instruction.
I’m guessing the former as otherwise as Robertogozzi says they would just be cancelling themselves anyway.
I am aware of the fact that stop orders have to be placed (renewed) on each execution, however, I have found that even after my criteria is no longer met orders are still being triggered.
I would also love to know how to ‘update’ and ‘cancel’ set stop (stoploss) and set profit (target) levels.
Sell at x stop
Exitshort at x stop
These will last only one bar and then be cancelled. If they are still on the market then it is either that your code has placed them again or you have a problem that you should report to PRT.
SET stop pLoss x
SET stop $Loss x
SET stop %loss x
These are on the market until the position has been closed.
You can change the value at any time but if you are on a limited risk account then you can only move them closer (don’t get me started on the stupidity of this!)
There are one or two topics on here about the fact that:
SET stop pLOSS 0
is supposed to (according to the PRT documentation) cancel the SET stop but it does not. People normally see fantastic false results if they use a value of zero.
Nicolas spoke to PRT about this but he keeps forgetting to pass the info on to us. Hopefully after his weekend of rest he will be able to! 🙂
It is best to either only use Limit and Stop orders and not put them back on the market if you want to cancel one or if using the SET instruction then do what I said in my first post:
SET Stop %Loss 100
Thanks Vonasi! That was crystal!