Ash, you could say that this “outside of conditions” thing is for simplification (as in : first get things to work prior to make it more complicated).
Those commands are perfectly allowed to be within conditions, but the explanation of the conditions under which you now must operate, are beyond “knowledge”.
There’s really quite a bit involved like a necessity to reset a SL command with setting the SL to 0 (this is in the documentation, but nothing expects that If / Else conditions really apply it while you are on the edge of that desire). Or how things were explained to you in a fashion “from top to bottom in the program code”, which generally is true, but only comprehensible if you don’t apply conditions. Otherwise all is possible.
So the general advice is to make all mutual exclusive and explicit as you can. An example of not doing that :
If OnMarket then
Set Stop pLoss to MyAcceptedLoss
endif
Why is this ambiguous ? well, because when the Set Stop command has been executed once, it will remain forever. Or maybe not when the position exits. I don’t even know.
This would make it unambiguous, though maybe without much sense :
If OnMarket then
Set Stop pLoss to MyAcceptedLoss
else
Set Stop pLoss 0
endif
Now you will always know what happens.
The moral is : when you want to change these stops and targets underway, then this is perfectly allowed and your approach regarding this is fine. But you must must know what you are doing very well. Make all as mutual exclusive as possible. No ambiguity is allowed in your code, or else you may not be able to follow yourself, while the PRT interpreter just does what you told it to do.
Now justisan’s example :
if … then
buy 1 lot…
endif
set stop ploss x
set target porofit y
Prefectly clear ! But two small issues, when you’d ask me :
1. the Set Stop makes no sense when no position is in order; it is even dangerous because the amount of position may change while the Set Stop suggests a fixed distance (I know, with variable x this can be made variable);
2. It just does not allow for conditions, while you clearly want these.
Ad 1.: I thus rather have the command right in the same If condition as where the Buy occurs. But only if the Set Stop will be dependent on that Buy. If not, we’d face another issue : redundancy. End if one thing is killing it is that.
Many roads lead to Rome, but you first need to know the roads very well in order to choose one.