Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Random number

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

    Random number


    I'm not a programmer, but I'm very involved haha. A long time ago I created a random number indicator, now I need it (I deleted it), now I do not know how I did it. number = random generated number.
    I have tried with:

    int number = Random(1,5);
    int number = rand(1,5);
    int number = Random ()% 100 + 1;
    int number = rand()% 100 + 1;

    However, he tells me that "Rand" does not exist in the context, I think it is because "it is not" the "stdlib.h". I repeat I do not know much about programming. And "Random" I do not know what it is, it tells me that "it uses a variable that does not". But I remember, some time ago I managed to do the random number, someone could help me. ? Very thanks and regards.

    #2
    Originally posted by samir View Post
    I'm not a programmer, but I'm very involved haha. A long time ago I created a random number indicator, now I need it (I deleted it), now I do not know how I did it. number = random generated number.
    I have tried with:

    int number = Random(1,5);
    int number = rand(1,5);
    int number = Random ()% 100 + 1;
    int number = rand()% 100 + 1;

    However, he tells me that "Rand" does not exist in the context, I think it is because "it is not" the "stdlib.h". I repeat I do not know much about programming. And "Random" I do not know what it is, it tells me that "it uses a variable that does not". But I remember, some time ago I managed to do the random number, someone could help me. ? Very thanks and regards.
    Code:
    Random rnd = new Random();
    int month = rnd.Next(1, 13); // creates a number between 1 and 12
    int dice = rnd.Next(1, 7); // creates a number between 1 and 6
    int card = rnd.Next(52); // creates a number between 0 and 51

    Comment


      #3
      Hello samir,

      Thank you for your post.

      koganam has hit the nail on the head here. I'd just like to add that there's publicly available documentation from Microsoft on the Random class in C#:

      Represents a pseudo-random number generator, which is an algorithm that produces a sequence of numbers that meet certain statistical requirements for randomness.


      Please let us know if we may be of further assistance to you.

      Comment


        #4
        Very thanks.

        Comment


          #5
          Thank you very much, a separate question. Does anyone know in which area of the documentation should I read in order to make the indicator work in the strategy tester and also in the historical candles?
          The behavior of the indicator does not comply with what I want, which is "The higher the value of the input, the higher the probability of being a 2" (between 1 and 99), 100 is always 2 (probability indicator, or at least that's what I want to do) (and it works well on new candles that appear live) But, in historical candlesticks and strategy tester almost always the indicator is flat and suddenly it has minimal variation, in the new real live candles the indicator moves a lot and works according to what I want.

          Code:
                          Probabilidad                    = 10;
                          AddPlot(Brushes.GreenYellow, "Resultado");
                      }
                  }
          
                  protected override void OnBarUpdate()
                  {
                                      Random rnd = new Random();
                              int numerogenerado = rnd.Next(1, 101);
                              if (numerogenerado <= Probabilidad)
                      {
                          Value[0] = 2;
                      }
                      else
                      {
                          Value[0] = 1;
                      }
          I appreciate your help, thank you very much. Greetings.
          Last edited by samir; 06-22-2019, 07:43 PM.

          Comment


            #6

            Comment


              #7
              Originally posted by samir View Post
              Thank you very much, a separate question. Does anyone know in which area of the documentation should I read in order to make the indicator work in the strategy tester and also in the historical candles?
              The behavior of the indicator does not comply with what I want, which is "The higher the value of the input, the higher the probability of being a 2" (between 1 and 99), 100 is always 2 (probability indicator, or at least that's what I want to do) (and it works well on new candles that appear live) But, in historical candlesticks and strategy tester almost always the indicator is flat and suddenly it has minimal variation, in the new real live candles the indicator moves a lot and works according to what I want.

              Code:
               Probabilidad = 10;
              AddPlot(Brushes.GreenYellow, "Resultado");
              }
              }
              
              protected override void OnBarUpdate()
              {
              Random rnd = new Random();
              int numerogenerado = rnd.Next(1, 101);
              if (numerogenerado <= Probabilidad)
              {
              Value[0] = 2;
              }
              else
              {
              Value[0] = 1;
              }
              I appreciate your help, thank you very much. Greetings.
              Move the declaration of rnd out of OnBarUpdate(). Declare it at the class level.

              As written you are generating a new random number on each pass instead of using the one that already exists.
              Last edited by koganam; 06-22-2019, 11:00 PM. Reason: Corrected grammar.

              Comment


                #8
                Extremely thanks kogaman.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                581 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                337 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                103 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                554 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                552 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X