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

Up Day/Down Day Trigger Variable

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

    Up Day/Down Day Trigger Variable

    What is the simplest way to include a variable that indicates whether the market is Up or Down? (by looking at DOW / S&P500 / NASDAQ)

    I just want to include in my condition something like: "If S&P gain is currently positive, then ... " etc.

    Thank you,
    Joe

    #2
    Hello Joe,
    Thanks for your post and I am happy to assist you.
    You can create a multi-instrument indicator/strategy to achieve the same http://www.ninjatrader.com/support/h...nstruments.htm

    Like, in Initialize
    Code:
    Add("ES 02-12", PeriodType.Day, 1);
    And in OnBarUpdate
    Code:
    if ([URL="http://www.ninjatrader.com/support/helpGuides/nt7/index.html?barsinprogress.htm"]BarsInProgress[/URL] == 1)
    {
    	if (CurrentBar < 1) return;
    	if (Close[0] >= Close[1])
    	{
    		//do something
    	}
    	else if (Close[0] < Close[1])
    	{
    		//do something
    	}
    }
    Please do let me know if I can be of any further assistance.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Thank you for your prompt help.

      If I want to look at the added bar, and also the current bar at the same time, would the following work?

      if (Closes[0][0] >= Closes[0][1] && Closes[1][0] >= Closes[1][1]) ..

      Also, does Close[1] refer to just the previous bar? Or the first bar...Because if it's the previous bar, that does not indicate an up day if I'm looking at intraday data.

      In this case, I would use the following to get the close* from the first bar of the day, correct?

      Last edited by joespo; 01-16-2012, 02:51 PM.

      Comment


        #4
        Hello Joe,
        Yes you can look at both the bars at the same time. So your code will work. But do check for the minimum bars like

        if (this.CurrentBars[0] < 1 || this.CurrentBars[1] < 1) return;

        Close[1] refers to the previous close of the current BarsInProgress.

        So if the BarsInProgress is 0 then Close[1] refers to the previous bar of the primary data series (intraday bar) and if the BarsInProgress is 1 then Close[1] refers to the previous bar of the secondary data series (the day bar you added)

        It is always a good idea to filter the data with the BarsInProgress property. You can get more info regarding the same from here http://www.ninjatrader.com/support/h...inprogress.htm

        Also heres the basic concept of Close and Closes



        Please do let me know if I can be of any further assistance.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Amazing; you guys are awesome.

          Thank you.

          Comment


            #6
            Here is the code that I am trying:

            In Initialize():
            Code:
            Add("SPY", PeriodType.Minute, 1);
            In OnBarUpdate():

            Code:
                        int intdatetime = ToDay(Time[0]);
                        string strdatetime = intdatetime.ToString();
                        int intyear = Convert.ToInt32(strdatetime.Substring(0,4));
                        int intmo = Convert.ToInt32(strdatetime.Substring(4,2));
                        int intday = Convert.ToInt32(strdatetime.Substring(6,2));
            Code:
            if Closes[1][0] > Closes[1][CurrentBar - Bars.GetBar(new DateTime(intyear, intmo, intday, 8, 37, 0))] ...
            Code:
            EnterLong();
            I am trying to compare the current bar to the bar at 8:37 AM for that day. If it is greater, then it will go long for the current primary chart (not the SPY).

            But it is still entering into a long position on 12/8 at 9:40 for the current chart...

            Why?

            Here is a link to the SPY on 12/8 which shows that it is down at 9:40 when it enters.

            Comment


              #7
              Hello Joe,
              Thanks for writing in and your kind words.

              If you are not filtering your code with BarsInProgress, then Bars can return the value for the primary data. So its better to use BarsArray[1] in place of Bars, since you are using Closes[1][0] etc.

              Unfortunately Bars/BarsArray is beyond what we can support. But you can refer to this sample code for further reference http://ninjatrader.com/support/forum...ad.php?t=19176

              It is recommended to use the Print function extensively for debugging your code, and verify what value you are getting http://www.ninjatrader.com/support/h...html?print.htm

              Also instead of converting time into a string and then extracting the date/month /day value from that string you can simply use
              Code:
              int intYear = Time[0].Year;
              int intMonth = Time[0].Month; 
              int intDay = Time[0].Day;
              Please let me do know if I can be of any further assistance.
              JoydeepNinjaTrader Customer Service

              Comment


                #8
                Thank you for everything.

                I will look into Bars/BarsArray.
                And I will also start using the Print function (I completely forgot about this for debugging).
                And I will use your more efficient method of getting integer date values (thank you).

                Hopefully I will come back with good news and not have to bother you again!

                Comment


                  #9
                  Hello Joe,
                  Thanks for wring in and wish you luck.

                  Please do let me know if I can assist you any further.
                  JoydeepNinjaTrader Customer Service

                  Comment


                    #10
                    It's working almost perfectly now. Your tips helped solve the issues.

                    Thanks!!

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Belfortbucks, Today, 09:29 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post Belfortbucks  
                    Started by zstheorist, Today, 07:52 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post zstheorist  
                    Started by pmachiraju, 11-01-2023, 04:46 AM
                    8 responses
                    151 views
                    0 likes
                    Last Post rehmans
                    by rehmans
                     
                    Started by mattbsea, Today, 05:44 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post mattbsea  
                    Started by RideMe, 04-07-2024, 04:54 PM
                    6 responses
                    33 views
                    0 likes
                    Last Post RideMe
                    by RideMe
                     
                    Working...
                    X