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

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;
        BertrandNinjaTrader Customer Service

        Comment


          #5
          thx a mill it is working...

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by helpwanted, Today, 03:06 AM
          1 response
          7 views
          0 likes
          Last Post sarafuenonly123  
          Started by Brevo, Today, 01:45 AM
          0 responses
          7 views
          0 likes
          Last Post Brevo
          by Brevo
           
          Started by aussugardefender, Today, 01:07 AM
          0 responses
          5 views
          0 likes
          Last Post aussugardefender  
          Started by pvincent, 06-23-2022, 12:53 PM
          14 responses
          242 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Started by TraderG23, 12-08-2023, 07:56 AM
          9 responses
          385 views
          1 like
          Last Post Gavini
          by Gavini
           
          Working...
          X