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 Jon17, Today, 04:33 PM
            0 responses
            1 view
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            4 views
            0 likes
            Last Post Javierw.ok  
            Started by timmbbo, Today, 08:59 AM
            2 responses
            10 views
            0 likes
            Last Post bltdavid  
            Started by alifarahani, Today, 09:40 AM
            6 responses
            41 views
            0 likes
            Last Post alifarahani  
            Started by Waxavi, Today, 02:10 AM
            1 response
            19 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Working...
            X