Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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:	61
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)
    JesseNinjaTrader Customer Service

    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
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Jonafare, 12-06-2012, 03:48 PM
        5 responses
        3,985 views
        0 likes
        Last Post rene69851  
        Started by Fitspressorest, Today, 01:38 PM
        0 responses
        2 views
        0 likes
        Last Post Fitspressorest  
        Started by Jonker, Today, 01:19 PM
        0 responses
        2 views
        0 likes
        Last Post Jonker
        by Jonker
         
        Started by futtrader, Today, 01:16 PM
        0 responses
        7 views
        0 likes
        Last Post futtrader  
        Started by Segwin, 05-07-2018, 02:15 PM
        14 responses
        1,792 views
        0 likes
        Last Post aligator  
        Working...
        X