I am struggling to code in order to avoid re-entering of trade once set profit target is met. For instance if I am long and set profit target is met, the code shouldn’t enter a new long trade although the conditions to go long is still true. Any help?
It is taking another long position because the conditions you specified are still being met, if you don’t want it to take another position then you must change the long entry condition or refine it in some way. What you haven’t stated is what you want the system to do after closing a long position, presumably you want it to be able to take another long position at some point? You can tell e.g. to take another long position if the long entry conditions are met after so many bars since the close of the last trade or after a certain amount of time has passed but you need to say what you want it to do.
Assuming you have different conditions for entering longs and shorts then setting and testing a flag will do what you need, see example in attached code sample I used to test it.
To help us continually offer you the best experience on ProRealCode, we use cookies. By clicking on "Continue" you are agreeing to our use of them. You can also check our "privacy policy" page for more information.Continue