Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

random entryy

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

    random entryy

    hi.. how can i get a random WHOLE number between a given set

    set= 1,2,3,4,5,6,7,8,10

    input=random(1,2,3,4,5,6,7,8,10)

    output i want from the given input is= 1, or 2, or 3 etc...

    basically i want a function that i can give it thirty different numbers, and it outputs one number for each trade.

    #2
    Hi Calhawk01,

    Thank you for your note.

    You can use this snippet to produce a random number between 1 and 30 -

    Code:
    Random randomNumber = new Random();
    
    Print(randomNumber.Next(1,30));
    This will create a new Random() instance and the second line will print a random number between 1 and 30.

    Let me know I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Cal View Post
      Hi Calhawk01,

      Thank you for your note.

      You can use this snippet to produce a random number between 1 and 30 -

      Code:
      Random randomNumber = new Random();
      
      Print(randomNumber.Next(1,30));
      This will create a new Random() instance and the second line will print a random number between 1 and 30.

      Let me know I can be of further assistance.
      will that produce whole numbers ? i'm trying to avoid.. 1.2;1.3;1.6 etc

      Comment


        #4
        Calhawk01,

        Yes this will produce whole numbers as it utilizes Int values.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Cal View Post
          Calhawk01,

          Yes this will produce whole numbers as it utilizes Int values.
          thank you very much!

          since i have you hear, one more question

          i'm trying to create an indicator; and i want to count how many times XYZ event occured during a trading session. would you have any templates in your mind?

          basically, XYZ event could be as simple as, close[0] crossed over sma(2); if that occured, count 1; if it occured again during the same session, count increases to 2 etc

          at the start of the new session, reset the counter

          Comment


            #6
            Calhawk01,

            Unfortunately, I do not have any templates or samples for that kind of code.

            You should be able to create this with a condition to increase the count and then another that will reset the variable when a new session has started.
            Cal H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            670 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            379 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            111 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            575 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            582 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X