Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using ExitLongLimit/Stop with onPriceChange

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

    Using ExitLongLimit/Stop with onPriceChange

    I created a strategy with strategy builder. I used ExitLongStop/Limit for my stop/TP because I wanted to be able to pass a variable into the stop loss.

    When I first ran the strategy, I found sometimes my exit orders were being cancelled before the stop or TP was hit, leaving my original long order running loose. The log said the orders had expired.

    I then edited my strategy to have the exitLong constantly repeat, only then did the trade play out as intended. However, I'm using on price change. So this means every price change my strategy is trying to resubmit the same exitLong orders over and over and over again. Obviously the orders get ignored as they already exist but Is this how it should be?

    #2
    Hello lucyb,

    Thank you for your post.

    Orders submitted by a managed approach strategy are automatically cancelled when the submission bar closes if the order is not filled when isLiveUntilCancelled is false or the overload with the isLiveUntilCancelled parameter is not used.

    When using the Strategy Builder, orders are submitted without using the isLiveUntilCancelled bool and will be false, meaning orders will be automatically cancelled.

    See isLiveUntilCancelled in the help guide.



    To keep limit and stop orders alive, continue re-submitting the order on each new bar for as long as you would like the order to remain alive. Save the limit or stop price to a double variable when the entry condition is true, and this can be used as the limit or stop price of the order on each resubmission.

    Below is a link to an example created with the Strategy Builder that demonstrates saving the order price to a variable and using bools to know when to keep an exit order alive by resubmitting the order.



    The alternative is to unlock the script and code by hand. With this the method overload signature with the isLiveUntilCancelled parameter can be set to true and the order will not automatically be cancelled.

    EnterLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName)

    Below is a link to unlocked examples that demonstrate.



    Please let me know if this does not resolve your inquiry.

    Comment


      #3
      Thank you. I guess I did it correctly.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      21 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      30 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      50 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Working...
      X