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

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 -

    BertrandNinjaTrader Customer Service

    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


      /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 -

        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by trilliantrader, 04-18-2024, 08:16 AM
        4 responses
        18 views
        0 likes
        Last Post trilliantrader  
        Started by mgco4you, Today, 09:46 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by wzgy0920, Today, 09:53 PM
        0 responses
        10 views
        0 likes
        Last Post wzgy0920  
        Started by Rapine Heihei, Today, 08:19 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by Rapine Heihei, Today, 08:25 PM
        0 responses
        10 views
        0 likes
        Last Post Rapine Heihei  
        Working...
        X