Prior to finding the reference to my own thread (Rogue trades) I already thought to respond. So regarding the subject in this thread here (Keltner channel etc.) I hope to contribute with this :
The activation of Autotrading goes in a way which is (for me) weird, to say the least. First thing what happens (or seem to happen) is that from the moment you activate Autotrading, all the bars in the cache will be traversed for a reason unknown. My idea about it is that first the "backtesting" part is executed, and when finally the current bars are reached, Autotrading may commence for real. If you'd observe the CPU usage, you will know when this "preprocess" is finished (it consumes a lot more CPU than when all is ready to go).
Let me add that my Autotrading does not wait even one second before a position is opened - it does that right away. This allows to judge "anomaly" quite well.
Now here is where this "knowledge" meets the issue described in this thread :
At some stage the broker opens the position. This is always the first trade visible, and this is not the Strategy's trade. This is always later and when exactly is not clear to me, but later. This could be "minutes". Now, because I work in AA (Asynchronous) mode, this allows for this situation in the first place (with AS mode Broker and Strategy entries would occur at the same moment). But now the thing :
When the Strategy finally enters its own trade (with the notice that all the time Broker matches Strategy already (in the Order and Position Tracker)), this occurs at the price of the moment; would this price be higher (for a Long) then the Strategy only
then starts to update its Currentosition.OpenProfit and thus the trade remains open longer than the Broker position would account for. This is how a first trade always is "off" with usually a much higher profit (this would be inherent for the Long position which starts like that for a reason (trend). Fact is :
This is incorrect.
What I now envision is that a SL etc. (formal TP too) would be submitted immediately while in your case (AS mode assumed) the real Entry is similar to what I encounter : thus later, when in my case the Strategy would enter.
The whole thing seems too complicated to even begin announcing it as bug (because how to mimic it, unless with real trading), but someone over at MC should be able to reason it out.
In addition, I feel that this is related to how the EnvironmentIsRealTimeCalc does its thing, which you don't need to be using in the first place. After days and days of observing this all, I now think that this property (or function) switches to True once the real Autotrading commenced (which is in my case when the Broker trade enters). This property / function lags because of the ticks (could be 10K ticks per second) *AND* the system is again disturbed by high CPU usage when the Autotrading commences (this higher CPU usage will settle down).
I did not work on the solution of this issue, because it is all with very indirect effects. But I already do know about some other way around : if I replace in my very case the EnvironmentIsRealTimeCalc with my self-made IsProd (read as IsLive) then no trade ever occurs. Also, referring to that other (Rogue) thread I am by now pretty much 100% sure that over there the same thing is happening, which is why I simply miss the start of it all and which is why I can't interfere with it. This is hard to explain, but the proper Output.Write tells it all easily. Thus, things occur during live trading, while the MC engine does not call the CalcBar() yet. The Rogue thing I solved, and for this SL etc. I would try to approach it the same.
My guts tell me that if you put the SL etc. under the condition of EnvironmentIsRealTimeCalc (True) that you will get there.
Ah, what helped me too is building in a System.Threading.Thread.Sleep(2000) before I start to do real things. This is to be build in CalcBar() (not in StartCalc) and of course only to be executed once (If "Initializing" and such). That at least allows me to show a "Start" entry in the Editor output and see things from the real beginning of the CalcBar calls.
Summarized (sort of)
Try to envision that you have conditions under If EnvironmentIsRealTimeCalc and that when you start Autotrading, all the bars in there are being processed with this property being false, until the current bar is reached. Then still all kind of arrangements have to be made, until finally this property gets true and you can
formally do your thing (like putting SL/TP pending orders). In AA mode all is still vague, but I think in SA mode this should to the job decently. Do please notice that when all the bars have been processed (I deem this a necessity - so I accept that), it still will take many minutes before the first real trade occurs. You might think your conditions are not met for several minutes, but I jump in right away and thus can see it is not right (or at least it requires understanding which I can't yet).
Please respond with your own judgment and further findings, so we can hopefully all learn from it. Your issue and me writing about it helps myself as well.