Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Well in Standard Backtest but Error in Optimization

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

    Well in Standard Backtest but Error in Optimization

    A strategy is well back-tested in Standard Mode, but many exceptions occur in Optimization Mode.
    The exception is: Object reference not set to an instance of an object.

    I have no idea about the reason, could you please kindly give me some help?

    The following is an example of error method, Exception occurs at the 2nd iteration of a following loop:

    public void UpdateBuffers_RSIReversal()
    {
    try
    {

    bool tempIfRSICrossAbove = false;
    bool tempIfRSICrossBelow = false;

    int tempRSIstyle = myFullRSIstyles[ToSymbolsIndex(BarsInProgress)];
    SWWriteLine("CP2:myRSILevels="+ myRSILevels[ToSymbolsIndex(BarsInProgress)].Length);
    for (int j = 0; j <= myRSILevels[ToSymbolsIndex(BarsInProgress)].GetUpperBound(0); j++)
    {
    //!!!!!!!!Exception occurs at the 2nd iteration of this loop.
    if (tempRSIstyle == (int)myEnumRSIstyles.RSIDefault)//i.e. myEnumRSIstyles == 0
    {
    tempIfRSICrossAbove = CrossAbove(RSI(BarsArray[BarsInProgress], myRSIPeriods[ToSymbolsIndex(BarsInProgress)], myRSISmoothPeriods[ToSymbolsIndex(BarsInProgress)]), myRSILevels[ToSymbolsIndex(BarsInProgress)][j], 1);
    tempIfRSICrossBelow = CrossBelow(RSI(BarsArray[BarsInProgress], myRSIPeriods[ToSymbolsIndex(BarsInProgress)], myRSISmoothPeriods[ToSymbolsIndex(BarsInProgress)]), myRSILevels[ToSymbolsIndex(BarsInProgress)][j], 1);
    }

    if (tempRSIstyle == (int)myEnumRSIstyles.RSIAvg)//i.e. myEnumRSIstyles == 1
    {
    tempIfRSICrossAbove = CrossAbove(RSI(BarsArray[BarsInProgress], myRSIPeriods[ToSymbolsIndex(BarsInProgress)], myRSISmoothPeriods[ToSymbolsIndex(BarsInProgress)]).Avg, myRSILevels[ToSymbolsIndex(BarsInProgress)][j], 1);
    tempIfRSICrossBelow = CrossBelow(RSI(BarsArray[BarsInProgress], myRSIPeriods[ToSymbolsIndex(BarsInProgress)], myRSISmoothPeriods[ToSymbolsIndex(BarsInProgress)]).Avg, myRSILevels[ToSymbolsIndex(BarsInProgress)][j], 1);
    }

    if (tempIfRSICrossAbove)
    {
    mySeriesRSICrossAboveOrBelow[BarsInProgress][j][0] = 1;
    return;
    }

    if (tempIfRSICrossBelow)
    {
    mySeriesRSICrossAboveOrBelow[BarsInProgress][j][0] = -1;
    return;
    }

    mySeriesRSICrossAboveOrBelow[BarsInProgress][j][0] = 0;
    }
    SWWriteLine("CP3");
    }
    catch (Exception e)
    { ReportExceptionInfo(e); }
    }

    #2
    Hello,

    Thank you for the question.

    You would need to check what specifically is becoming null to really know what is happening on the next iteration.

    I would suggest to try doing the following for testing:
    Remove the try/catch, these will likely not assist in finding the null.
    Check the objects that can be null with a print and address what is null, because I can not see the types for the variables I am unsure what specifically posted could be null, but an example could be:

    if(myRSIPeriods == null) Print("myRSIPeriods is null");
    if(myRSIPeriods[ToSymbolsIndex(BarsInProgress)] == null) PrintPrint("myRSIPeriods[ToSymbolsIndex(BarsInProgress)] is null");

    If the object myRSIPeriods or myRSIPeriods[ToSymbolsIndex(BarsInProgress)] can be null, this would let you see if it is on the iteration.

    You may need to go through the whole condition to locate what is null.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Jesse,

      Thank you for your help.

      I notice that option "Optimize data series" in the Group "Optimization Properties" determines my problem. If "Optimize data series" is true, my DataSeries type variables work correctly, otherwise exceptions occur.

      NinjaTrader 8 Guide says, "If set to true, the Data Series Value property will be available for optimization." What does this mean?

      Comment


        #4
        Hello,

        That would allow you to iterate over different periods on a dataseries, that option simply enables the dataseries property to appear so you can optimize it.

        Instead of selecting 1 time, you could select 1 minute through 10 minute at the interval of 1 for example.

        If that is controlling the error, you would need to visit the code being used related to the DataSeries as you said to see what specifically is becoming null.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ebaydan777, Today, 02:41 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Started by aligator, Today, 02:28 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_ChristopherJ  
        Started by daniel_weber8, Today, 01:21 PM
        1 response
        22 views
        0 likes
        Last Post NinjaTrader_ChristopherS  
        Started by jungsoohuh, Today, 12:07 PM
        1 response
        28 views
        0 likes
        Last Post NinjaTrader_PaulH  
        Started by SharonSS, Today, 11:54 AM
        2 responses
        24 views
        0 likes
        Last Post SharonSS  
        Working...
        X