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

what is the best way to set strategy start/end time?

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

    what is the best way to set strategy start/end time?

    Hi guys,

    I'm trying to set trading start/end time, I thought it is simple but it seems much harder than I thought.

    The main difficulty is to get the HHMM string converted into a proper timespan format. Could you advise?

    Code:
            private string startTradingTime = "0931"; // Default setting for startTradingTime
            private string endTradingTime = "1100"; // Default setting for endTradingTime

    Code:
    if (Time[0].TimeOfDay<DateTime.ParseExact(startTradingTime,"HHMM",System.Globalization.CultureInfo.InvariantCulture).TimeOfDay
                    && Time[0].TimeOfDay>DateTime.ParseExact(endTradingTime,"HHMM",System.Globalization.CultureInfo.InvariantCulture).TimeOfDay
                    && Position.MarketPosition == MarketPosition.Flat) return;

    #2
    Originally posted by leontancfa View Post
    Hi guys,

    I'm trying to set trading start/end time, I thought it is simple but it seems much harder than I thought.

    The main difficulty is to get the HHMM string converted into a proper timespan format. Could you advise?

    Code:
            private string startTradingTime = "0931"; // Default setting for startTradingTime
            private string endTradingTime = "1100"; // Default setting for endTradingTime

    Code:
    if (Time[0].TimeOfDay<DateTime.ParseExact(startTradingTime,"HHMM",System.Globalization.CultureInfo.InvariantCulture).TimeOfDay
                    && Time[0].TimeOfDay>DateTime.ParseExact(endTradingTime,"HHMM",System.Globalization.CultureInfo.InvariantCulture).TimeOfDay
                    && Position.MarketPosition == MarketPosition.Flat) return;
    This does the job for me:

    Code:
    private [B]int[/B] startTradingTime = 81500
    private [B]int[/B] endTradingTime = 223000;
    
    ...
    
    if(
    ToTime(Time[0]) >=startTradingTime
    && ToTime(Time[0]) <= endTradingTime
    [I]&& other conditions[/I]
    )
    "Integer representation of time is in the following format Hmmss where 7:30 AM would be 73000 and 2:15:12 PM would be 141512."
    Last edited by arbuthnot; 07-12-2015, 09:25 AM.

    Comment


      #3
      Code:
      if (   ToTime(Time[0]) >= ToTime( 09, 30, 00)
      	&& ToTime(Time[0]) <= ToTime( 16, 00, 10) ) 
      {

      Comment


        #4
        Thank you Arbuthnot, that does it for me also.

        Comment


          #5
          Originally posted by sledge View Post
          Code:
          if (   ToTime(Time[0]) >= ToTime( 09, 30, 00)
          	&& ToTime(Time[0]) <= ToTime( 16, 00, 10) ) 
          {
          Thanks, sledge, for showing another solution.

          Comment


            #6
            How to apply start and end time?

            if ( ToTime(Time[0]) >= ToTime( 09, 30, 00)
            && ToTime(Time[0]) <= ToTime( 16, 00, 10) )
            {

            How to add the start and end time to
            the NinjaTrader Standard Indicator ( Volume Profile )

            Please Help

            Comment


              #7
              I know nothing about Volume Profile but I do know a tiny bit about code!

              What you need to do is to open the Volume Profile indicator (Tools -> Edit NinjaScript) then right click -> 'Save As...' and rename it as you wish.

              Then change the conditions as follows:

              Code:
              if (
              startBarIndex > 0
              && startBarIndex == CurrentBar
              && ToTime(Time[0]) >= ToTime( 09, 30, 00)
              && ToTime(Time[0]) <= ToTime( 16, 00, 10)
              )
              
              DrawDiamond("Start Tag", false, 0, High[0] + TickSize, Color.Turquoise); // unchanged
              You can, of course, change the times as you wish. You can set variables to make the hours, etc, changeable when the indicator is applied.

              Comment


                #8
                Originally posted by eMaxTeo View Post
                if ( ToTime(Time[0]) >= ToTime( 09, 30, 00)
                && ToTime(Time[0]) <= ToTime( 16, 00, 10) )
                {

                How to add the start and end time to
                the NinjaTrader Standard Indicator ( Volume Profile )

                Please Help
                That Volume Profile indicator can only run in live market, and cannot back track. Say if you open the indicator at 10:43, it does not back track the volume back from 9:30 to 10:43. It will only show you volume profile at the point that you open the indicator.

                Comment


                  #9
                  Hi, arbuthnot

                  I had follow your instruction
                  But it did not follow start and end time??
                  It straight away start at the point that I open the indicator?

                  Please Help.

                  Comment


                    #10
                    Originally posted by eMaxTeo View Post
                    Hi, arbuthnot

                    I had follow your instruction
                    But it did not follow start and end time??
                    It straight away start at the point that I open the indicator?

                    Please Help.
                    As I said, I know nothing about this indicator, but leontancfa obviously does. Please read his post #8.

                    This code (which works) will work with a normal indicator but this isn't one of them!

                    Comment


                      #11
                      Originally posted by leontancfa View Post
                      That Volume Profile indicator can only run in live market, and cannot back track. Say if you open the indicator at 10:43, it does not back track the volume back from 9:30 to 10:43. It will only show you volume profile at the point that you open the indicator.
                      Hi, Leontancfa

                      Volume Profile indicator can only run in live market.
                      Set : start 9.30 end 1600;

                      Say if you open the indicator at 10:43.
                      since it cannot back track,
                      I am ok if run from 10.43 to 1600.

                      Say if you open the indicator at 8:43.
                      It should wait till 930 than start and end 1600.

                      Please Help

                      Comment


                        #12
                        Originally posted by eMaxTeo View Post
                        Hi, arbuthnot

                        I had follow your instruction
                        Exactly how did you follow this instruction? What did you do? Did you try to edit the actual standard NT indicator? Did you edit a copy of it?
                        But it did not follow start and end time??
                        It straight away start at the point that I open the indicator?

                        Please Help.

                        Comment


                          #13
                          Hello,

                          Say if you open the indicator at 8:43.
                          It should wait till 930 than start and end 1600.
                          The volume Profile profile indicator that comes with NinjaTrader would only include the features you see in it, anything additional you would have to create a copy of the original and modify the copy.

                          Also this indicator only works in real time and does not work historically,if you add it to the chart it would start from that point as was said in post #8

                          If you needed the indicator to only start working at a certain point in time, there would be two options. The first is to add the indicator to the chart at that time which would be difficult if you have more than one chart. The second is to use a time filter which has been shown in a few prior posts.

                          If you need the indicator to do absolutely nothing before a certain time you could use a statement like the following to prevent the scripts logic:

                          Code:
                          if (ToTime(Time[0]) < ToTime( 09, 30, 00) || ToTime(Time[0]) > ToTime( 16, 00, 10)) return;
                          This statement would check if the current Time is less than 9:30 or is greater than 1600, if it is outside of the window "return" is used to stop the processing at that point.

                          In the indicator, you would need to place this statement in the top of OnBarUpdate and also in OnMarketData and in the Plot override to prevent everything from happening until that time.

                          Here are examples of each:

                          Code:
                          protected override void OnBarUpdate()
                          {
                          	if (ToTime(Time[0]) < ToTime( 09, 30, 00) || ToTime(Time[0]) > ToTime( 16, 00, 10)) return;
                          }
                                   
                          
                          protected override void OnMarketData(MarketDataEventArgs e)
                          {
                          	if (ToTime(Time[0]) < ToTime( 09, 30, 00) || ToTime(Time[0]) > ToTime( 16, 00, 10)) return;
                          }
                                  
                          public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
                          {
                          	if (ToTime(Time[0]) < ToTime( 09, 30, 00) || ToTime(Time[0]) > ToTime( 16, 00, 10)) return;
                          }

                          Please let me know if I may be of additional assistance.
                          JesseNinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by koganam View Post
                            Exactly how did you follow this instruction? What did you do? Did you try to edit the actual standard NT indicator? Did you edit a copy of it?
                            Yes.
                            I had follow the instruction.
                            But
                            It straight away start at the point that I open the indicator.

                            Comment


                              #15
                              Originally posted by eMaxTeo View Post
                              Yes.
                              I had follow the instruction.
                              But
                              It straight away start at the point that I open the indicator.
                              You did not answer my questions.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by StockTrader88, 03-06-2021, 08:58 AM
                              45 responses
                              3,992 views
                              3 likes
                              Last Post johntraderuser2  
                              Started by TAJTrades, Today, 09:46 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post TAJTrades  
                              Started by rhyminkevin, Yesterday, 04:58 PM
                              5 responses
                              62 views
                              0 likes
                              Last Post dp8282
                              by dp8282
                               
                              Started by realblubb, Today, 09:28 AM
                              0 responses
                              8 views
                              0 likes
                              Last Post realblubb  
                              Started by AaronKoRn, Yesterday, 09:49 PM
                              1 response
                              19 views
                              0 likes
                              Last Post Rikazkhan007  
                              Working...
                              X