• 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

Delayed Entry

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

    Delayed Entry

    Okay, this should be simple but I wonder if there is a simple way to code a delayed entry after a cross over.

    If I have this:

    Code:
    SMA smaFirst = SMA([First);
    SMA smaSecond = SMA(Second);
                    
     if (CrossBelow(smaFirst, smaSecond, 1))
     {
        entryOrder = EnterShort(1, DefaultQuantity);
     }
    That's all fine and good but I want to possibly delay the entry by a few candles. I thought of delaying the SMA but can't think of a good way to do that except for writing a new indicator.

    Alternatively I would like to tell the CrossBelow method to ignore the current cross and wait a few candles before taking action.

    Any suggestions?

    Thanks,

    Molecool

    #2
    molecool, I'd save the barnumber on the initial cross as a variable and then enter after CurrentBar == savedBarnumber + x
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Well, thanks for that but it's a bit of a hack, isn't it? Especially if you want to trade both ways.

      Wouldn't it be a lot cleaner to somehow produce a delayed SMA and pass that one into the CrossBelow or CrossAbove instead?

      On the other hand, you may want to keep the current SMA for inverse exits (above cross to exit short short and below cross to exit long).

      Trivial on the surface but tricky once you think about it more.
      Last edited by molecool; 08-26-2010, 12:39 PM.

      Comment


        #4
        molecool, there are a number of ways you could do what you seek, including all the ones previously mentioned.

        If you wanted to create a delayed SMA, you could do something like this:
        Code:
        private DataSeries delayedSMA;
        Initialize()
        {
           delayedSMA = new DataSeries(this);
        }
        OnBarUpdate()
        {
           // to delay by 3 bars, use the third most recent SMA value
           delayedSMA.Set(SMA(14)[3]);
            
           if (CrossAbove(delayedSMA, someOtherSMA, 1))
               EnterLong()
        }
        AustinNinjaTrader Customer Service

        Comment


          #5
          Thank you - I like this much better. And I can still use the regular SMA as the exit then.

          Perfect - appreciate your help.

          Comment


            #6
            Hello, Bertrand
            I'm trying to wait 1 bar after my condition is met and check the current closing price to the closing price 1 bar ago when my condition was true, if it is higher then I Enter Long. Does this code look correct to you? Any help will be greatly appreciated.

            protected override void OnBarUpdate()
            {
            // Condition set 1
            if (CrossAbove(WilliamsR(TriggW), UVL, 1))
            tcBar = CurrentBar;

            if (CurrentBar == TcBar + 3) && Close[0] > close[1]
            {
            EnterLong(DefaultQuantity, "GoLong");
            }

            Comment


              #7
              Looks good, but would that compile for you even? NinjaScript / C# is case sensitive so tcBar is not TcBar.

              Why do you add 3 bars then to your saved signal bar?
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Thanks for the fast reply,

                "3" was a typo, i meant to say 1.
                Thanks for pointing out TcBar.
                I'll give it another try.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by sergey_z, Today, 02:34 AM
                3 responses
                13 views
                0 likes
                Last Post NinjaTrader_PaulH  
                Started by frankduc, Today, 05:24 AM
                2 responses
                10 views
                0 likes
                Last Post frankduc  
                Started by shmarola, Today, 01:01 AM
                0 responses
                4 views
                0 likes
                Last Post shmarola  
                Started by CriticalMind, 11-29-2015, 12:39 PM
                3 responses
                1,323 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by novel168, 06-14-2019, 09:20 PM
                3 responses
                12 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X