Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help understanding script

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

    Help understanding script

    Hi,
    I generated this strat with the experimental AI option. I understand approxCompare but need help understanding what the "Values" sections are doing/refering to. I looked at the documentation for "Values", but I'm still not clear. Any help appreciated.
    David

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class AutoStrategy : Strategy
    {

    protected override void OnStateChange()
    {
    base.OnStateChange();

    if (State == State.SetDefaults)
    {
    IncludeTradeHistoryInBacktest = false;
    IsInstantiatedOnEachOptimizationIteration = true;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    Name = "AutoStrategy";
    SupportsOptimizationGraph = false;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    AddChartIndicator(KeltnerChannel(1.40625, 9));
    AddChartIndicator(KeltnerChannel(1.125, 9));
    AddChartIndicator(KeltnerChannel(0.84375, 10));
    AddChartIndicator(KeltnerChannel(1.5, 10));
    }
    }

    protected override void OnBarUpdate()
    {
    base.OnBarUpdate();

    if (CurrentBars[0] < BarsRequiredToTrade)
    return;

    if (KeltnerChannel(1.40625, 9)[1].ApproxCompare(KeltnerChannel(1.125, 9).Values[2][2]) > 0)
    EnterLong();

    if (KeltnerChannel(0.84375, 10).Values[1][0].ApproxCompare(KeltnerChannel(1.5, 10)[1]) <= 0)
    ExitLong();
    }
    }
    }​

    #2
    Hello trader3000a,

    Values is the name used for the collection of plots that an indicator has. That is saying to use the second plot and 2 bars ago on that plot. For the Keltner channel that would be its Lower plot.

    Comment


      #3
      Hi Jesse,
      What about the first part of the first statement, which does not contain a "Values" section? Does it mean the upper keltner level in that case (is uppper the defualt?), or the midline, or...?
      thanks,
      David

      Comment


        #4
        Hello trader3000a,

        That is shorthand for the first plot an indicator has. That's generally used if an indicator only has one plot so you don't need to specify a plot name. That still works to reference the first added plot on any indicator.

        To know which plot is which you can look in the indicators code at the AddPlot statements. The order the plots are added in relate to which Values index it is. The first AddPlot is Values[0] and then it increments from there. The Values[2] used in that code would be the 3rd added plot.

        The first added plot in the Keltner is the midline.

        Comment


          #5
          Hi Jesse, thanks. So the first line in the strat's execution is saying:

          If the midline of the 1.40625, 9 period keltner channel 1 bar ago is greater than the lower line of the 1.125, 9 period keltner channel 2 bars ago, enter long.

          Am I correct?

          David

          Comment


            #6
            Hello trader3000a,

            That sounds correct, because ApproxCompare is used its best to bring in the definition for that to see how that is used in the condition.

            An int value representing the outcome of the comparison. Returns 0 if values are equal, 1 if value1 is greater than value2. -1 if value1 is less than value2.
            Code:
            if (KeltnerChannel(1.40625, 9)[1].ApproxCompare(KeltnerChannel(1.125, 9).Values[2][2]) > 0)

            This is saying if the midline of 1 bar ago is greater than the the Lower plot of two bars ago.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, 03-13-2026, 05:17 AM
            0 responses
            96 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            154 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            82 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            54 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            72 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X