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 NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        71 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        143 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        76 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        47 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        51 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X