Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Dynamic exit limit + stoploss if BarsSinceEntryExecution >= 1

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

    Dynamic exit limit + stoploss if BarsSinceEntryExecution >= 1

    Hi team,

    I have a strategy that exit the market with a limit order which value is updated on each bar.
    .
    I would like to add a protective stoploss that i want to be created only if BarsSinceEntryExecution >= 1. The stoploss is a hard price (the high or low of the last bar) depending if the position is short or long respectively.

    I read that i have to create the stoplosses in OnExecutionUpdate() which i did. Attaching the code. However when i enable the strategy i have the following error:
    Click image for larger version

Name:	image.png
Views:	110
Size:	7.7 KB
ID:	1273905

    Can anybody helps here?
    Attached Files

    #2
    Hello linkcou,

    That is just letting you know that you need to use the other overload for BarsSinceEntryExecution because you have added a secondary series to your script. Instead of BarsSinceEntryExecution() you need to use the overload

    BarsSinceEntryExecution(int barsInProgressIndex, string signalName, int entryExecutionsAgo)

    If you submitted the entry order to barsInProgress 0 you would just need to use 0 in this overload:

    BarsSinceEntryExecution(0, "long limit entry",0)

    Comment


      #3
      Thanks Jesse, it seems it works!

      Another quick question: is it necessary to cancel the open exit orders when one of them is filled?

      For example, if the limit exit order is filled then do i need to cancel the Stoploss or it's done automatically?

      Thanks

      Comment


        #4
        Hello linkcou,

        If you are using signal names then no, when the associated position is closed the order should be canceled. If you see that the order is not cancelled in testing you can alternatively use CancelOrder from OnExecutionUpdate when one of the targets fills to cancel the opposite order. https://ninjatrader.com/support/help...ub=CancelOrder

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        87 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        132 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        65 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        118 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        67 views
        0 likes
        Last Post PaulMohn  
        Working...
        X