Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Writing a bool Method. Getting error CS0161.

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

    Writing a bool Method. Getting error CS0161.


    How do I solve the error?

    protected ISeries<double> argument1;
    protected ISeries<double> argument2;
    private int lookBackPeriod;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "aRectsDemo";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = false;
    DrawVerticalGridLines = false;
    PaintPriceMarkers = false;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    Ticktimeframe = 1000;
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Tick, Ticktimeframe);
    }
    }

    protected override void OnBarUpdate()
    {

    WasAbove(Close, SMA(20), 20);

    }

    protected bool WasAbove (ISeries<double> argument1, ISeries<double> argument2, int lookBackPeriod)
    {
    for (int i = 0; i < lookBackPeriod; i++)
    {
    if (argument1[i] > argument2[i])
    {
    return true;
    }

    else
    return false;
    }
    }

    #2
    Hello jamestrader21x,

    If you want to learn about that error specifically you can search for any error code you see in the platform on google, we are using C# so you can find the explanation in MSDN or also other websites like stackoverflow.

    Your method does not return in all paths, it always has to return something so it would need to be written like the following:

    Code:
    private bool WasAbove (ISeries<double> argument1, ISeries<double> argument2, int lookBackPeriod)
    {
        bool result = false;
        for (int i = 0; i < lookBackPeriod; i++)
        {
            if (argument1[i] > argument2[i])
            {
                 result = true;
             }
        }
        return result;
    }
    as a side note you are currently not getting the return value of the method in OnBarUpdate, you could use a variable:

    Code:
    bool result = WasAbove(Close, SMA(20), 20);
    JesseNinjaTrader Customer Service

    Comment


      #3
      I checked online before posting. I couldn't find a satisfying answer. I appreciate the help. By the way, how did you post that code in like that? I've always wonder how people do that on this forum.

      Comment


        #4
        Hello jamestrader21x,

        To add code blocks you need to click the A in the top right of the forum text editor (advanced editor) and then there is a hash tag: # in the toolbar, you select the text and then press the button.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks for the help! I got my code updated. Even overloaded it. I don't know why Ninja Trader doesn't have a 'WasAbove/Below' method. CrossAbove/Below only covers entry above/below thresholds. Sometimes ISeries<doubles> stay above threshold for quite awhile; making CrossAbove/Below useless or you have to extend the look back period. Again, thanks for the help!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by wzgy0920, 04-20-2024, 06:09 PM
          2 responses
          27 views
          0 likes
          Last Post wzgy0920  
          Started by wzgy0920, 02-22-2024, 01:11 AM
          5 responses
          32 views
          0 likes
          Last Post wzgy0920  
          Started by wzgy0920, 04-23-2024, 09:53 PM
          2 responses
          49 views
          0 likes
          Last Post wzgy0920  
          Started by Kensonprib, 04-28-2021, 10:11 AM
          5 responses
          193 views
          0 likes
          Last Post Hasadafa  
          Started by GussJ, 03-04-2020, 03:11 PM
          11 responses
          3,235 views
          0 likes
          Last Post xiinteractive  
          Working...
          X