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

Simple Time math

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

    Simple Time math

    I've looked at the "SampleTimeFilter" strategy and need help modifying it with some simple time math. The sample code allows me to make the opposite condition, when to NOT trade, for example around the market open, or news events. If I have the following code:
    Code:
     
    [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ( ToTime(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]) > [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]65000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] && ToTime(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]) < [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]71000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] )[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]bTimeToPause = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT][/SIZE][/FONT]
    how would I change it to use a parameter offset around 8:30, or 7:00? I can't just use something like:
    Code:
     
    nTimeStart = 70000 - Pause_Time_Buffer * 100;
    because that would yeild 69500 when Pause_Time_Buffer = 5 mins.

    There has to be some simple time math I just can't find anywhere. I'd like my code to be more like:
    Code:
    [SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New]xTimeStart = [/FONT][/SIZE][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]70000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]xTimeStart.SubtractMinutes( Pause_Time_Buffer );[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]xTimeEnd = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]70000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]xTimeEnd.AddMinutes( Pause_Time_Buffer );[/FONT][/SIZE]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ( ToTime(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]) > xTimeStart && ToTime(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]) < xTimeEnd )[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]bTimeToPause = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
    [/SIZE][/FONT]
    So what type should I use for xTimeStart and xTimeEnd?

    #2
    Originally posted by TiggerTrader View Post
    I've looked at the "SampleTimeFilter" strategy and need help modifying it with some simple time math. The sample code allows me to make the opposite condition, when to NOT trade, for example around the market open, or news events. If I have the following code:
    Code:
     
    [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ( ToTime(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]) > [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]65000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] && ToTime(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]) < [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]71000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] )[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]bTimeToPause = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT][/SIZE][/FONT]
    how would I change it to use a parameter offset around 8:30, or 7:00? I can't just use something like:
    Code:
     
    nTimeStart = 70000 - Pause_Time_Buffer * 100;
    because that would yeild 69500 when Pause_Time_Buffer = 5 mins.

    There has to be some simple time math I just can't find anywhere. I'd like my code to be more like:
    Code:
    [SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New]xTimeStart = [/FONT][/SIZE][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]70000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]xTimeStart.SubtractMinutes( Pause_Time_Buffer );[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]xTimeEnd = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]70000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]xTimeEnd.AddMinutes( Pause_Time_Buffer );[/FONT][/SIZE]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ( ToTime(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]) > xTimeStart && ToTime(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]) < xTimeEnd )[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]bTimeToPause = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
    [/SIZE][/FONT]
    So what type should I use for xTimeStart and xTimeEnd?
    If you want to use the syntax that you have described, then you should be using the standard C# DateTime objects and methods, not the NT data-massage methods.

    ref: https://www.google.com/search?q=%2Bd...w=1293&bih=876

    Comment


      #3
      Yeah, that's what I thought, but ick! Doesn't really lend itself to my topic of "Simple Time math"

      I would need to construct a DateTime variable and somehow miraculusly set it to 7AM today. Not straightforward as far as I can tell, then do math on that...

      Really was hoping there was a simpler way. Even a constructor of DateTime dtTest = new DateTime( 700 AM ); or something.

      Comment


        #4
        Originally posted by TiggerTrader View Post
        Yeah, that's what I thought, but ick! Doesn't really lend itself to my topic of "Simple Time math"

        I would need to construct a DateTime variable and somehow miraculusly set it to 7AM today. Not straightforward as far as I can tell, then do math on that...

        Really was hoping there was a simpler way. Even a constructor of DateTime dtTest = new DateTime( 700 AM ); or something.
        TiggerTrader: Check out SH_Dagget's code. It takes time as inputs.. which is what you are looking for?


        Comment


          #5
          Thanks, but its not quite.

          I want to do MATH on the times. His code points me to using TimeSpans, but Time[0] is a DateTime, so let the conversions ensue...

          Just wish there was an easy way...

          Comment


            #6
            Originally posted by TiggerTrader View Post
            Thanks, but its not quite.

            I want to do MATH on the times. His code points me to using TimeSpans, but Time[0] is a DateTime, so let the conversions ensue...

            Just wish there was an easy way...
            I reused some of his code, and this work. (0005 is 5 minutes)


            if ( Time[0].TimeOfDay >= openTimeTS
            && Time[0].TimeOfDay < openTimeTS + convertTimeSetting("0005")
            {

            Comment


              #7
              Thanks for your reply but adding 30 lines of code to do what should happen in 3 is not what I was hoping for.

              Comment


                #8
                Originally posted by TiggerTrader View Post
                Thanks for your reply but adding 30 lines of code to do what should happen in 3 is not what I was hoping for.
                Code:
                private DateTime xTimeInit;
                private DateTime xTimeStart;
                private DateTime xTimeEnd;
                [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]private bool[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] bTimeToPause = [/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]false[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New];[/FONT]
                [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]private double[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] Pause_Time_Buffer = [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]10.0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New];[/FONT]
                Code:
                [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] (Time[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]].Date != Time[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]1[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]].Date) [/FONT]
                [FONT=Courier New]{[/FONT]
                [FONT=Courier New]xTimeInit = Time[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]].Add([/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]new[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] TimeSpan([/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]7[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New], [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]00[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New], [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]00[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]));[/FONT]
                [FONT=Courier New]xTimeStart = xTimeInit.AddMinutes([/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] - Pause_Time_Buffer ); [/FONT]
                [FONT=Courier New]xTimeEnd = xTimeInit.AddMinutes( Pause_Time_Buffer );[/FONT]
                [FONT=Courier New]}[/FONT]
                [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] ( Time[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]] > xTimeStart && Time[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]] < xTimeEnd ) [/FONT][FONT=Courier New]bTimeToPause = [/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]true[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New];[/FONT]
                Last edited by koganam; 01-06-2013, 03:02 PM.

                Comment


                  #9
                  Wouldn't that be nice if that would work? Aren't we just adding 7 hours to the date & time of bar 0? I'm looking for 7:00. I run this on a range bar chart, so the cross over of the day would happen at random times.

                  Comment


                    #10
                    Originally posted by TiggerTrader View Post
                    Wouldn't that be nice if that would work? Aren't we just adding 7 hours to the date & time of bar 0? I'm looking for 7:00. I run this on a range bar chart, so the cross over of the day would happen at random times.
                    Yes, and no.

                    The code says (I added annotations):
                    Code:
                    [COLOR=#0000ff]if[/COLOR][FONT=Courier New] (Time[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]].Date != Time[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]1[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]].Date) [/FONT][FONT=Arial]//when and only when the last bar's date is not the same as this bar's date. IOW, when a new day starts, then and only then, set the start and end times to today's times. (Your code was the one that specified 7AM: I just used it).[/FONT]
                    [FONT=Courier New]{[/FONT]
                    [FONT=Courier New]xTimeInit = Time[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]].Add([/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]new[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] TimeSpan([/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]7[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New], [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]00[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New], [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]00[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]));[/FONT]
                    [FONT=Courier New]xTimeStart = xTimeInit.AddMinutes([/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] - Pause_Time_Buffer ); [/FONT]
                    [FONT=Courier New]xTimeEnd = xTimeInit.AddMinutes( Pause_Time_Buffer );[/FONT]
                    [FONT=Courier New]}[/FONT]
                    IOW, that code runs ONLY once a day, and sets the begin and end times, whenever the bars say that we have crossed the day boundary, regardless of what type of bars, as it is only time dependent. Have you even run the code to see if it does what you requested?

                    Regardless you also have to decide when to make bTimeToPause = false;. As your code never mentioned it, I do not know when you want so to do.

                    Sarcasm can be cute, but you might want to discard it when you ask for help, even if you think the help is useless.
                    Last edited by koganam; 01-06-2013, 05:15 PM.

                    Comment


                      #11
                      After re-reading my post, I can see how sarcasm came thru. Believe me, it was not my intention. I guesss I am more frustrated with myself as this isn't clicking yet. I've spent 20 years as a software developer, my last 10 years doing C++. This should be a breeze for me, but WOW am I rusty!

                      I sincerely apologize if I've hurt your feelings even a twinge, and sincerely thank you for sticking with me thru this.

                      OK, so I got the code to work, thank you again, but I still don't get it. What is
                      Code:
                      xTimeInit = Time[[FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]].Add([/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]new[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] TimeSpan([/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]7[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New], [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]00[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New], [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]00[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]));[/FONT]
                      doing? It looks like:
                      Time[0] is the date & time of the current bar.
                      Add says that it Adds the TimeSpan to the current structure, which I interpret as adding 7 hours to this bar's actual date & time. So the bar when we cross from one day to the next may have closed at midnight & 3 minutes & 30 seconds. So what is happening is that the "Pauses" occurs around 7:03:30, not 7AM. This would work on a minute bar because the first minute would be 12:00 AM.

                      But again, thanks for the help.

                      Remember, I was just hoping this would be easy, so far it has been well over 5 hours of work

                      Let me summizire what I was hoping the steps would be:
                      1. be able to set a variable to 7AM
                      2. be able to add & subtact an amount of time to make other variables (the buffer zone)
                      3. compare this bar's time to the buffer zone

                      So far, I can't do step 1.

                      Comment


                        #12
                        P.S. I tried this to get 8:30, but it failed to work:
                        Code:
                        [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]
                        dtNYSETimeInit = Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]].Subtract([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] TimeSpan(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]].Hour, Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]].Minute, Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]].Second));
                        dtNYSETimeInit.Add([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] TimeSpan([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]8[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]30[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]00[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]));
                        [/SIZE][/FONT][/SIZE][/FONT]

                        Comment


                          #13
                          Originally posted by TiggerTrader View Post
                          After re-reading my post, I can see how sarcasm came thru. Believe me, it was not my intention. I guesss I am more frustrated with myself as this isn't clicking yet. I've spent 20 years as a software developer, my last 10 years doing C++. This should be a breeze for me, but WOW am I rusty!

                          I sincerely apologize if I've hurt your feelings even a twinge, and sincerely thank you for sticking with me thru this.

                          OK, so I got the code to work, thank you again, but I still don't get it. What is
                          Code:
                          xTimeInit = Time[[FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]].Add([/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]new[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] TimeSpan([/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]7[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New], [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]00[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New], [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]00[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]));[/FONT]
                          doing? It looks like:
                          Time[0] is the date & time of the current bar.
                          Add says that it Adds the TimeSpan to the current structure, which I interpret as adding 7 hours to this bar's actual date & time. So the bar when we cross from one day to the next may have closed at midnight & 3 minutes & 30 seconds. So what is happening is that the "Pauses" occurs around 7:03:30, not 7AM. This would work on a minute bar because the first minute would be 12:00 AM.

                          But again, thanks for the help.

                          Remember, I was just hoping this would be easy, so far it has been well over 5 hours of work

                          Let me summizire what I was hoping the steps would be:
                          1. be able to set a variable to 7AM
                          2. be able to add & subtact an amount of time to make other variables (the buffer zone)
                          3. compare this bar's time to the buffer zone

                          So far, I can't do step 1.
                          Actually you are right. I left out one little detail in there. That line should read:

                          Code:
                          xTimeInit = Time[[FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]].[SIZE=3][COLOR=red][B]Date.[/B][/COLOR][/SIZE]Add([/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]new[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] TimeSpan([/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]7[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New], [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]00[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New], [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]00[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]));[/FONT]
                          That centers the time at midnight, before the arithmetic. Oops.

                          Don't worry too much about the sarcasm comment: I know that it is sometimes hard to convey the real intent when writing, as opposed to when speaking. Hence, my rather liberal use of smiley's to show jocularity, if I think what I write may sound sarcastic, and that is not my real intent.

                          Comment


                            #14
                            Thanks! That was it. Now it makes perfect sense. I'll get the hang of it eventually.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by yertle, Today, 08:38 AM
                            4 responses
                            10 views
                            0 likes
                            Last Post yertle
                            by yertle
                             
                            Started by bill2023, Yesterday, 08:51 AM
                            6 responses
                            27 views
                            0 likes
                            Last Post NinjaTrader_Erick  
                            Started by NinjaTrader_ChelseaB, 01-08-2017, 06:59 PM
                            80 responses
                            19,667 views
                            5 likes
                            Last Post NinjaTrader_ChelseaB  
                            Started by adeelshahzad, Today, 03:54 AM
                            2 responses
                            16 views
                            0 likes
                            Last Post adeelshahzad  
                            Started by dappa, Today, 09:18 AM
                            1 response
                            6 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Working...
                            X