Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trade Time Filter

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

    Trade Time Filter

    Can you please tell me why this time filter has no affect in limiting the trade time of this script? I am creating this code from the wizard.
    protectedoverridevoid OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(EMA(7), EMA(20), 1)
    && Variable0 ==
    1)
    {
    EnterLong(DefaultQuantity,
    "BuyMarket");
    }
    // Condition set 2
    if (CrossBelow(EMA(7), EMA(20), 1)
    && Variable0 ==
    1)
    {
    EnterShort(DefaultQuantity,
    "SellMarket");
    }
    // Condition set 3
    if (ToTime(Time[0]) > ToTime(10, 0, 0)
    && ToTime(Time[
    0]) < ToTime(15, 30, 0))
    {
    Variable0 =
    1;
    }
    }

    #2
    kenb2004,

    Because once you have set Variable0 to equal to 1 it will always be equal to 1. What you need to do is add an additional condition set that determines when you would set Variable0 to equal to 0 or something not 1.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      OK, so I added an additional Condition and my results were the same what am I doing wrong? It's still trading 24 hrs a day.
      protected override void OnBarUpdate()
      {
      // Condition set 1
      if (CrossAbove(EMA(7), EMA(20), 1)
      && Variable0 == 1)
      {
      EnterLong(DefaultQuantity, "BuyMarket");
      }
      // Condition set 2
      if (CrossBelow(EMA(7), EMA(20), 1)
      && Variable0 == 1)
      {
      EnterShort(DefaultQuantity, "SellMarket");
      }
      // Condition set 3
      if (ToTime(Time[0]) > ToTime(10, 0, 0)
      && ToTime(Time[0]) < ToTime(15, 30, 0))
      {
      Variable0 = 1;
      }
      // Condition set 4
      if (ToTime(Time[0]) < ToTime(9, 59, 0)
      && ToTime(Time[0]) > ToTime(15, 31, 0))
      {
      Variable0 = 0;
      }
      }

      Comment


        #4
        kenb2004,

        The condition you added is incorrect. Time would never be < 9:59AM and greater than 3:31PM at the same time. You need to set these ranges separately.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I'm not sure I understand. Evidently a range is not even required to set Var0=1. I set it "if time is greater than 10am var0=1 and time is greater than 3:31pm var0=0 and it worked. Is this the correct way to establish a time trading range?
          Last edited by kenb2004; 09-19-2010, 07:33 AM.

          Comment


            #6
            kenb2004,

            You have already set a range for when Variable0 will be set to 1. Once it is set to 1 once it will always be the value of 1 until you set it differently regardless of if you are still in that time range or not. Basically you need to setup 3 different time ranges.

            1. Some time range prior to when you want to trade
            2. Time range you want to trade
            3. Time range after you don't want to trade anymore.

            #1 and #3 should set Variable0 = 0
            #2 should set Variable0 = 1
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              kenb2004

              You could do it this way:

              protected override void OnBarUpdate()
              {
              // Condition set 1
              if (CrossAbove(EMA(7), EMA(20), 1)
              && ToTime(Time[0]) > ToTime(10, 0, 0)
              && ToTime(Time[0]) < ToTime(15, 30, 0))
              {
              EnterLong(DefaultQuantity, "BuyMarket");
              }

              // Condition set 2
              if (CrossBelow(EMA(7), EMA(20), 1)
              && ToTime(Time[0]) > ToTime(10, 0, 0)
              && ToTime(Time[0]) < ToTime(15, 30, 0))
              {
              EnterShort(DefaultQuantity, "SellMarket");
              }
              }

              This way, you wouldn't have to set any variables.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              649 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              370 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              109 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              574 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              576 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X