Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Boolean True/False with other parameters

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

    Boolean True/False with other parameters

    Hello Ninjatrader Team,
    I want to create a true or false Boolean.

    My goal is to create a strategy where first there needs to be a 20 TICK gap from yesterdays close.(this would be the true or false) Then Ninjatrader should look for a stochastic reading greater then or equal 20 ONLY after 11 AM (central time. market for me opens at 8:30 AM) if all of that is true then go long

    This is the code I have right now but I have no idea how to make it work, can someone take a look and correct what is wrong with it .

    Thank you for you help
    Code:
    #region Inputs
    		private bool FirstGAP = false;
    		private int _cntrcts = 1;
    		private TimeSpan _StartTime = new TimeSpan(8, 31, 0);
    		private TimeSpan _ExTime = new TimeSpan(15, 14, 0);
    		private double _StpLs = 200;
    		private double _PrfTg = 200;
    		#endregion
           
            protected override void OnBarUpdate()
            {
    			if (Bars.BarsSinceSession >=40)
    		    if (!FirstGAP && Time[0].TimeOfDay == _StartTime && Close[0]>Bars.GetDayBar(1).Close + 20 * TickSize)
    		        {
    				if (Stochastics(7, 14, 3).D[0] >= 20)
    				
    				EnterLong(0, 1, "Gap long");
    				}
    				
    				
    
    		     	
    			
    			
    			SetProfitTarget(50);
    			
    		}

    #2
    Hello wallsteetking,

    While, I am not quite sure what is not working on your strategy one thing that I do see that may effect how your strategy is that you are checking to see if the time is equal to "_StartTime " so that it will only enter the market if the times are the exact same.

    Note that TimeOfDay will basically return your local PC clock as well.

    Also, you may want to check for "null" using "Bars.GetDayBar(1)" or you may also use the PriorDayOHLC indicator as well.

    Let us know if that helps if not could you clarify what problems are you having? Do you get a message inside of the Log tab?
    JCNinjaTrader Customer Service

    Comment


      #3
      The issue that I am having is once I put in
      Code:
      if (Bars.BarsSinceSession >=40)
      nothing happens/or no trades are found. how can i correct this issue.
      To clarify what I am trying to do.

      The algorithmic should do this.
      Step 1: See if >= 20 Tick gap exist.
      Step 2: wait till 11 AM (No trades before 11AM )then look for stochastic that is >=20
      Step 3 : If step 1 and step 2 are true take long position.

      Code:
      #region Inputs
      		private bool FirstGAP = false;
      		private int _cntrcts = 1;
      		private TimeSpan _StartTime = new TimeSpan(8, 31, 0);
      		private TimeSpan _ExTime = new TimeSpan(15, 14, 0);
      		private double _StpLs = 200;
      		private double _PrfTg = 200;
      		#endregion
             
              protected override void OnBarUpdate()
              {
      			if (Bars.BarsSinceSession >=40)
      		    if (!FirstGAP && Time[0].TimeOfDay == _StartTime && Close[0]>Bars.GetDayBar(1).Close + 20 * TickSize)
      		        {
      				
      				if (Stochastics(7, 14, 3).D[0] >=20)
      				
      				EnterLong(DefaultQuantity, "");
      				}

      Comment


        #4
        Originally posted by wallsteetking View Post
        The issue that I am having is once I put in
        Code:
        if (Bars.BarsSinceSession >=40)
        nothing happens/or no trades are found. how can i correct this issue.
        To clarify what I am trying to do.

        The algorithmic should do this.
        Step 1: See if >= 20 Tick gap exist.
        Step 2: wait till 11 AM (No trades before 11AM )then look for stochastic that is >=20
        Step 3 : If step 1 and step 2 are true take long position.

        Code:
        #region Inputs
                private bool FirstGAP = false;
                private int _cntrcts = 1;
                private TimeSpan _StartTime = new TimeSpan(8, 31, 0);
                private TimeSpan _ExTime = new TimeSpan(15, 14, 0);
                private double _StpLs = 200;
                private double _PrfTg = 200;
                #endregion
         
                protected override void OnBarUpdate()
                {
                    if (Bars.BarsSinceSession >=40)
                    if (!FirstGAP && Time[0].TimeOfDay == _StartTime && Close[0]>Bars.GetDayBar(1).Close + 20 * TickSize)
                        {
         
                        if (Stochastics(7, 14, 3).D[0] >=20)
         
                        EnterLong(DefaultQuantity, "");
                        }
        What is the error in your log?

        You need to do a null check for GetDayBar().

        Comment


          #5
          The log tap gives me no errors. Second how do I do a null check for GetDayBar().????

          Comment


            #6
            Hello wallsteetking,

            Code:
            if (Bars.GetDayBar(1) == null)
            {
                 Print("GetDayBar() is null");
            }
            else
            {
                 Print("GetDayBar for the Close is: "+Bars.GetDayBar(1).Close);
            }
            You may also view our Help Guide at the following link for another reference.
            JCNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by funk10101, Today, 12:02 AM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by GLFX005, Today, 03:23 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by nandhumca, Yesterday, 03:41 PM
            1 response
            13 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by The_Sec, Yesterday, 03:37 PM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by vecnopus, Today, 06:15 AM
            0 responses
            1 view
            0 likes
            Last Post vecnopus  
            Working...
            X