Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MTF: Is StopLoss Logic Only applied to the Primary bar series?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    MTF: Is StopLoss Logic Only applied to the Primary bar series?

    I have been confused by a MTF Strategy that on backtesting shows an exit at Stop Loss, Earlier than the entry.

    CalculateOnClose = true throughout this discussion.

    The StopLoss was set or "submitted to" the secondary bar series, so I would expect that unless the secondary bar series trades through the stop loss, it would not be triggered in a back test.... as would be the case in real life.

    //Submit SL to secondary Bar Series

    Code:
    if(BarsInProgress == 10)
                {
                     ...
                     EnterLong(100000);
                     SetStopLoss(CalculationMode.Ticks,upStopLoss);
                 }
    But that isn't what appears to be happening.

    This is a shot of the back test results showing an entry time of 8:56:28 AM which is the timestamp of the entry bar on the secondary bar series. (timestamps are close of bar, the open of the entry bar is at 8:37:04)



    It shows an exit at SL at 8:40:48 AM which is a timestamp at close of a primary bar series bar.

    This is apparently made possible because the entry bar on the secondary time series Opens before the primary bar series bar closes. Secondary entry bar Opens at 8:37:04, where the primary series bar closes at 8:40:48, with the primary series bar having traded during its formation below the SL level.

    Here's a shot of the secondary bar series with the entry:



    Here's a shot of the Primary Bar Series.



    Please confirm that I am interpreting these results accurately.

    If I am I have two ideas to solve this problem, and would appreciate feedback on these two ideas.

    1. Since it appears that SetStopLoss always applies to the primary bar series, I could do away with it, and get the behavior of a SL by submitting an order in the opposite direction, submitted to the secondary bar series under BarsInProgress == 1, using Positions[1].MarketPosition to know where I am.

    2. Easier and I think with some side benefits, I could use a very small chart period for the primary bar series... adding granularity. I could use a 100 tick chart as the primary bar series and have all my logic applied to secondary... much larger chart periods, so that I would never run into the above problem.

    I know this is long post, but I wanted to be clear on a confusing situation. Hopefully it will help others in the future. Please tell me if my diagnosis is correct what you think of my solutions... I particularly like adding granularity.

    #2
    Crassius, thanks for the detailed post - you're correct for the Set()'s, they will work against the primary series - if you wish to submit to an added BIP, please work with the Exit() methods that would offer a parameter for BIP in the advanced overload as well.



    You can also work with a finer chart as primary series in your strategy setup.

    Comment


      #3
      Thank you Crassuis for this great post!

      I actually ran into the same problem with my backtests, and you clarified what is happening.

      I don't want to use the smaller timeframe as primary BIP, and I'm trying to use a SetTrailStop(), which is more convenient than the Exit() for my purpose. I thought I could work around this problem by seeting the trail to 999999 at every OnBarUpdate() when the strategy is flat. then when BIP == 0 and the strategy is not flat I can set it to the desired value. I'm running into a situation where this seems to work my short, but not for my long trades???

      I have attached a MWE, maybee someone can tell what I'm missing.

      The screenshot below shows what happens on a chart (EURUSD 60 min):
      Attached Files

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      647 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      368 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      108 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      571 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      573 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X