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

One Trade Per Direction Problem

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

    #16
    m3power222,

    You can create a user variable of type bool in the User Defined Inputs page. Then in the Condition Builder you can set it to true or false as you deem necessary. Then as it comes to a new trading day you can reset that bool variable to whatever state you need it to be.

    Unfortunately we do not have sample code.
    Josh P.NinjaTrader Customer Service

    Comment


      #17
      Originally posted by NinjaTrader_Josh View Post
      m3power222,

      You can create a user variable of type bool in the User Defined Inputs page. Then in the Condition Builder you can set it to true or false as you deem necessary. Then as it comes to a new trading day you can reset that bool variable to whatever state you need it to be.

      Unfortunately we do not have sample code.

      This seems like a common answer to a lot of questions using a bool flag. Why isn't there samples?

      Comment


        #18
        This is a very basic programming concept and you can find code snippets throughout the forums demonstrating it. There is no "sample" because the concept is generally specifically tailored to a particular cases.

        You can also find many resources on this on google too.
        Josh P.NinjaTrader Customer Service

        Comment


          #19
          Sooooo close!!!!! I added:

          #region Variables
          private bool boolFlag = true;

          if (condition long
          && boolFlag == true)
          {
          enter long
          boolFlag = false;
          }

          if (condition short
          && boolFlag == true)
          {
          enter short
          boolFlag = false;
          }


          So now it will take only 1 trade period. But I need it to take 1 trade long if condition is met and 1 trade short if condition is met per day.

          From my reading a bool flag can only be true or false? If I could do a true1, true2, etc I think my problem would be solved.

          Any other ideas? At least now it will only just 1.

          Comment


            #20
            m3power222,

            If you want a long and a short you should use two bool flag variables, one for each.
            Josh P.NinjaTrader Customer Service

            Comment


              #21
              Originally posted by NinjaTrader_Josh View Post
              m3power222,

              If you want a long and a short you should use two bool flag variables, one for each.
              That did the trick:

              private bool entrylong = true;
              private bool entryshort = true;


              Thanks Josh.


              Is there a way to reset it to true for the next day without readding the strat? Reason being is if I just keep it connected 24x7 as I have logic to only enter trades mon-fri from x time to y time.

              Comment


                #22
                Code:
                if (Bars.FirstBarOfSession && FirstTickOfBar)
                {
                     entrylong = true;
                     entryshort = true;
                }
                Josh P.NinjaTrader Customer Service

                Comment


                  #23
                  Originally posted by NinjaTrader_Josh View Post
                  Code:
                  if (Bars.FirstBarOfSession && FirstTickOfBar)
                  {
                       entrylong = true;
                       entryshort = true;
                  }

                  Thanks again, can't test it as market replays are one day at a time.

                  Unless there is a way to string them together?

                  Comment


                    #24
                    One at a time for Market Replay. NT7 will allow you to string them together.
                    Josh P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by agclub, 04-21-2024, 08:57 PM
                    5 responses
                    32 views
                    0 likes
                    Last Post agclub
                    by agclub
                     
                    Started by ESHunter, Today, 08:06 PM
                    2 responses
                    16 views
                    0 likes
                    Last Post ESHunter  
                    Started by ETFVoyageur, 05-07-2024, 07:05 PM
                    19 responses
                    150 views
                    0 likes
                    Last Post ETFVoyageur  
                    Started by ETFVoyageur, Yesterday, 10:13 PM
                    3 responses
                    26 views
                    0 likes
                    Last Post ETFVoyageur  
                    Started by ETFVoyageur, Yesterday, 12:52 AM
                    3 responses
                    33 views
                    0 likes
                    Last Post ETFVoyageur  
                    Working...
                    X