Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy compiles but wont enable

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

    Strategy compiles but wont enable

    Hello,

    I have written a strategy that successfully compiles but when I go to enable it, it won't stay enabled. I've gone through section by section and line by line to determine which part of my code is not able to enable and this is the part giving me trouble:
    This is located in a for loop where I am trying to compare close values in the past to the value 1 in front and 1 behind the current value being evaluated.

    if(Close[i] > Close[i + 1] && Close[i] > Close[i - 1])
    {
    ArrayPeak[1,j] = Close[i];
    j = j + 1;
    }

    if(Close[i] < Close[i + 1] && Close[i] < Close [i - 1])
    {
    ArrayValley[1,k] = Close[i];
    k = k + 1;
    }


    This section is comparing the values generated by the previous section to determine an overall trend.

    if(ArrayPeak[0,0] > ArrayPeak[0,1] && ArrayPeak[0,0] > ArrayPeak[0,2] && ArrayPeak[0,1] > ArrayPeak[0,2] && ArrayValley[0,0] > ArrayValley[0,1] && ArrayValley[0,0] > ArrayValley[0,2] && ArrayValley[0,1] > ArrayValley[0,2])
    {
    TrendUpward = true;
    }

    if(ArrayPeak[0,0] < ArrayPeak[0,1] && ArrayPeak[0,0] < ArrayPeak[0,2] && ArrayPeak[0,1] < ArrayPeak[0,2] && ArrayValley[0,0] < ArrayValley[0,1] && ArrayValley[0,0] < ArrayValley[0,2] && ArrayValley[0,1] < ArrayValley[0,2])
    {
    TrendDownward = true;
    }


    Both of these sections independently do not allow the code to enable successfully.

    Am I declaring and using these arrays incorrectly? And can I not use a variable inside the Close[]?

    Thank you
    Jeff​

    #2
    Hello Jeff,

    Is the strategy becoming disabled?

    If so, are there errors on the Log tab of the Control Center?

    When using barsAgo indexes on Series<T> objects, are all indexes less than CurrentBar?
    For arrays, are all indexes less than the size of the collection? (Array.Count)


    "Am I declaring and using these arrays incorrectly?"

    You have not provided the code where the arrays are being declared. If these are declared in the scope of the class and instantiated in State.DataLoaded, this would be correct.

    "And can I not use a variable inside the Close[]?"

    You can use a variable to supply a barsAgo index as long as the value is less than CurrentBar.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Sorry I did forget to include the declaration of the arrays.

      private double[,] ArrayPeak;
      private double[,] ArrayValley;​

      Comment


        #4
        Hello Jeff,

        The access modifier appears to show the variables are declared in the scope of the class.

        When using barsAgo indexes on Series<T> objects, are all indexes less than CurrentBar?
        For arrays, are all indexes less than the size of the collection? (Array.Count)​
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        93 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        138 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        68 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        123 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        73 views
        0 likes
        Last Post PaulMohn  
        Working...
        X