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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        152 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        87 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        131 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        127 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        106 views
        0 likes
        Last Post CarlTrading  
        Working...
        X