Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

stop a strategy

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

    stop a strategy

    Hello, i have a strategy that depending on certain conditions i enable.

    Is there a way to have this strategy run once ie open a long or short position and then exit to be enabled again.
    Rather than have it run and have position closed for loss or profit and then quickly open a new position or submit a limit order (which is what the strategy does)

    The strategy needs to run on each tick as the strategy updates the stop as it progresses and needs the intrabar information.

    I wanted to determine if there was a strategy parameter that can be used for this OR i need to keep track of this in the strategy ie when flat and exit the strategy there at that point if a position has been opened once.

    Is there a programmatic call/function i can use to disable the strategy within itself or a best practice approach

    thanks

    #2
    Hello explorer101,

    Are you asking how to disable a strategy from within the strategy code?

    The CloseStrategy() method can do this.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello, yes thanks that is the function. But i wondered also if there was a strategy setting that could be used ie run once for one position. Or is that down to the code itself to test when flat?

      Comment


        #4
        Hello explorer101,

        OnPositionUpdate() triggers when the position changes.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks,

          I am already checking the marketposition in my code :

          But seems this would be the place to check on the change.

          In the help .....

          A MarketPosition object representing the updating position update provided directly from the broker.

          If i run this on SIM account or Replay will the update still be received for the marketposition ? ie it doesnt only work on live account?

          And then calling CloseStrategy() within the override of OnPositionUpdate() would be fine?

          thanks

          Comment


            #6
            Hello explorer101,

            Yes, the MarketPosition updates in OnPositionUpdate() for all connections and accounts including the Sim101 and Playback.

            Yes, you can call CloseStrategy() in OnPositionUpdate().

            I encourage you to give it a try.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            51 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            127 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            69 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            42 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