Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Script for 8:30am open & add function

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

    Script for 8:30am open & add function

    I'm migrating from Metastock to NT, therefore I'm in need of some help with the following:
    * For the NT indicator "Current DayOHL", how can I script an open to be at 8:30 am, instead of the normal open (I trade eminis)?
    * I downloaded an indicator that shows no errors when compiled. As I added additional script to it, the add function is not plotting the new script. The existing indicator has:

    Add(new Plot(new Pen(Color.Green,2), PlotStyle.Bar, "BullBar"));
    Add(new Plot(new Pen(Color.Red,2), PlotStyle.Bar, "BearBar"));

    I later included:

    Add(new Plot(new Pen(Color.Gold,2), PlotStyle.Bar, "GldBar"));
    where GldBar is calculated in the main section (GldBar.Set([0])) and the parameters defined in the Properties section.

    There are no compilation errors, but GldBar will not plot as I have it with the above Add function. On the other hand if in the main section of the calculations I replace GldBar.Set([0]) with BullBar.Set([0]) it will plot a gold bar based on the calculations. What am I missing?

    Thanks

    #2
    Hello 2Look4me,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    1. For the CurrentDayOHL, you would not need to change the code but rather change the Session Template used to a session that opens at 8:30 AM. You can create and edit Session Templates under the Session Manager in Tools > Session Manager. Session Templates are applied via the Data Series menu of the chart > right click > Data Series. For information on the Session Manager and Session Template please visit the following link: http://www.ninjatrader.com/support/h...on_manager.htm

    2. Is GldBar set as the DataSeries name for the plot? You can check this under the #region Properties section of the code. Change anything in reference to the BullBar to GldBar.

    Please let me know if you have any questions.

    Comment


      #3
      PatrickH, thanks for the prompt response.
      1. I believe I made a mistake when I said to change the code to reflect an open at 8:30 am, instead of the normal open. Therefore your advice was consistent with my request.

      Although the normal Eminis open is not of importance in my calculations; I still want to keep the Highs & Lows prior to 8:30 am.

      I would like to create a point in time that I can reference (I picked 8:30 am) as more bullish (when trading above 8:30 am) or more bearish (when trading below 8:30 am).

      The Metastock script is: C > (ValueWhen(1, Hour()=8 AND Minute()=30,O)) or
      C < (ValueWhen(1, Hour()=8 AND Minute()=30,O)) for Bullish and Bearish respectively.

      Therefore, I need assistance in coding 8:30 am as a point of reference. 8:30 am is an arbitrary time, for it can be 8:40am or 8:50 am, etc.

      2. I did have GldBar set as the DataSeries under the #region Properties. I had the following script:
      [Browsable(false)]
      [XmlIgnore()]
      private DataSeries GldBar
      {
      get { return Values[3]; }
      }

      I believe the GldBar DataSeries format and syntax is consistent with the other DataSeries that are plotting well. But somehow I am having problems plotting GldBar. Any other suggestions?

      Comment


        #4
        Hello 2look4me,

        Thank you for your response.

        The code in NinjaScript would be the following:
        Code:
        if(Close[0] > Close[CurrentBar - Bars.GetBar(new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 8, 30, 0))])
        //Bull
        Code:
        if(Close[0] < Close[CurrentBar - Bars.GetBar(new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 8, 30, 0))])
        //Bear
        For the Plot, may we review the full indicator for the GldBar? You can send it to platformsupport[at]ninjatrader[dot]com if you prefer, with this thread in the subject line: 'http://www.ninjatrader.com/support/forum/showthread.php?t=70765'

        Comment


          #5
          Patrick, thanks for the script. I'm trying different variations with the plot to see what works, else will send it in to support as last recourse.

          Comment


            #6
            Hi Patrick,

            For the CurrentDayOHL indicator, replacing the CurrentOpen = Open [0] with the 8:30 time script, it doesn't plot a horizontal line consistent with the 8:30 time

            if (currentDate != Bars.GetTradingDayFromLocal(Time[0]) || currentOpen == double.MinValue)
            {
            currentOpen = Close[CurrentBar-Bars.GetBar(new DateTime(Time[0].Year,Time[0].Month,Time[0].Day,8,30,0))];
            currentHigh = High[0];
            currentLow = Low[0];
            sameDay = false;
            }
            What did I miss?

            Comment


              #7
              Hello 2Look4me,

              Thank you for your post.

              What instrument are you testing this on? What session template are you using when you right click in the chart > select Data Series > Session Template?

              Comment


                #8
                I'm just testing it on the TF(Russell 2K eminis).
                The session template shows "use instrument settings"

                Comment


                  #9
                  Hello 2Look4me,

                  Can you provide a screenshot of the inconsistent horizontal line?

                  Comment


                    #10
                    I'm enclosing attachment for 3 different dates.
                    Attached Files

                    Comment


                      #11
                      Hello 2Look4me,

                      Thank you for your response.

                      Please try the code below instead:
                      Code:
                      			if (currentDate != Bars.GetTradingDayFromLocal(Time[0]) || currentOpen == double.MinValue)
                      			{
                      				currentOpen = Open[0];
                      				currentHigh 	= 	High[0];
                      				currentLow		=	Low[0];
                      				sameDay         =   false;
                      			}
                      			if(ToTime(Time[0]) < ToTime(8,30,0))
                      			{
                      				currentOpen = Open[0];
                      				PlotColors[0][0] = Color.Transparent;
                      			}
                      			
                      			if(currentDate == Bars.GetTradingDayFromLocal(Time[0]) && ToTime(Time[0]) >= ToTime(8,30,0))
                      				currentOpen = Close[CurrentBar-Bars.GetBar(new DateTime(Time[0].Year,Time[0].Month,Time[0].Day,8,30,0))];

                      Comment


                        #12
                        Thanks Patrick, that worked great.
                        Happy New Year!

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        576 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        334 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        101 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        553 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        551 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X