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

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 chbruno, Today, 04:10 PM
                0 responses
                3 views
                0 likes
                Last Post chbruno
                by chbruno
                 
                Started by josh18955, 03-25-2023, 11:16 AM
                6 responses
                436 views
                0 likes
                Last Post Delerium  
                Started by FAQtrader, Today, 03:35 PM
                0 responses
                6 views
                0 likes
                Last Post FAQtrader  
                Started by rocketman7, Today, 09:41 AM
                5 responses
                19 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by frslvr, 04-11-2024, 07:26 AM
                9 responses
                127 views
                1 like
                Last Post caryc123  
                Working...
                X