Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop Loss when using multiple Bar series in historical Data

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

    Stop Loss when using multiple Bar series in historical Data

    Dear All,

    I am facing an issue when trying to use historical data for testing a strategy.
    My strategy is making use of 2 different bar series, the 1minute for finding my entry conditions and the 1tick for the actual entries so that I can enter the trade like in a real time market. For this purpose I activated the TickReplay option.
    It seems to be taking my entries like it should but the issue I have is with my stop loss. What happens is that if my stop loss price has occured during my entry bar, it will get triggered even if this price occured before my entry. See the snapshot below. I get this systematically. This seems to be related to the fact that my primary bar series is the 1minute and hence I get stopped when I shouldn't.
    Click image for larger version  Name:	Screenshot 2025-02-17 220051.png Views:	1 Size:	34.5 KB ID:	1335064

    The way I typically put my entry/stop loss/take profit is like here below. The number 2 in my long entry is the ID of my 1tick bar series.

    HTML Code:
    string order_id = "Long Entry";
    EnterLong(2, 1, order_id);
    SetStopLoss(order_id, CalculationMode.Price, StopPrice, false);
    SetProfitTarget(order_id, CalculationMode.Price, ProfitPrice);​​
    I did see from the following link that orders should be placed and managed from the primary bar series but I wanted to see if there is a way to work around this for my usecase.
    NinjaTrader 8

    Many thanks for your help,
    Attached Files
    Last edited by sebinho; 02-17-2025, 03:35 PM.

    #2
    Hello sebinho,

    Unfortunately, Set methods cannot be submitted to a secondary series as the BarsInProgressIndex cannot be specified. Intra-bar granularity cannot be implemented with Set methods.

    This means you will need to use Exit methods such as ExitLongLimit() / ExitShortStopMarket() / etc or the unmanaged approach.

    See this support page on intra-bar granularity, including the information under the heading 'Note on Set methods'.


    See also the reference sample.
    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


    As well as this support example that properly implements intra-bar granularity with exit methods.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    60 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    39 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    21 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    23 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    51 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X