Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can I expose a value for optimization?

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

    Can I expose a value for optimization?

    Hi

    Is it possible to expose a value that is calculated in a strategy, so that it is accessible by a custom optimization type? This is what I tried, but it was just a guess and did not work.

    In the strategy:
    // expose the SQN result for optimisation???
    [Browsable(false)]
    public double SQN
    {
    get { return sQN; }
    }

    The optimization type:
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// System Quality Number
    /// </summary>
    [Gui.Design.DisplayName("SQN")]
    public class SQN : OptimizationType
    {
    public override double GetPerformanceValue(SystemPerformance systemPerformance)
    {
    return( this.Strategy.SQN );
    }
    }
    }

    Cheers
    Tony

    #2
    Hello Tony,

    You would not be able to directly pass a variable like that from a Strategy to an Optimization Type like that since it is different base type.

    This is something that we do not support and I am not aware of any good way to to do this. You may try to write the variable to a file and then have your Optimization Type read this file but you may run into situations were the file is being used by the Strategy when the Optimization Type is as well.

    I will leave this thread open if any other members of our Forum would like to share their experiences.
    JCNinjaTrader Customer Service

    Comment


      #3
      Tony,

      Oddly, I was just working on this. Here is an easy way to pass numeric data to the optimization type:

      In your Strategy itself, there are variables as part of the base class (Variable0-Variable9)

      double MyValue=3;
      Variable2=MyValue;

      Now, in the OptimizationType code, do the following:

      publicoverridedouble GetPerformanceValue(SystemPerformance systemPerformance)
      {
      Strategy.Print(
      "From Strategy: "+Strategy.Variable2);
      return Strategy.Variable2;
      }

      This way, the Strategy can do the calculation and then pass that to the optimizer. For example, since there is no way to determine the initial risk value (R) from SystemPerformance, I could tally those Rs in code and then pass that to the optimizer.

      Hope that helps.

      Comment


        #4
        Thanks Bobcat, you're a legend!

        I've been calculating SQN in OnTermination(), but the optimiser doesn't see it if I assign Variable0 there. It worked when I assigned Variable0 in OnBarUpdate(), though, which is fine - it's an easy change.

        One question: Are the Variables0-9 used for any other purpose? Could I create obscure problems by using them?

        Thanks again
        Tony

        Comment


          #5
          Hello Tony,

          Variables0-9 are a in the base Strategy class and were initially designed so that you can set those variables inside of the Strategy Wizard when a condition is met.

          I have not worked with it enough to know if there are any issues that you can run into besides the one that you have already ran into.
          JCNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

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