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

Gap UP and Down Strategy

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

    Gap UP and Down Strategy

    Hello All,

    this is a first time I m trying to build strategy for GAP UP and GAP Down

    I would like to put Dot on chart where
    Today Open higher than Yesterday High and (Gap up)
    Today Open Lower then Yesterday Low (Gap Down)

    I build strategy but Dot are not paint on Daily chart for this example i ran this script on
    NQ 03-17

    here is code

    public class Runner : Strategy
    {
    #region Variables
    // Wizard generated variables
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    Add(CurrentDayOHL());
    Add(PriorDayOHLC());
    Add(CurrentDayOHL());
    Add(PriorDayOHLC());

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (CurrentDayOHL().CurrentOpen[0] > PriorDayOHLC().PriorHigh[0])
    {
    DrawDot("My dot" + CurrentBar, false, 0, Low[0] + -5 * TickSize, Color.Green);
    }

    // Condition set 2
    if (CurrentDayOHL().CurrentOpen[0] < PriorDayOHLC().PriorLow[0])
    {
    DrawDot("My dot" + CurrentBar, false, 0, High[0] + 5 * TickSize, Color.Green);
    }
    }

    Can someone tell me what I'm doing wrong here please

    #2
    Originally posted by niks.baps View Post
    Hello All,



    Can someone tell me what I'm doing wrong here please
    Is nothing happening? Are there errors in the log or output window?

    You could put in some Print statements to see what is going on in the output window.

    Code:
            protected override void OnBarUpdate()
            {
               Print ( "CurrentOpen="+CurrentDayOHL().CurrentOpen[0] );
              Print ( "PriorLow=" +  PriorDayOHLC().PriorLow[0]);
              Print ( "PriorHigh=" + PriorDayOHLC().PriorHigh[0]);
    
          // Condition set 1
    ....

    Comment


      #3
      when I used below print statement hare output I got


      Print (Time[0] + " CurrentOpen="+CurrentDayOHL().CurrentOpen[0] );
      Print (Time[0] + " PriorLow=" + PriorDayOHLC().PriorLow[0]);
      Print (Time[0] + " PriorHigh=" + PriorDayOHLC().PriorHigh[0]);



      Output
      12/15/2016 4:15:00 PM CurrentOpen=4933.75
      12/15/2016 4:15:00 PM PriorLow=4933.75
      12/15/2016 4:15:00 PM PriorHigh=4933.75

      NQ 03-17 Dec 15 Close = 4933.75

      Comment


        #4
        So none of your DrawDots are being called because everything is equal, and you are not getting errors.

        I've never used CurrentDayOHL or PriorDayOHLC, but you should probably concentrate research on PriorDayOHLC.


        -----
        edit----

        it should be working? Are you using this in market replay? Or live connection?

        Last edited by sledge; 12-17-2016, 09:52 PM.

        Comment


          #5
          I'm using on Live data and No error

          this is first time so dont know how to get Prior Day High and Prior day Low and compare against today open ,So i use indicator ,and Indicator only reading close price

          Comment


            #6
            here is what I'm trying to build

            If Current Day Open > Yesterdays High -- Dot under current candle -5 tick
            if Current Day Open < Yesterday Low -- Dot top on current candle +5 Tick

            Comment


              #7
              Hello niks.baps,

              It is fine to use those indicators to get the current day's open and previous day's high.

              The condition you have also appears correct for the description you have given.

              However, based on the output from the prints, it looks like the condition is not true. The current open is not greater than the previous day's high as they are equal, so no dot is drawn.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                I want to this condition true for all bars on chart ,not only current bar
                what should do in that case Please advice


                Also output i paste here just for one day ,but actually it same output for all bars on chart

                11/1/2016 5:15:00 PM CurrentOpen=4758.5
                11/1/2016 5:15:00 PM PriorLow=4758.5
                11/1/2016 5:15:00 PM PriorHigh=4758.5
                11/2/2016 5:15:00 PM CurrentOpen=4718.5
                11/2/2016 5:15:00 PM PriorLow=4718.5
                11/2/2016 5:15:00 PM PriorHigh=4718.5
                11/3/2016 5:15:00 PM CurrentOpen=4676
                11/3/2016 5:15:00 PM PriorLow=4676
                11/3/2016 5:15:00 PM PriorHigh=4676
                11/4/2016 5:15:00 PM CurrentOpen=4658.25
                11/4/2016 5:15:00 PM PriorLow=4658.25
                11/4/2016 5:15:00 PM PriorHigh=4658.25
                11/7/2016 5:15:00 PM CurrentOpen=4777.25
                11/7/2016 5:15:00 PM PriorLow=4777.25
                11/7/2016 5:15:00 PM PriorHigh=4777.25
                11/8/2016 5:15:00 PM CurrentOpen=4802
                11/8/2016 5:15:00 PM PriorLow=4802
                11/8/2016 5:15:00 PM PriorHigh=4802
                11/9/2016 5:15:00 PM CurrentOpen=4821
                11/9/2016 5:15:00 PM PriorLow=4821
                11/9/2016 5:15:00 PM PriorHigh=4821
                11/10/2016 5:15:00 PM CurrentOpen=4743.5
                11/10/2016 5:15:00 PM PriorLow=4743.5
                11/10/2016 5:15:00 PM PriorHigh=4743.5
                11/11/2016 5:15:00 PM CurrentOpen=4749.75
                11/11/2016 5:15:00 PM PriorLow=4749.75
                11/11/2016 5:15:00 PM PriorHigh=4749.75
                11/14/2016 5:15:00 PM CurrentOpen=4695.75
                11/14/2016 5:15:00 PM PriorLow=4695.75
                11/14/2016 5:15:00 PM PriorHigh=4695.75
                11/15/2016 5:15:00 PM CurrentOpen=4766.75
                11/15/2016 5:15:00 PM PriorLow=4766.75
                11/15/2016 5:15:00 PM PriorHigh=4766.75
                11/16/2016 5:15:00 PM CurrentOpen=4785.25
                11/16/2016 5:15:00 PM PriorLow=4785.25
                11/16/2016 5:15:00 PM PriorHigh=4785.25
                11/17/2016 5:15:00 PM CurrentOpen=4829.75
                11/17/2016 5:15:00 PM PriorLow=4829.75
                11/17/2016 5:15:00 PM PriorHigh=4829.75
                11/18/2016 5:15:00 PM CurrentOpen=4808.75
                11/18/2016 5:15:00 PM PriorLow=4808.75
                11/18/2016 5:15:00 PM PriorHigh=4808.75
                11/21/2016 5:15:00 PM CurrentOpen=4853.75
                11/21/2016 5:15:00 PM PriorLow=4853.75
                11/21/2016 5:15:00 PM PriorHigh=4853.75
                11/22/2016 5:15:00 PM CurrentOpen=4875.5
                11/22/2016 5:15:00 PM PriorLow=4875.5
                11/22/2016 5:15:00 PM PriorHigh=4875.5
                11/23/2016 5:15:00 PM CurrentOpen=4850.5
                11/23/2016 5:15:00 PM PriorLow=4850.5
                11/23/2016 5:15:00 PM PriorHigh=4850.5
                11/24/2016 5:15:00 PM CurrentOpen=4863.5
                11/24/2016 5:15:00 PM PriorLow=4863.5
                11/24/2016 5:15:00 PM PriorHigh=4863.5
                11/25/2016 5:15:00 PM CurrentOpen=4870.5
                11/25/2016 5:15:00 PM PriorLow=4870.5
                11/25/2016 5:15:00 PM PriorHigh=4870.5
                11/28/2016 5:15:00 PM CurrentOpen=4862.25
                11/28/2016 5:15:00 PM PriorLow=4862.25
                11/28/2016 5:15:00 PM PriorHigh=4862.25
                11/29/2016 5:15:00 PM CurrentOpen=4875.25
                11/29/2016 5:15:00 PM PriorLow=4875.25
                11/29/2016 5:15:00 PM PriorHigh=4875.25
                11/30/2016 5:15:00 PM CurrentOpen=4822
                11/30/2016 5:15:00 PM PriorLow=4822
                11/30/2016 5:15:00 PM PriorHigh=4822
                12/1/2016 5:15:00 PM CurrentOpen=4736.25
                12/1/2016 5:15:00 PM PriorLow=4736.25
                12/1/2016 5:15:00 PM PriorHigh=4736.25
                12/2/2016 5:15:00 PM CurrentOpen=4738.75
                12/2/2016 5:15:00 PM PriorLow=4738.75
                12/2/2016 5:15:00 PM PriorHigh=4738.75
                12/5/2016 5:15:00 PM CurrentOpen=4781.25
                12/5/2016 5:15:00 PM PriorLow=4781.25
                12/5/2016 5:15:00 PM PriorHigh=4781.25
                12/6/2016 5:15:00 PM CurrentOpen=4788.25
                12/6/2016 5:15:00 PM PriorLow=4788.25
                12/6/2016 5:15:00 PM PriorHigh=4788.25
                12/7/2016 5:15:00 PM CurrentOpen=4842.5
                12/7/2016 5:15:00 PM PriorLow=4842.5
                12/7/2016 5:15:00 PM PriorHigh=4842.5
                12/8/2016 5:15:00 PM CurrentOpen=4861.75
                12/8/2016 5:15:00 PM PriorLow=4861.75
                12/8/2016 5:15:00 PM PriorHigh=4861.75
                12/9/2016 5:15:00 PM CurrentOpen=4892.25
                12/9/2016 5:15:00 PM PriorLow=4892.25
                12/9/2016 5:15:00 PM PriorHigh=4892.25
                12/12/2016 5:15:00 PM CurrentOpen=4865.75
                12/12/2016 5:15:00 PM PriorLow=4865.75
                12/12/2016 5:15:00 PM PriorHigh=4865.75
                12/13/2016 5:15:00 PM CurrentOpen=4937.25
                12/13/2016 5:15:00 PM PriorLow=4937.25
                12/13/2016 5:15:00 PM PriorHigh=4937.25
                12/14/2016 5:15:00 PM CurrentOpen=4931.5
                12/14/2016 5:15:00 PM PriorLow=4931.5
                12/14/2016 5:15:00 PM PriorHigh=4931.5
                12/15/2016 5:15:00 PM CurrentOpen=4933.75
                12/15/2016 5:15:00 PM PriorLow=4933.75
                12/15/2016 5:15:00 PM PriorHigh=4933.75
                Last edited by niks.baps; 12-18-2016, 02:16 PM.

                Comment


                  #9
                  Hello niks.baps,

                  You will not be able to force the condition to be true if this is not true.
                  If you want the condition to always be true, do not use a condition.

                  For example on 12/15 the CurrentOpen is 4933.75, the PriorHigh is 4933.75. Because these are the same, the current open is not greater than the prior high and the condition evaluates as false.

                  On 12/14 the CurrentOpen is 4931.5, the PriorHigh is 4931.5. These are equal. Since the current open is not greater than the previous high the condition evaluates as false.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Right now code is only reading Daily Close only

                    I have 180 days of Data on NQ 03-17 and for all previous day data code reading only close price for that Day
                    12/12/2016 5:15:00 PM CurrentOpen=4865.75
                    12/12/2016 5:15:00 PM PriorLow=4865.75
                    12/12/2016 5:15:00 PM PriorHigh=4865.75
                    12/13/2016 5:15:00 PM CurrentOpen=4937.25
                    12/13/2016 5:15:00 PM PriorLow=4937.25
                    12/13/2016 5:15:00 PM PriorHigh=4937.25
                    12/14/2016 5:15:00 PM CurrentOpen=4931.5
                    12/14/2016 5:15:00 PM PriorLow=4931.5
                    12/14/2016 5:15:00 PM PriorHigh=4931.5
                    12/15/2016 5:15:00 PM CurrentOpen=4933.75
                    12/15/2016 5:15:00 PM PriorLow=4933.75
                    12/15/2016 5:15:00 PM PriorHigh=4933.75

                    for example if you at NQ 03 -17 December 15,14,13 Open ,High Low code reading Same value


                    What I'm trying to do is
                    which ever day Full GAP UP or Down I would like to paint Dot at the top or bottom of the Daily candle

                    Here is the code I have

                    protected override void Initialize()
                    {
                    Add(CurrentDayOHL());
                    Add(PriorDayOHLC());
                    Add(CurrentDayOHL());
                    Add(PriorDayOHLC());

                    CalculateOnBarClose = true;
                    }

                    /// <summary>
                    /// Called on each bar update event (incoming tick)
                    /// </summary>
                    protected override void OnBarUpdate()
                    {

                    // Condition set 1
                    Print (Time[0] + " CurrentOpen="+CurrentDayOHL().CurrentOpen[0] );
                    Print (Time[0] + " PriorLow=" + PriorDayOHLC().PriorLow[0]);
                    Print (Time[0] + " PriorHigh=" + PriorDayOHLC().PriorHigh[0]);

                    if (CurrentDayOHL().CurrentOpen[1] > PriorDayOHLC().PriorHigh[0] )
                    {
                    Print(Time[0] + "GapUP");
                    DrawDot("My dot" + CurrentBar, false, 0, Low[0] + -5 * TickSize, Color.Green);
                    }

                    // Condition set 2
                    if (CurrentDayOHL().CurrentOpen[0] <PriorDayOHLC().PriorLow[0])
                    {
                    Print(Time[0] + "GapDown");
                    DrawDot("My dot" + CurrentBar, false, 0, High[0] + 5 * TickSize, Color.Green);
                    }
                    }

                    Comment


                      #11
                      Hello Niks.baps,

                      Thank you for your note.

                      The issue is that CurrentDayOHL and PriorDayOHL only work when applied to an intraday data series.

                      What you can do is add a minute secondary data series, then limit your code to run on the secondary data series only using BarsInProgress.

                      Under Initialize,

                      Add(PeriodType.Minute,60);

                      Under OnBarUpdate()
                      if(CurrentBar<1) return;

                      if(BarsInProgress==1)
                      {
                      Print (Time[0] + " CurrentOpen="+CurrentDayOHL().CurrentOpen[0] );
                      Print (Time[0] + " PriorLow=" + PriorDayOHLC().PriorLow[0]);
                      Print (Time[0] + " PriorHigh=" + PriorDayOHLC().PriorHigh[0]);

                      if (CurrentDayOHL().CurrentOpen[1] > PriorDayOHLC().PriorHigh[0] )
                      {
                      Print(Time[0] + "GapUP");
                      DrawDot("My dot" + CurrentBar, false, 0, Low[0] + -5 * TickSize, Color.Green);
                      }

                      // Condition set 2
                      if (CurrentDayOHL().CurrentOpen[0] <PriorDayOHLC().PriorLow[0])
                      {
                      Print(Time[0] + "GapDown");
                      DrawDot("My dot" + CurrentBar, false, 0, High[0] + 5 * TickSize, Color.Green);
                      }
                      }
                      }

                      CurrentDayOHL section of our Helpguide:


                      Please let us know if you need further assistance.
                      Alan P.NinjaTrader Customer Service

                      Comment


                        #12
                        Thank you for your help I use below code

                        if(CurrentBar<1) return;

                        if(BarsInProgress==1)
                        {
                        Print (Time[0] + " CurrentOpen="+CurrentDayOHL().CurrentOpen[0] );
                        Print (Time[0] + " PriorLow=" + PriorDayOHLC().PriorLow[0]);
                        Print (Time[0] + " PriorHigh=" + PriorDayOHLC().PriorHigh[0]);

                        if (CurrentDayOHL().CurrentOpen[0] > PriorDayOHLC().PriorHigh[0] )
                        {
                        Print(Time[0] + "GapUP");
                        DrawDot("My dot" + CurrentBar, false, 0, Low[0] + -5 * TickSize, Color.Green);
                        }

                        // Condition set 2
                        if (CurrentDayOHL().CurrentOpen[0] <PriorDayOHLC().PriorLow[0])
                        {
                        Print(Time[0] + "GapDown");
                        DrawDot("My dot" + CurrentBar, false, 0, High[0] + 5 * TickSize, Color.Green);
                        }
                        }
                        }

                        Now Code reading correct Previous Day High and Low ,
                        But Current Open (Todays Open ) reading value previous day close

                        YM 03 -17
                        Dec 20th Open -- > 19882
                        Dec 19th High --> 19860
                        Dec19th Low --> 19792
                        Dec 19th Close --> 19838

                        Output from Code :
                        12/20/2016 4:00:00 PM CurrentOpen=19838
                        12/20/2016 4:00:00 PM PriorLow=19792
                        12/20/2016 4:00:00 PM PriorHigh=19860

                        Comment


                          #13
                          Hello niks.baps,

                          The values are printing correctly, the Dec 20th globex open was 18838, which you can confirm on CME’s website,

                          Find information for E-mini Dow Jones Industrial Average Index Futures Settlements provided by CME Group. View Settlements


                          The open you are referring to, 19882 was the US Stock Market Open at 930AM Est time.

                          CurrentDayOHL is going to refer to the Globex open at 6PM est time rather than the regular trading hours open.

                          Please let us know if you need further assistance.
                          Alan P.NinjaTrader Customer Service

                          Comment


                            #14
                            Thanks Alan for response

                            I check that and it is reading right
                            what change I should make for CurrentDayOHL to read open at 9:30 est time instead of 6:00PM

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by alifarahani, Today, 09:40 AM
                            6 responses
                            31 views
                            0 likes
                            Last Post alifarahani  
                            Started by Waxavi, Today, 02:10 AM
                            1 response
                            17 views
                            0 likes
                            Last Post NinjaTrader_LuisH  
                            Started by Kaledus, Today, 01:29 PM
                            5 responses
                            13 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Started by Waxavi, Today, 02:00 AM
                            1 response
                            12 views
                            0 likes
                            Last Post NinjaTrader_LuisH  
                            Started by gentlebenthebear, Today, 01:30 AM
                            3 responses
                            17 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Working...
                            X