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

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 funk10101, Today, 09:43 PM
                0 responses
                6 views
                0 likes
                Last Post funk10101  
                Started by pkefal, 04-11-2024, 07:39 AM
                11 responses
                37 views
                0 likes
                Last Post jeronymite  
                Started by bill2023, Yesterday, 08:51 AM
                8 responses
                44 views
                0 likes
                Last Post bill2023  
                Started by yertle, Today, 08:38 AM
                6 responses
                26 views
                0 likes
                Last Post ryjoga
                by ryjoga
                 
                Started by algospoke, Yesterday, 06:40 PM
                2 responses
                24 views
                0 likes
                Last Post algospoke  
                Working...
                X