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

30 minutes pause on range bar chart

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

    30 minutes pause on range bar chart

    Hello,

    How can I do it on a range bar chart to stop re-engaging for 30 minutes after a closed position?

    Thanks

    #2
    Hello Benjee,

    Thank you for your note.

    Upon the close of a trade you could set the time to a datetime variable plus 30 minutes, for example

    Code:
    DateTime tradeClosedTime =Time[0].AddMinutes(30);
    In your entries if statement, you would want to check that the datetime variable was not null (meaning it has been set) and that the current time is greater than our datetime variable,

    Code:
    if(tradeClosedTime != null && (ToTime(Time[0]) >= tradeClosedTime ))
    The following sample uses a time filter which demonstrates the use of ToTime,


    The following sample demonstrates how you could check if the position is closed as well as an example of how to halt a strategy from processing,


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

    Comment


      #3
      Hello,

      Thanks for your help.

      I did the code, but something is wrong.
      Compile error CS0135 "tradeClosedTime" conflicts with the declaration

      Code:
              #region Variables
              	private int tradeClosedTime = 0;
      		private bool exitSubmit = false;
      	#endregion
      
              protected override void OnBarUpdate()
              {
      			
      			// After position is closed set tradeClosedtime and reset bool 
      			if (Position.MarketPosition == MarketPosition.Flat && exitSubmit)
      			{
      				DateTime tradeClosedTime = Time[0].AddMinutes(30);
      				exitSubmit = false;
      			}
      
      
      				
      		         if ( tradeClosedTime != 0 && ToTime(Time[0]) >= tradeClosedTime)) 
                  {
                      EnterLongLimit(0, false, DefaultQuantity, Close[0] + 2 * TickSize, "SB");
      				buyFlag = false;
      				exitSubmit = true;
                  }
      what's the problem?

      Comment


        #4
        Hello Benjee,

        Thank you for your note.

        You declare tradeClosedTime as a type int, but then declare it as a date time object.

        You could try removing,

        Code:
        private int tradeClosedTime = 0;
        Please let us know if you need further assistance.
        Attached Files
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Hello AlanP,

          thanks for your efforts, but I dont understand

          If I dont declare int, it can not be interpreted my entries if statement. CS0103 error.
          How do I give it then?

          Comment


            #6
            Hello,

            Thank you for the reply.

            After you have declared tradeClosedTime as a DateTime object, you can use that object for comparison against other DateTime objects:

            Code:
            Time[0] >= tradeClosedTime
            Alternatively, if you need the minutes part of the object as an int, you can use the dot operator to get the Minutes:

            int minute = tradeClosedTime.Minute;

            Please see this publicly available link to the documentation on the DateTime structure:

            Represents an instant in time, typically expressed as a date and time of day.


            Please let us know if we may be of any further assistance.
            Last edited by NinjaTrader_ChrisL; 02-05-2018, 07:41 AM. Reason: Keep Time[0] a DateTime object.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_AlanP View Post
              Hello Benjee,

              Thank you for your note.

              Upon the close of a trade you could set the time to a datetime variable plus 30 minutes, for example

              Code:
              DateTime tradeClosedTime =Time[0].AddMinutes(30);
              In your entries if statement, you would want to check that the datetime variable was not null (meaning it has been set) and that the current time is greater than our datetime variable,

              Code:
              if(tradeClosedTime != null && (ToTime(Time[0]) >= tradeClosedTime ))
              The following sample uses a time filter which demonstrates the use of ToTime,


              The following sample demonstrates how you could check if the position is closed as well as an example of how to halt a strategy from processing,


              Please let us know if you need further assistance.
              Your code is defective. You cannot compare an int to a DateTime object.

              Correct is:
              Code:
              if (tradeClosedTime != null && (Time[0] >= tradeClosedTime )){//... }
              comparing two DateTime objects. :-)
              Last edited by koganam; 02-02-2018, 10:00 PM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by DJ888, 04-16-2024, 06:09 PM
              6 responses
              18 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by Jon17, Today, 04:33 PM
              0 responses
              1 view
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              6 views
              0 likes
              Last Post Javierw.ok  
              Started by timmbbo, Today, 08:59 AM
              2 responses
              10 views
              0 likes
              Last Post bltdavid  
              Started by alifarahani, Today, 09:40 AM
              6 responses
              41 views
              0 likes
              Last Post alifarahani  
              Working...
              X