Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculating the median of 4 values

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

    Calculating the median of 4 values

    Hi!
    I'v begun to program a custom indicator. But I can't figure out how to calculate a simple median of n values in c#. I want to calculate the median of the recent 4 troughs in MACD. I have stored the 4 values in an array, but as it looks in the c# reference one has to use a Series with the median function in the Statistic class.
    http://msdn.microsoft.com/en-us/library/system.web.ui.datavisualization.charting.statistic formula.mean(VS.100).aspx

    Is there another simpler way to calculate the median?
    If not, how do you declare a Series with 4 values and how do you asign the 4 values to it?

    /Andreas

    #2
    Unfortunately this is outside of the scope we can support here, are you already on .NET 4 for this to be available as method?

    As a hint - for example here's a link to code published where a GetMedian() method is developed accepting an int array as input -

    Hello, I have several jagged arrays which have been sorted. I'm trying to find the median of each array. Any tips appreciated. TIA. Bhads.

    Comment


      #3
      Thanks for the reply. I'm totally new to c#.
      I suposed that common functions like i.e. median would be predefined in c# as they are in Excel. But that is obviously not the case. Do you have to write your own code for all these common functions in c#?

      This code does calculates the median of an array
      i dont know wat is wrong with my code. when i compile. i get the error saying line 29: error: expression must have pointer-to-object type #include <iostream> using namespace std; #include <vector> double* median(double a[], int a_size) // Function Median { // Start of Function ( Median )


      /A

      Comment


        #4
        Many needed methods are already available in C#, MSDN would be the source to go to. In addition we have defined trading related methods in our NinjaScript, the language reference for this can be found in the NinjaScript section of our help guide, just press F1 in the software to access this. In the editor you can also just type 'this' followed by a dot to access the Intellisense feature -

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        563 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        329 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        547 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        548 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X