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 sjsj2732, Yesterday, 04:31 AM
        0 responses
        33 views
        0 likes
        Last Post sjsj2732  
        Started by NullPointStrategies, 03-13-2026, 05:17 AM
        0 responses
        286 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        284 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        133 views
        1 like
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        91 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Working...
        X