Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

new entry algo

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

    new entry algo

    Greets!

    I am trying to develop a different approach to selecting a target price for EnterLongLimit.

    Variables:

    Code:
     
    #region  touch_price
     
    private int ifactor1 = 8;
      [Description("value for array matrix multiplier to develop touch price for target on LIT")]
       [GridCategory("Touch_Price")]
      [Gui.Design.DisplayName ("1.a  value for array matrix multiplier to develop touch price 3( 1 8 1)")]
            public int factor1
            { get { return ifactor1; } set { ifactor1 = Math.Max(1, value); }  }
     
      private int ifactor2 = 8;
      [Description("value for array matrix multiplier to develop touch price for target on LIT")]
       [GridCategory("Touch_Price")]
      [Gui.Design.DisplayName ("1.b  value for array matrix multiplier to develop touch price 3( 1 8 1)")]
            public int factor2
            { get { return ifactor2; } set { ifactor2 = Math.Max(1, value); }  }
     
      private int ifactor3 = 8;
      [Description("value for array matrix multiplier to develop touch price for target on LIT")]
       [GridCategory("Touch_Price")]
      [Gui.Design.DisplayName ("1.c  value for array matrix multiplier to develop touch price 3( 1 8 1)")]
            public int factor3
            { get { return ifactor3; } set { ifactor3 = Math.Max(1, value); }  }
      #endregion
    a double is used as a limiting factor also:

    private double touch_price = 0;
    private int total_factor = 10;
    and in OnBarUpdate:

    double BIP3prc = Typicals[3][0];
    double BIP2prc = Lows[2][0];
    double BIP1prc = Closes[1][0];
    total_factor = factor1 + factor2 + factor3;
    touch_price = ( (factor3 * BIP3prc) + (factor2 * BIP2prc) + (factor1 * BIP1prc) )/10;
    BUT there are no results at the end of the optimization run, but no errors in compilation or on the log tab. Optimizing without that code is good.

    Any ideas what I goofed on to start looking?

    Thanks,
    Jon

    #2
    Hi Jon,

    You will have to Print() all values to make sure they're what you expect, and use TraceOrders output to track strategy order submission. If this doesn't provide any clues, then next step is simplifying your code.

    One general concern is performing math on mixed types (integer & double). Anytime you do, this cast the integer as a double by adding (double) before the variable name.

    myValue = (double) myInt * myDouble;
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_RyanM View Post
      Hi Jon,

      You will have to Print() all values to make sure they're what you expect, and use TraceOrders output to track strategy order submission. If this doesn't provide any clues, then next step is simplifying your code.

      One general concern is performing math on mixed types (integer & double). Anytime you do, this cast the integer as a double by adding (double) before the variable name.

      myValue = (double) myInt * myDouble;
      Ryan,

      Thanks for the insight. The rest of the code is trouble free.

      Would changing

      private int total_factor = 10;

      to

      private double total_factor = 10;

      cause any obvious issues? I was thinking there might be a trouble if I tried to add those doubles together?!

      I also see now what I might be an issue ... trying to always have 10 as total as in

      private int total_factor = 10 and (factor1 + factor2 + factor3) = 10 = total_factor

      Can you offer some insight .. I am not clear for best solution.

      Thanks so much,
      Jon

      Comment


        #4
        Changing type to double shouldn't cause issues unless there is an unknown requirement that it's an integer.

        There's no shortcut to debugging this, so be sure to print all values and use TraceOrders to get a perspective on what your code is doing.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_RyanM View Post
          Changing type to double shouldn't cause issues unless there is an unknown requirement that it's an integer.

          There's no shortcut to debugging this, so be sure to print all values and use TraceOrders to get a perspective on what your code is doing.
          Not looking for an actual shortcut, rather what is 'generally accepted'. I havent had much code seen in trying to 'force' added values to always have a specific sum.

          Sorry if that (obviously) wasnt clear. Is there anything in the C# math that does that natively? I wasnt able to spot an instance, and my logic thinking something like

          (Math.Max(Math.Min(factor1+factor2+factor3 = 10))

          while not useful might have an ability to be useful in some way toward a solution?

          Jon

          Comment


            #6
            You may want to look into floating point values as a potential issue here. You can use Compare() against 10 to be sure there aren't issues with this:
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by Trader.Jon View Post
              Not looking for an actual shortcut, rather what is 'generally accepted'. I havent had much code seen in trying to 'force' added values to always have a specific sum.

              Sorry if that (obviously) wasnt clear. Is there anything in the C# math that does that natively? I wasnt able to spot an instance, and my logic thinking something like

              (Math.Max(Math.Min(factor1+factor2+factor3 = 10))

              while not useful might have an ability to be useful in some way toward a solution?

              Jon
              Hi Jon,
              Not sure I follow what you are trying to do 100% however, if you want to set all three variables to = 10.0 you can do this:

              factor1 = factor2 = factor3 = (10D/3D);

              This will set all of the variables to 3.33 of course. If you dont want them all to be completely evenly sized and want to just lop the missing difference into factor3 for example you could try
              Code:
              if(factor1 + factor2 + factor3 < 10D)
                  factor3 += (10D - (factor1+factor2+factor3));
              this should leave factor1+factor2+factor3 = 10.0. Hope this helps with your strategy logic
              DexterNinjaTrader Customer Service

              Comment


                #8
                Dexter,

                Thanks. The actual need was to have each of the factor1/2/3 to have a whole value between 1 to 8 so that the total would be 10 for all three, with none of them below 1.

                Input is alway appreciated!

                Jon

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                648 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                369 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                108 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                572 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                573 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X