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 burtoninlondon, Today, 12:38 AM
          0 responses
          10 views
          0 likes
          Last Post burtoninlondon  
          Started by AaronKoRn, Yesterday, 09:49 PM
          0 responses
          14 views
          0 likes
          Last Post AaronKoRn  
          Started by carnitron, Yesterday, 08:42 PM
          0 responses
          11 views
          0 likes
          Last Post carnitron  
          Started by strategist007, Yesterday, 07:51 PM
          0 responses
          14 views
          0 likes
          Last Post strategist007  
          Started by StockTrader88, 03-06-2021, 08:58 AM
          44 responses
          3,983 views
          3 likes
          Last Post jhudas88  
          Working...
          X