• 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

Deactivating a Custom Strategy for a specified period of time

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

    Deactivating a Custom Strategy for a specified period of time

    I am writing a Custom Strategy that will look for an entry signal on the current Candle[0] by testing conditions on Candle[0], Candle[1], Candle[2], or Candle[3]. Of course, sometimes those conditions all may be satisfied on a 5-minute chart at, say, 9:30, such that finding them again following the closes of the next one, two, or three candles would be redundant.

    So, my question is this:

    If the condition sets of Candle[0] found those condition sets on a 5-minute chart all to be true at, say, 9:30, how can I deactivate my strategy so it won't identify the same true conditions and take the same actions at 9:35, 9:40, and 9:45?

    #2
    Hello Longhornmark , thanks for your post.

    The Times[][] array is used in NinjaScript to reference the timestamp of a bar. There are examples such as this one that shows how to limit trading hours down to a particular time of day.

    You could set up a boolean flag at the class level that will signal your condition has been hit at a particular time.

    All the best regards.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Chris, I don't see how your example would help me. I'm not trying to limit my trading. Instead, I wish my Custom Strategy to suppress its alert that all conditions in a Condition Set have fulfilled, if those same conditions should fulfill again at the close of any of the next 3 candles. And by the way, I use NinjaTrader 7; you provided a NinjaTrader 8 example.

      Comment


        #4
        Originally posted by Longhornmark View Post
        I am writing a Custom Strategy that will look for an entry signal on the current Candle[0] by testing conditions on Candle[0], Candle[1], Candle[2], or Candle[3]. Of course, sometimes those conditions all may be satisfied on a 5-minute chart at, say, 9:30, such that finding them again following the closes of the next one, two, or three candles would be redundant.

        So, my question is this:

        If the condition sets of Candle[0] found those condition sets on a 5-minute chart all to be true at, say, 9:30, how can I deactivate my strategy so it won't identify the same true conditions and take the same actions at 9:35, 9:40, and 9:45?
        What is Candle[0]? -- I am unfamiliar with this nomenclature.

        AFAIK, NinjaScript has no such thing, DataSeries or otherwise, called "Candle".
        Can you be more specific what you are referring to here?

        [I presume you mean a "bar", but bars are a concept, they are represented in code using parallel
        DataSeries called Open, High, Low, Close, etc. For example, the data points of the candlestick
        2 bars ago is accessed via Open[2], High[2], Low[2], Close[2], etc. To say Candle[2] is very unclear,
        and (my apologies) but it does not provide much faith that you understand NinjaScript that well. ]

        You can try this idea:
        Set a boolean (like Chris suggested) if those conditions are true at 9:30 -- then you check
        that boolean on subsequent bars to see if it's still true ... sounds easy enough.

        Now, if you want this boolean to stay true no more than 3 bars, then invent another integer
        variable and save the value of CurrentBar at the time the boolean is set to true. Then test
        if the boolean needs to be reset back to false (aka ignored) by checking if CurrentBar has
        advanced 3 bars past the saved value ... make sense?

        Code:
        private bool MyCondition = false
        private int MyCurrentBar = 0;
        
        protected override void OnBarUpdate()
        {
            if (your condition set found)
            {
               MyCondition = true;
               MyCurrentBar = CurrentBar;
            }
           else if (MyCurrentBar > 0 && (CurrentBar - MyCurrentBar) > 3)
           {
              MyCondition = false;
              MyCurrentBar = 0;
           }
        
            ... now use MyCondition as desired, it will only be true for
            ... next 3 bars after you set it to true
        
        }
        Does that help?
        Last edited by bltdavid; 05-21-2019, 09:02 PM. Reason: Oops, should be '> 3' not '== 3' -- meaning true for 3 bars then reset back to false on 4th bar

        Comment


          #5
          Hi Longhornmark, Thanks for your reply.

          I notice that the Alert method documentation has a rearmSeconds parameter. If NinjaTrader sees the same alert ID it will skip the alert automatically. This could be used to limit the number of alerts that happen within a time window as an alternate solution to writing the "wait" code.

          https://ninjatrader.com/support/help...nt7/?alert.htm - Alert method

          All the best wishes!
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            Yes, Chris, I have seen that item But it pertains specifically to alerts.

            Instead of that, I am trying to suppress my code from painting an ArrowUp or an ArrowDown on my chart, but only when it has done so within the past three candles.
            Last edited by Longhornmark; 05-24-2019, 05:09 AM. Reason: Just now, I discovered bitdavid's post. Candle[0] was a generic term, bitdavid, not meant to be taken literally as attempted NinjaScript.

            Comment


              #7
              Hi Longhornmark, thanks for the follow-up.

              The MRO method would be useful to solve this problem. If that method returns a barsAgo value for the condition you supply, then do not draw the signal. It takes a delegate for its first parameter, that will be the condition to evaluate.

              Please let me know if you have any questions on that.
              Chris L.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by chazyang, Today, 02:01 AM
              1 response
              3 views
              0 likes
              Last Post chazyang  
              Started by tonynt, Today, 01:20 AM
              0 responses
              13 views
              0 likes
              Last Post tonynt
              by tonynt
               
              Started by sdauteuil, Yesterday, 11:02 PM
              1 response
              3 views
              0 likes
              Last Post sdauteuil  
              Started by Jschmelz, Yesterday, 04:45 PM
              1 response
              9 views
              0 likes
              Last Post NinjaTrader_Marco  
              Started by sisenberg, Yesterday, 08:06 PM
              1 response
              11 views
              0 likes
              Last Post sisenberg  
              Working...
              X