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:	106
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 NullPointStrategies, Today, 05:17 AM
        0 responses
        41 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        124 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        64 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        41 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X