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

Check if previous day's close was smaller then open

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

    Check if previous day's close was smaller then open

    Hey there,


    How do I check whether the previous day`s close was smaller than the previous day`s open?

    In TradeSignal the code would look like this:

    Code:
     if dayofweek(date)=2
      
    and close[1]<(100-MinDown)/100*open[1]
    then buy this bar at open;

    Does someone know how my code should look like in NT7?

    #2
    Hello SpaceGrey,

    Thanks for your post.

    If you are using daily bars then you can check if (Close[1] < Open[1])
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Paul View Post
      Hello SpaceGrey,

      Thanks for your post.

      If you are using daily bars then you can check if (Close[1] < Open[1])

      Thank you very much, do you also know how I can check if the close from monday was lower then the open on monday - if so: he should execute a order on the next day (tuesday)


      I tried it like this:

      Code:
      	if (Time[0].DayOfWeek == DayOfWeek.Monday && alreadyTradedToday == false)
      			{
      		
      				
      					if(Close[0] > Open[0]){
      						
      						if (Time[0].DayOfWeek == DayOfWeek.Tuesday && alreadyTradedToday == false)
      							
      			{
      					EnterLong(Convert.ToInt32(DefaultQuantity), "");
      				alreadyTradedToday = true;
      			}

      But it doesnt seem to work

      Comment


        #4
        Hello SpaceGrey,

        Thanks for your reply.

        The issue is that you won't have Time = Monday and Time = Tuesday at the same time.

        I've reworked your code (not tested), please test on the sim101 account

        if (Time[0].DayOfWeek == DayOfWeek.Monday && alreadyTradedToday == false)
        {
        if(Close[0] < Open[0]) // changed this as i thought you wanted close less than the open?
        {
        EnterLong(Convert.ToInt32(DefaultQuantity), "");
        alreadyTradedToday = true;
        }
        }
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Paul View Post
          Hello SpaceGrey,

          Thanks for your reply.

          The issue is that you won't have Time = Monday and Time = Tuesday at the same time.

          I've reworked your code (not tested), please test on the sim101 account

          if (Time[0].DayOfWeek == DayOfWeek.Monday && alreadyTradedToday == false)
          {
          if(Close[0] < Open[0]) // changed this as i thought you wanted close less than the open?
          {
          EnterLong(Convert.ToInt32(DefaultQuantity), "");
          alreadyTradedToday = true;
          }
          }
          Okay thank you, worked perfectly - but it still trades on monday?
          It should actually trade on tuesday, IF the close is less than the open on monday

          Comment


            #6
            Hello SpaceGrey,

            Thanks for your reply.

            To assist further, please post a screenshot of your chart that shows the orders and also post your complete code, thank-you.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Paul View Post
              Hello SpaceGrey,

              Thanks for your reply.

              To assist further, please post a screenshot of your chart that shows the orders and also post your complete code, thank-you.

              I have not tested it yet on a chart but my code looks like this:

              Code:
              
              #region Using declarations
              using System;
              using System.ComponentModel;
              using System.Diagnostics;
              using System.Drawing;
              using System.Drawing.Drawing2D;
              using System.Xml.Serialization;
              using NinjaTrader.Cbi;
              using NinjaTrader.Data;
              using NinjaTrader.Indicator;
              using NinjaTrader.Gui.Chart;
              using NinjaTrader.Strategy;
              #endregion
              
              // This namespace holds all strategies and is required. Do not change it.
              namespace NinjaTrader.Strategy
              {
                  /// <summary>
                  /// 
                  /// </summary>
                  [Description("")]
                  public class Tuesday : Strategy
                  {
                      #region Variables
                      // Wizard generated variables
                      private int myInput0 = 1; // Default setting for MyInput0
                      // User defined variables (add any user defined variables below)
                      #endregion
              		
              		bool alreadyTradedToday = false;
              
                      /// <summary>
                      /// This method is used to configure the strategy and is called once before any strategy method is called.
                      /// </summary>
                      protected override void Initialize()
                      {
                          CalculateOnBarClose = true;
                      }
              
                      /// <summary>
                      /// Called on each bar update event (incoming tick)
                      /// </summary>
                      protected override void OnBarUpdate()
                      {
              			
              			if(CurrentBar <2) return;
              		 if (Time[0].DayOfWeek != Time[1].DayOfWeek) // Neuer Tag
                 {   
              	
                        	alreadyTradedToday = false;
              
              }
              			
              			if (Time[0].DayOfWeek == DayOfWeek.Monday && alreadyTradedToday == false) {
                           if(Close[0] < Open[0]) 
                 {
              EnterLong(Convert.ToInt32(DefaultQuantity), "");
              alreadyTradedToday = true;
                  } 
              }
              
              
              
                      }
              
                      #region Properties
                      [Description("")]
                      [GridCategory("Parameters")]
                      public int MyInput0
                      {
                          get { return myInput0; }
                          set { myInput0 = Math.Max(1, value); }
                      }
                      #endregion
                  }
              }
              and another question: Is there any limitation on how many strategies I can trade at the same time? 30? 50? 100? or is there no limit?

              Comment


                #8
                Hello SpaceGrey,

                Thanks for your reply.

                The only limit to the number of strategies would be the loading of your PC's resources. NinjaTrader7 only uses 1 core of a multicore PC so the CPU is likely to be the limiting factor.

                I am a bit confused by your comments and would appreciate if you can clarify:
                "Okay thank you, worked perfectly - but it still trades on monday?
                It should actually trade on tuesday, IF the close is less than the open on monday"
                and "I have not tested it yet on a chart but my code looks like this:"

                Are you running this in the strategy analyzer? If so can you provide a screenshot of the chart (showing the incorrect entries) in the strategy analyzer along with the settings that you using in the strategy analyzer?

                If you haven't tested your code then I suggest you test your code either on a chart or in the strategy analyzer and provide a screenshot of the results that show where the trades occurred that are not what you wanted.

                Thanks in advance for further clarifications.
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Here are 2 Images.

                  As you can see in the "Entry Time" on the first image:
                  all these dates are on Monday - but they actually should be on Tuesday.

                  Like I said:

                  my script should check if the close from monday was lower then the open on monday - IF SO: he should execute a order on the next day (TUESDAY)

                  on the second & third image you can see a trade on the chart.

                  Link to the 3 images: https://imgur.com/a/utSS7iN

                  Comment


                    #10
                    Hello SpaceGrey,

                    Thanks for your reply and screenshots.

                    The reason for asking to see a chart screenshot is to make sure we are discussing the same thing and in this case we are not. My assumption, since post #2 is that you are using daily bars and the chart screenshots are showing minute bars so from this point forward I will provide answers based on you using minute bars on the forex instrument.

                    By default, NinjaTrader will assign the forex instruments the forex session template which runs from 5 PM of 1 day to the next day at 5PM.

                    With the above in mind, are you wanting to place your order on the first bar of the session on Tuesday ( first bar = 5:01 PM?) or 5:01PM on Monday which would be the beginning of the Tuesday session?
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Paul View Post
                      Hello SpaceGrey,

                      Thanks for your reply and screenshots.

                      The reason for asking to see a chart screenshot is to make sure we are discussing the same thing and in this case we are not. My assumption, since post #2 is that you are using daily bars and the chart screenshots are showing minute bars so from this point forward I will provide answers based on you using minute bars on the forex instrument.

                      By default, NinjaTrader will assign the forex instruments the forex session template which runs from 5 PM of 1 day to the next day at 5PM.

                      With the above in mind, are you wanting to place your order on the first bar of the session on Tuesday ( first bar = 5:01 PM?) or 5:01PM on Monday which would be the beginning of the Tuesday session?


                      on Monday which would be the beginning of the Tuesday session

                      Comment


                        #12
                        Hello SpaceGrey,

                        Thanks for your reply and further clarification.

                        As you are using less than daily bars, to obtain the prior day Open and prior day Close values you can use the Indicator PriorDayOHLC as this indicator provides those values. This would allow you to determine if the prior day close is less than the Open. Reference: https://ninjatrader.com/support/help...r_day_ohlc.htm

                        The system property Bars.FirstBarOfSession is a bool that is true only once per session on the very first bar and you can use this as a condition for your entry. Reference: https://ninjatrader.com/support/help...rofsession.htm

                        By checking if it is the first bar of the session and if the bar is day of week Monday then this would be the beginning of the Tuesday session.

                        Putting it together would look like:

                        if (Bars.FirstBarOfSession)
                        {
                        if (Time[0].DayOfWeek == DayOfWeek.Monday)
                        {
                        if (PriorDayOHLC().PriorClose[0] < PriorDayOHLC().PriorOpen[0])
                        {
                        EnterLong(Convert.ToInt32(DefaultQuantity), "");
                        }
                        }
                        }
                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Paul View Post
                          Hello SpaceGrey,

                          Thanks for your reply and further clarification.

                          As you are using less than daily bars, to obtain the prior day Open and prior day Close values you can use the Indicator PriorDayOHLC as this indicator provides those values. This would allow you to determine if the prior day close is less than the Open. Reference: https://ninjatrader.com/support/help...r_day_ohlc.htm

                          The system property Bars.FirstBarOfSession is a bool that is true only once per session on the very first bar and you can use this as a condition for your entry. Reference: https://ninjatrader.com/support/help...rofsession.htm

                          By checking if it is the first bar of the session and if the bar is day of week Monday then this would be the beginning of the Tuesday session.

                          Putting it together would look like:

                          if (Bars.FirstBarOfSession)
                          {
                          if (Time[0].DayOfWeek == DayOfWeek.Monday)
                          {
                          if (PriorDayOHLC().PriorClose[0] < PriorDayOHLC().PriorOpen[0])
                          {
                          EnterLong(Convert.ToInt32(DefaultQuantity), "");
                          }
                          }
                          }

                          Thank you very much Paul, it works perfect!!


                          But I still have a question: Is there also a way to entry a longposition, if the monday falls more then 1%?

                          Comment


                            #14
                            Hello SpaceGrey,

                            Thanks for your reply.

                            You would just need to enter your condition coding into the example code previously provided as an entry condition.
                            Paul H.NinjaTrader Customer Service

                            Comment


                              #15
                              Yes I know but my question was how I can detect the falling % on a certain day

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NRITV, Today, 01:15 PM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by maybeimnotrader, Yesterday, 05:46 PM
                              5 responses
                              24 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by quantismo, Yesterday, 05:13 PM
                              2 responses
                              16 views
                              0 likes
                              Last Post quantismo  
                              Started by frankthearm, Today, 09:08 AM
                              6 responses
                              27 views
                              0 likes
                              Last Post frankthearm  
                              Started by adeelshahzad, Today, 03:54 AM
                              5 responses
                              33 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Working...
                              X