Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ToTime

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

    ToTime

    I have a condtion for long entry of...

    (ToTime(Time[0]) >= 93500 && ToTime(Time[0]) < 133000))

    This is 9:35am to 1:30pm unless I'm mistaken. But when I look at the backtest charts it's entering trades at 3:30pm for instance?

    #2
    Hello zachj,

    Is that your full condition before entering a trade?

    Happy to be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Have these defined variables...
      private int timestart = 93500;
      private int timeend = 133000;

      if (BarsInProgress == 1)
      if (SMA(BarsArray[0],Fast)[2] > SMA(BarsArray[0],Slow)[2] && SMA(BarsArray[0],Fast)[3] < SMA(BarsArray[0],Slow)[3] && Close[0] > Highs[0][2] +.10
      || SMA(BarsArray[0],Fast)[3] > SMA(BarsArray[0],Slow)[3] && SMA(BarsArray[0],Fast)[4] < SMA(BarsArray[0],Slow)[4] && Close[0] > Highs[0][3] +.10
      && (ToTime(Time[0]) >= timestart && ToTime(Time[0]) < timeend))

      {
      EnterLong(200, "");
      }

      Update: Oh I think I may see. I would have to have the time condition on both of the OR ELSE statements, right now it's only on the second of the OR statements. That's it I think right? Is there a way to put the time condition in just once instead of having for both statements? I thnk I just put another if statement outside of the first one?
      Last edited by zachj; 06-14-2013, 02:26 PM.

      Comment


        #4
        Hello zachj,

        Yes, exactly that would work by putting an if statement inside of another if statement to help keep your time condition true.
        JCNinjaTrader Customer Service

        Comment


          #5
          Will this work, or do I have to somehow get the time if statement within the first if statement?....

          if (BarsInProgress == 1)
          if (SMA(BarsArray[0],Fast)[2] > SMA(BarsArray[0],Slow)[2] && SMA(BarsArray[0],Fast)[3] < SMA(BarsArray[0],Slow)[3] && Close[0] > Highs[0][2] +.10
          || SMA(BarsArray[0],Fast)[3] > SMA(BarsArray[0],Slow)[3] && SMA(BarsArray[0],Fast)[4] < SMA(BarsArray[0],Slow)[4] && Close[0] > Highs[0][3] +.10)
          if (ToTime(Time[0]) >= timestart && ToTime(Time[0]) < timeend)

          {
          EnterLong(200, "");
          }

          Comment


            #6
            Hello zachj,

            Thank you for your response.

            Are you only checking these conditions on the first bar?
            Code:
            if (BarsInProgress == 1)
            The following will work as long as the if condition for the time is the first if or included in the braces of the SMA conditions:
            Code:
            if (SMA(BarsArray[0],Fast)[2] > SMA(BarsArray[0],Slow)[2]	&& SMA(BarsArray[0],Fast)[3] < SMA(BarsArray[0],Slow)[3] && Close[0] > Highs[0][2] +.10 
            || SMA(BarsArray[0],Fast)[3] > SMA(BarsArray[0],Slow)[3]	&& SMA(BarsArray[0],Fast)[4] < SMA(BarsArray[0],Slow)[4] && Close[0] > Highs[0][3] +.10)
            {
            if (ToTime(Time[0]) >= timestart && ToTime(Time[0]) < timeend) 
            
            {
            EnterLong(200, "");
            }
            }
            Or:
            Code:
            if (ToTime(Time[0]) >= timestart && ToTime(Time[0]) < timeend) 
            
            {
            if (SMA(BarsArray[0],Fast)[2] > SMA(BarsArray[0],Slow)[2]	&& SMA(BarsArray[0],Fast)[3] < SMA(BarsArray[0],Slow)[3] && Close[0] > Highs[0][2] +.10 
            || SMA(BarsArray[0],Fast)[3] > SMA(BarsArray[0],Slow)[3]	&& SMA(BarsArray[0],Fast)[4] < SMA(BarsArray[0],Slow)[4] && Close[0] > Highs[0][3] +.10)
            {
            EnterLong(200, "");
            }
            }
            Please let me know if you have any questions.

            Comment


              #7
              For BIP==1, all the SMA info and the High is in regards to the primary series, the Close[0] statement is the only part using the added secondary series.

              Does this work then?...
              Code:
              if (BarsInProgress == 1) //OnBarUpdate called for 1min bars
              if (ToTime(Time[0]) >= timestart && ToTime(Time[0]) < timeend)
              if (SMA(BarsArray[0],Fast)[2] > SMA(BarsArray[0],Slow)[2]	&& SMA(BarsArray[0],Fast)[3] < SMA(BarsArray[0],Slow)[3] && Close[0] > Highs[0][2] +.10 
              || SMA(BarsArray[0],Fast)[3] > SMA(BarsArray[0],Slow)[3]	&& SMA(BarsArray[0],Fast)[4] < SMA(BarsArray[0],Slow)[4] && Close[0] > Highs[0][3] +.10) 
              {
              EnterLong(200, "");
              }

              Comment


                #8
                Hello zachj,

                Thank you for your update.

                That is correct, the conditions will then only calculate on BIP 1.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                579 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                334 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                101 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                554 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                551 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X