Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Opening Gaps?

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

    Opening Gaps?

    I am pretty sure I am missing something completely stupid...
    I am trying to create a strategy of going long opening gaps. I have tried using the condition
    Close(1)>Open(0),
    but then using Open in the entry field results in a buy at the open of the previous day...not on the day that the stock gapped....

    #2
    Your method could only work at the first minutes of the section.
    Two possible methods to find the gap at any moment:
    1. " Open[Bars.BarsSinceSession]-Close[Bars.BarsSinceSession+1]", I found one bar deviation could occur for different days.
    2. "CurrentDayOHL().CurrentOpen[0]-PriorDayOHLC().PriorClose[0]", I not yet confirm if it works properly.

    I currently use the first method.

    Comment


      #3
      You would need to add finer (intraday) granularity to your script as otherwise evaluating this condition on daily bars you would already be on the next bar when you're able to execute the trade as the condition is triggered after the bar would have closed in backtesting.

      Comment


        #4
        SO Ive been studying the forums and the reverences but am still confused.

        I am having some difficulty with the barsarray.

        So I first added the 2 time frames.
        as per...
        protectedoverridevoid Initialize()
        {
        // Add a 1 minute Bars object to the strategy
        Add(PeriodType.Minute, 1);

        // Add a 1 day Bars object to the strategy
        Add(PeriodType.Day, 1);
        CalculateOnBarClose = false;

        Then to try and indicate the open of the first 1 minute bar is below the close of the previous day bar, I am trying
        {
        if (BarsInProgress != 1)
        return;
        //trying to determine if the open is below the close
        if (Open[BarsArray[1] < Close[BarsArray[2])
        {
        EnterLongStopLimit(
        1000, Open[0] + 0.16, Open[0] + 0.1, "Long");
        }
        }

        zThe error I get is Syntax error, ']' expected... I think I hav all statements closed, but I am missing something for sure. Im a newbie at this, so don't laught too hard!

        Comment


          #5
          Hello stalt,

          if you want to determine if the open is above the close of a particular timeframe,
          you would do it using Open and Close example:
          if( Open[0] > Close[0] )
          above would for example compare the Open and close of the last bar of one timeframe. They are arrays, so you use [] to access a particular index. In this case, we use 0 for the current bar.

          In your case, if you want to compare a 1 minute bar open being below the close of the previous
          day bar:

          if ( Open[0] < Closes[2][0] )

          This compares the Open of the current minute bar to the Close of the current Day bar.

          Closes will have as many elements as how many time periods you have added. There is also Highs,Lows and so forth!

          For more information on Closes and multiple time frames, please see the following helpguide articles:



          Hope this helps clear things up for you. Just let us know if you have any other questions.
          Last edited by NinjaTrader_Dexter; 04-20-2011, 10:23 AM.
          DexterNinjaTrader Customer Service

          Comment


            #6
            read the psots, spend a couple of hours. I am not getting any results.

            Hre is the code I am using

            protectedoverridevoid Initialize()
            {
            Add(PriorDayOHLC());
            Add(EMA(
            5));
            Add(PeriodType.Minute,
            1);
            Add(PeriodType.Day,
            1);
            CalculateOnBarClose =
            false;
            }
            ///<summary>
            /// Called on each bar update event (incoming tick)
            ///</summary>
            protectedoverridevoid OnBarUpdate()
            {
            // Condition set 1
            if (Open[1] < Closes[2][0])

            {
            EnterLong(
            1000, "Long");
            }
             

            }
            I am running this on stocks I know have gapped down and I am getting no entries....Tried running it from April4 - 20 on APKT, MCP, APKT had a clear gapdown on 4/12...no entry indicated...

            Comment


              #7
              Hello stalt,

              Thank you for your post,

              Open[1] < Closes[2][0] would compare the open of a minute bar 1 bar ago to the close of the current day. Try comparing the current minute bar to yesterday's day bar's close:
              Open[0] < Closes[2][1]

              Try switching to that and see if you get your buy signals correctly.

              Adding Print() statements can help you see what the current value of bars or time periods is, which helps debug logic. For more information on debugging NinjaScript, please see this post: http://www.ninjatrader.com/support/f...ead.php?t=3418

              Let me know if I can assist you any further.
              DexterNinjaTrader Customer Service

              Comment


                #8
                Stil no buys...puzzled......

                Comment


                  #9
                  Hello stalt,

                  Lets try a few more things. Since we need to check yesterdays close, lets check if we have a bar for yesterday yet. We also need to narrow down and run this code only on the day bar update. try adding this in the top of your OnBarUpdate:
                  Code:
                  if(BarsInProgress == 2 && CurrentBar < 1)
                      return;
                  This will make sure we have at least 2 day bars (Yesterday, and current day's building bar) before trying to access yesterday's close. Give this a try and let me know if it works.
                  DexterNinjaTrader Customer Service

                  Comment


                    #10
                    Still no trades....
                    Just to be sure I put this in the correct spot, here is all the code...
                    protectedoverridevoid Initialize()
                    {
                    Add(PriorDayOHLC());
                    Add(EMA(
                    5));
                    Add(PeriodType.Minute,
                    1);
                    Add(PeriodType.Day,
                    1);
                    CalculateOnBarClose =
                    false;
                    }
                    ///<summary>
                    /// Called on each bar update event (incoming tick)
                    ///</summary>
                    protectedoverridevoid OnBarUpdate()
                    {
                    if(BarsInProgress == 2 && CurrentBar < 1)
                    return;
                    // Condition set 1
                    if (Open[0] < Closes[2][1])

                    {
                    EnterLong(
                    1000, "Long");
                    }


                    }

                    Comment


                      #11
                      Hi stalt,

                      I forgot to mention to put it in an if / else. You will also need to check the current timeframe OnBarUpdate() is currently in. Like this:
                      Code:
                      if (BarsInProgress == 2)
                      {
                      	if(CurrentBar < 1)
                      		return;
                      	else if(Close[1] > Opens[1][0])
                      		EnterLong(1000, "Long");
                      					
                      }
                      Something like that, sorry about the confusion.
                      I changed the logic around: Close[1] > Opens[1][0]= if the Close of a the day bar yesterday is greater than the Open of the current minute bar. Close[1] refers to the Day bars because we are in a BarsInProgress check.
                      Give that a try and see if you correctly get buy signals.
                      Last edited by NinjaTrader_Dexter; 04-21-2011, 04:34 PM.
                      DexterNinjaTrader Customer Service

                      Comment


                        #12
                        really apprecciate the quick response, but again no trades....0 results

                        Comment


                          #13
                          sorry my bad! I got some results! let me check them!

                          Comment


                            #14
                            dang...defaulted to another startegy...still no re****s with htis strategy....

                            Comment


                              #15
                              Could you please post the full export of what you attempt to use so we could give it a run here later today? Do you see any log tab errors as you attempt to run it or does it just not deliver the trades you seek?

                              Thanks,

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              668 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              377 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              110 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              575 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              580 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X