Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8162525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:44:41+00:00 2026-06-06T18:44:41+00:00

I am putting together a technical analysis library that I hope others may use

  • 0

I am putting together a technical analysis library that I hope others may use eventually, so I want to make sure I validate data going into my methods and return something appropriate. Right now, if the validation fails I have it returning a blank value. Would it be more appropriate to throw an exception? What is the better practice if other developers may use this library? Here is how I am validating currently:

    /// <summary>
    /// Calculates the MACD (Moving Average Convergence Divergence) over n periods, where n is the number of elements in the input prices.
    /// </summary>
    /// <param name="InputValues">The numbers used for the MACD calculation. Index 0 must be the oldest, with each index afterwards one unit of time forward. There must more values present than what the SlowEMA calls for.</param>
    /// <param name="FastEMA">Optional: The smaller (faster) EMA line used in MACD. Default value is 12. Must be less than the SlowEMA.</param>
    /// <param name="SlowEMA">Optional: The larger (slower) EMA line used in MACD. Default value is 26. Must be less than the number of elements in InputValues.</param>
    /// <param name="SignalEMA">Optional: The EMA of the MACD line. Must be less than the FastEMA.</param>
    /// <returns>Returns the components of a MACD, which are the MACD line itself, the signal line, and a histogram number.</returns>
    public MACD CalculateMACD(decimal[] InputValues, decimal FastEMA = 12M, decimal SlowEMA = 26M, decimal SignalEMA = 9M)
    {
        MACD result;

        // validate that we have enough data to work with
        if (FastEMA >= SlowEMA) { return result; }
        if (SlowEMA >= InputValues.Count()) { return result; }
        if (SignalEMA >= FastEMA) { return result; }

        // Do MACD calculation here


        return result;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:44:44+00:00Added an answer on June 6, 2026 at 6:44 pm

    There are three standard Argument Exceptions in .Net:

    • ArgumentException
    • ArgumentNullException
    • ArgumentOutOfRangeException

    They all have overloads on their constructors to allow you to state which argument was an issue, and a more verbose message when throwing them.

    It would be normal practice to use these.

    Edit:

    Further to null (or empty or whatever) being acceptable, I would still tend to throw the exception, as you don’t necessarily know what the user of your library will be ok with. If they don’t mind nulls, they can always catch the exception and handle it as appropriate.

    However if you don’t throw an exception then you are limited in your ability to tell the consumer of your library what the problem was.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm putting together a site that will make itself available for user input. I
I'm putting together a simple drop down that contains nested ul's. I want it
I'm putting together a technical response to tender, one of the requirements is to
I putting together a page that will display a set of stored values. I
I am putting together a fairly simple web app that uses user inputted data
I'm putting together a Swing application where I often want to replace the contents
I'm putting together a simple web page that presents the user with a jQuery
I'm putting together a prototype to use XAML to create PNG buttons. The basic
I am currently putting together some jQuery that will activate slideDown() when an element
I am putting together an Java application that needs to display some basic lab

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.