Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entry restriction

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

    Entry restriction

    HI guys i would appreciate if get a bit of help ..

    I want to restrict my startegy to have only 1 long and 1 short trade per session . my session is time between 10 and 2 pm.

    can i program this on strat analyzer ?

    #2
    amit_rwd,

    As you place in a long trade, set a bool variable to true that prevents future long trades. Do this for shorts as well. When a new session starts, reset the bool to false.

    Untested pseudo-code to give you an idea.
    Code:
    if (Bars.FirstBarOfSession && FirstTickOfBar)
    {
         longTrade = false;
         shortTrade = false;
    }
    
    if (longTrade == false && some other entry conditions)
    {
         EnterLong();
         longTrade = true;
    }
    
    if (shortTrade == false && some entry conditions)
    {
         EnterShort();
         shortTrade = true;
    }
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      cheers Josh

      seems i have got somethings wrong here is what i wrote
      How do i need to declare longtrade in variable section ? so script can recognise longtrade function

      protected override void OnBarUpdate()
      {

      if (Bars.FirstBarOfSession && FirstTickOfBar)
      {
      longTrade = false;
      shortTrade = false;
      } // Condition set 1
      if (ToTime(Time[0]) == ToTime(10, 0, 0))
      {
      Variable0 = MAX(8)[0];
      Variable1 = MIN(8)[0];
      }

      // Condition set 2
      if (longTrade == false && ToTime(Time[0]) >= ToTime(10, 0, 0)
      && ToTime(Time[0]) <= ToTime(14, 0, 0)
      && Close[0] >= Variable0

      {
      EnterLong(DefaultQuantity, "");
      longTrade = true;
      }

      Comment


        #4
        amit_rwd, you would need to add to your Variables section -

        Code:
         
        private bool longTrade;
        private bool shortTrade;

        Comment


          #5
          thx a mill it is working...

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          626 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          359 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          105 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          562 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          567 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X