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

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 Tim-c, Today, 02:10 PM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by Taddypole, Today, 02:47 PM
            0 responses
            0 views
            0 likes
            Last Post Taddypole  
            Started by chbruno, 04-24-2024, 04:10 PM
            4 responses
            50 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by TraderG23, 12-08-2023, 07:56 AM
            10 responses
            399 views
            1 like
            Last Post beobast
            by beobast
             
            Started by lorem, Yesterday, 09:18 AM
            5 responses
            23 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X