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

Adding a button to Enable and Disable specific strategy

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

    Adding a button to Enable and Disable specific strategy

    Hi, I would like to create buttons on my chart to enable and disable my strategy.
    I have found a LongShort button strategy on User-app-share which gives me the code I need. I found CloseStrategy("My Strategy"); in User Guide but what I don't find is the code to enable the strategy so I can use it to enable my strategy. Can someone let me know what command I would use for that?

    #2
    Hello set2win,

    Thank you for the post.

    There is currently not a supported means to enable strategies through code. What would be suggested here would be to just turn your logic on or off with the button but leave the strategy overall enabled.

    I look forward to being of further assistance.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Well that is a problem with the no Enable. But I like you idea, so I could have a variable called Enable and toggle it on and off with the buttons and part of the condition for going long or short would incorporate that variable. Does that sound like a way to do it?

      Comment


        #4
        Hello set2win,

        Yes that would be correct. You could just toggle the trading logic by using a variable.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Its been awhile since I wrote this. But my question now relates to the long and short button script. It is set to work Calculate.OnEachTick, if I have OnBarClose it does not work, I have another strategy that needs the OnBarClose vs on tick . What I tried is add data series tick, put the longEnable = true enclosed in If (BarsInProgress ==1) the onclick method added to the button clciked section if barsinprogress and in the onbarupdate added if barsinprogress to if butttonclicked. Is there something else needed to get this to work. Or is it just not possible unless its OnEachClick

          Comment


            #6
            So actually the problem was If BarsInProgress != 0 return, removing that and all you need is the AddDataSeries tick. and none of the other if Barsinprogress ==1. But in the strategy that I was working on I cant get my button to work . I want the button to be a momentary button when presses does one thing and returns to its original state to GoLong , it enables and or statement in my onbar update to trade either enableLong == true or all my other conditions it never executes. I guess Ill work on it some more.

            Comment


              #7
              I like the idea of using a bool to disable a strategy thru conditions, I need help as how to change that bool from true to false when Profit Target order is executed and or when Profit Target level is reach while being in position. have to be careful not to disable prior to exit

              Any Suggestions apprecaited

              Comment


                #8
                Hello DTSSTS,

                You can use OnExecutionUpdate to see when an order is filled/filling.

                OnExecutionUpdate - https://ninjatrader.com/support/help...tionupdate.htm

                You could check execution.Name to see if it matches "Profit target" or the signal name for your own profit target order. You could also check in OnExecututionUpdate if Position.MarketPosition == MarketPosition.Flat.

                For example, checking the following in OnExecutionUpdate would let you know then the profit target fills and the strategy is flat.

                Code:
                if (exectuon.Name == "Profit target" && Position.MarketPosition ==  MarketPosition.Flat)
                {
                
                }
                JimNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by bortz, 11-06-2023, 08:04 AM
                47 responses
                1,602 views
                0 likes
                Last Post aligator  
                Started by jaybedreamin, Today, 05:56 PM
                0 responses
                8 views
                0 likes
                Last Post jaybedreamin  
                Started by DJ888, 04-16-2024, 06:09 PM
                6 responses
                18 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by Jon17, Today, 04:33 PM
                0 responses
                4 views
                0 likes
                Last Post Jon17
                by Jon17
                 
                Started by Javierw.ok, Today, 04:12 PM
                0 responses
                12 views
                0 likes
                Last Post Javierw.ok  
                Working...
                X