Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

random entry system?

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

    random entry system?

    I have some ideas I want to test as far as money/trade management/exits go and spent some time tonight trying to figure out how to randomly enter the market. I was not able though to figure out how to do this.
    Anyone have a system or idea to share with just 1 input for number of trades per day?
    ie. input the number 3, the system will randomly enter 3 trades at some point during the day.

    thanks
    nate

    #2
    I would do something like this (pseudocode of course):

    in OnBarUpdate()
    if (Bars.BarsSinceSession == 0)
    {
    // Set the bars on which we will trade this session
    myArray = new int[NumTrades] // this needs to be a member variable of type int []
    generate NumTrades random numbers b/t 1 and max bars per session
    Store those random numbers in MyArray
    return
    }

    if (Bars.BarsSinceSession is in MyArray)
    {
    Place your trade
    }


    Not tested, but I think this should work.

    Comment


      #3
      If you just want to test your money management exits I suggest you just enter trades based on Close[0] > Open[0]. Every time you enter a trade increment a counter. When the counter hits your input of 3. Stop further trades.
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        Thanks guys, there are other things I would like to mess around with actually beyond just money management though.
        Really, I should have asked this in a different fashion...
        how do I generate bounded random numbers?
        I think I could figure out what I want to do if I just knew that.

        Comment


          #5


          Google random numbers. There are a lot of resources you can find.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            oops, I was thinking someone was going to give a ninja version of rand...forgot this is basic csharp stuff.
            When I thought more about it last night, probly the easiest thing to do is just create random time variables and then use totime and enter market orders.

            thanks guys!

            Comment


              #7
              Originally posted by Pete S View Post
              I would do something like this (pseudocode of course):

              in OnBarUpdate()
              if (Bars.BarsSinceSession == 0)
              {
              // Set the bars on which we will trade this session
              myArray = new int[NumTrades] // this needs to be a member variable of type int []
              generate NumTrades random numbers b/t 1 and max bars per session
              Store those random numbers in MyArray
              return
              }

              if (Bars.BarsSinceSession is in MyArray)
              {
              Place your trade
              }


              Not tested, but I think this should work.
              Uhm, does somebody have an idea how to make an random entry? I tried to make it work with the above quoted text, but I couldn't get that to work.

              I did try the following way:
              Code:
              [FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// Open first long position[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
              [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]( Bars.BarsSinceSession == [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
              [SIZE=2][FONT=Courier New]EnterLong([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Enter Long"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
               
              [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// Open afterwards random positions[/COLOR][/SIZE][/FONT]
              [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]Random randNum = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Random();[/SIZE][/FONT]
              [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](BarsSinceExit() > randNum.Next([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]5[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]30[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]))[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
              [SIZE=2][FONT=Courier New]EnterLong([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Enter Long"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
              [/SIZE][/FONT]
              But that only gave me the same random number for the complete backtest.

              I also tried it with this:
              Code:
              [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]while[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](BarsSinceExit > [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
              [SIZE=2][FONT=Courier New]Random randNum = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Random();[/SIZE][/FONT]
              [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](BarsSinceExit() > randNum.Next([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
              [SIZE=2][FONT=Courier New]EnterLong([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Enter Long"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
              [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
              [/SIZE][/FONT]
              But that didn't work either.

              Can somebody help me out? I already tried Googling but a lot of the sites I dug up where of bad quality or more focused on the experts. Lol, even the book "C# for Dummies" doesn't have anything about this.

              Regards,

              Jos

              Comment


                #8
                Just create yourself one of these and call the function when you need a random number:
                Learn how to generate random numbers in C# with this comprehensive tutorial. Master the art of randomization using built-in methods and algorithms. Explore various approaches and techniques for generating random numbers efficiently in your C# programs.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Josh View Post
                  Just create yourself one of these and call the function when you need a random number:
                  http://www.c-sharpcorner.com/UploadF...domNumber.aspx
                  Thank Josh for the link. I tried that and it didn't work, so I have to do something wrong.

                  I put the following in the Variables region:
                  Code:
                  [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]#region[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Variables[/SIZE][/FONT]
                  [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// User defined variables (add any user defined variables below)[/COLOR][/SIZE][/FONT]
                  [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]private [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] RandomNumber([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] min, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] max)[/SIZE][/FONT]
                  [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                  [SIZE=2][FONT=Courier New]Random random = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Random();[/SIZE][/FONT]
                  [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] random.Next(min, max); [/SIZE][/FONT]
                  [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                  [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]#endregion[/COLOR][/SIZE][/FONT]
                  [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
                  Then I put the following in the main section:
                  Code:
                  [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] OnBarUpdate()[/SIZE][/FONT]
                  [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                   
                  [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](Position.MarketPosition == MarketPosition.Flat)[/SIZE][/FONT]
                  [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                  [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] returnValue = RandomNumber([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]5[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
                  [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](BarsSinceExit() > returnValue)[/SIZE][/FONT]
                  [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                  [SIZE=2][FONT=Courier New]EnterLong([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Enter Long"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
                  [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                  [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]else [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](BarsSinceExit() < returnValue)[/SIZE][/FONT]
                  [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                  [SIZE=2][FONT=Courier New]EnterShort([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Enter Short"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
                  [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                  [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                  [/SIZE][/FONT]}
                  It looks sound to me, but only is there a short trade entered on the first bar of the day, which is then closed on the last bar of the day. EnterLong doesn't do anything.

                  Could someone help me out? I guess I'm overlooking the obvious.

                  Regards,

                  Jos

                  Comment


                    #10
                    If you've made 1 trade that means your random # generator is working just fine. From here you just need to debug your code. Please see this tip: http://www.ninjatrader-support2.com/...ead.php?t=3418
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Josh View Post
                      If you've made 1 trade that means your random # generator is working just fine. From here you just need to debug your code. Please see this tip: http://www.ninjatrader-support2.com/...ead.php?t=3418
                      Thanks, but I was already aware of that link.

                      Through debugging I did find that it seems that only at the beginning of a new day there is a new random number generated, which then lasts for all the trades on that day. Is this because of the way NinjaTrader calls upon the C# code?

                      Regards,

                      Jos

                      Comment


                        #12
                        You will get a new number every time you call the function. If your OnBarUpdate() only triggers once you will only get it once. In your case you are limiting your condition for only when you are Flat. You are only Flat once and that is at the beginning. After that you are never flat until the strategy closes you at the end of the day.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          I have the following code which produces random numbers OK. Not sure if your trading logic hooks into this correctly.

                          Outside any methods, in User defined variables section:

                          private Random rand = new Random();

                          Inside OnBarUpdate:

                          myVariable = rand.Next(NN);

                          Comment


                            #14
                            Originally posted by TCT-Peter View Post
                            I have the following code which produces random numbers OK. Not sure if your trading logic hooks into this correctly.

                            Outside any methods, in User defined variables section:

                            private Random rand = new Random();

                            Inside OnBarUpdate:

                            myVariable = rand.Next(NN);
                            Thank you very much! That works excellent.

                            Regards,

                            Jos

                            Comment


                              #15
                              New Random numbers

                              I have an execution size (int) that is related to market volatility, for example 483 lots. How do I enter new random number positions until that position of 483 has been built up?

                              For example New Random number (1,50)

                              1
                              23
                              44
                              2
                              4
                              16


                              I basically want to chop up a large market order into small random sizes.

                              Regards to all.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              672 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