• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Disable strategy

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

    Disable strategy

    Hello,

    I'd like to disable an strategy at a certain time (p.e 14:00), but I guess if there is an open position this position is going to be close.

    How I have to say if there is an open position do not disable. could be this:

    if (ToTime(Time[0]) = ToTime(14, 0, 0) && Position.MarketPosition == MarketPosition.Flat)

    Disable()

    #2
    Hello josefo,

    Thank you for your inquiry.

    Yes, doing this will cause your strategy to disable only if it is both 2:00 PM and the strategy is in a flat position.

    However, ensure you are using two equal signs (==) for your ToTime condition.

    Please note that this will not disable your strategy at a later time even when the strategy is in a flat position. If you wish to have your strategy disable at 2:00 PM or later when flat, you'd want to do the following:
    Code:
    if (ToTime(Time[0]) >= 140000 && Position.MarketPosition == MarketPosition.Flat)
         Disable();
    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Thanks Zachary for your kind support.

      Comment


        #4
        Originally posted by josefo View Post
        Hello,

        I'd like to disable an strategy at a certain time (p.e 14:00), but I guess if there is an open position this position is going to be close.

        How I have to say if there is an open position do not disable. could be this:

        if (ToTime(Time[0]) = ToTime(14, 0, 0) && Position.MarketPosition == MarketPosition.Flat)

        Disable()
        Why disable at all, if you want to keep positions? Why not just use a time-filter to determine when the strategy will be allowed to initiate trades, and do nothing otherwise?

        Comment


          #5
          I have in my strategies always a timeframe; but I think should be a good idea that when this timeframe is over to disable the strategy.

          Comment


            #6
            I have tried to disable the strategy after a period time:

            if time > 150000 and time < 230000 and market position flat, then disable.

            But if I set this, I cannot enable strategy at any time.

            Do you know why?

            Comment


              #7
              Hello josefo,

              Please remember that strategies are ran on historical bars as well and the code specifying to disable the strategy during the times you have specified in your condition will trigger if a historical bar meets the conditions.

              If you would like to avoid this, you can utilize the Historical boolean to prevent the Disable() logic from running.

              Upon the strategy running on real-time data, the Historical boolean is no longer true.

              More information about Historical can be found here: http://ninjatrader.com/support/helpG...historical.htm

              Please, let us know if we may be of further assistance.
              Zachary G.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by josefo View Post
                I have tried to disable the strategy after a period time:

                if time > 150000 and time < 230000 and market position flat, then disable.

                But if I set this, I cannot enable strategy at any time.

                Do you know why?
                There is no way to enable the Strategy from code. That is why I made the suggestion to not Disable() in the first place.

                ref: http://ninjatrader.com/support/forum...ad.php?t=57196

                Comment


                  #9
                  Hello again,

                  I think I have not not explained myself properly.

                  I have more than 30 strategies running; everyone with their timeframe. I want to disable every strategy if their timeframe is over. P.E if the strategy runs from 080000 until 150000, I like that if the time is greater then 150000 and the position is flat (no open positions), disable the strategy.

                  But when I code it:

                  if (ToTime(Time[0]) > ToTime(15, 0, 0)
                  && ToTime(Time[0]) < ToTime(23, 0, 0)
                  && Position.MarketPosition == MarketPosition.Flat)

                  Disable();

                  when I try to enable the strategy manually through the Strategy tab (at 070000 or later in the morning), it is impossible. The strategy remains disable.

                  Why?

                  Thanks in advance.

                  Comment


                    #10
                    Hello josefo,

                    I have answered this in my previous post.

                    Originally posted by NinjaTrader_ZacharyG View Post
                    Hello josefo,

                    Please remember that strategies are ran on historical bars as well and the code specifying to disable the strategy during the times you have specified in your condition will trigger if a historical bar meets the conditions.

                    If you would like to avoid this, you can utilize the Historical boolean to prevent the Disable() logic from running.

                    Upon the strategy running on real-time data, the Historical boolean is no longer true.

                    More information about Historical can be found here: http://ninjatrader.com/support/helpG...historical.htm

                    Please, let us know if we may be of further assistance.
                    Zachary G.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello Zachary,

                      I'm very sorry but my problem is that I still dont understand your answer.

                      But don't worry, it's my fault.

                      Thank you for your support.

                      Comment


                        #12
                        Hello josefo,

                        When placing a strategy on a chart, the strategy will run on both historical and real-time data.

                        Unless you specify that you want specific logic only to run on real-time data, or that you want the entire strategy to run only on real-time data, all of your logic will be ran on every historical bar.

                        Because a historical bar can trigger your condition to call Disable(), your strategy is disabled immediately after you start it up.

                        To avoid this, you would either need to allow your strategy to run only on real-time data, by doing the following below:
                        Code:
                        protected override void OnBarUpdate()
                        {
                             if (Historical)
                                  return;
                        }
                        Or, only allow your condition to disable your strategy to work only on real-time data:
                        Code:
                        if (!Historical && ToTime.....)
                             Disable();
                        Zachary G.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello Zachary,

                          Now it's absolutely clear. Thanks for clarifying !!!

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by ntbone, Today, 09:54 PM
                          0 responses
                          1 view
                          0 likes
                          Last Post ntbone
                          by ntbone
                           
                          Started by rwilliam, Today, 03:14 PM
                          0 responses
                          5 views
                          0 likes
                          Last Post rwilliam  
                          Started by rwilliam, Today, 03:10 PM
                          1 response
                          4 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by rontronimous, Today, 03:04 PM
                          2 responses
                          8 views
                          0 likes
                          Last Post rontronimous  
                          Started by zacharydw00, Today, 03:14 PM
                          0 responses
                          5 views
                          0 likes
                          Last Post zacharydw00  
                          Working...
                          X