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

Median of different time period

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

    Median of different time period

    Merry Xmas Ninja Dev's

    I can't seem to find a way to the get the Median of a different time frame in a strategy. I know there is a way :P Can someone please point me in the right direction. Variable0 works by itself, its the Median of the other 2 time frames that I want to add.

    protected override void Initialize()
    {
    Add(PeriodType.Minute, 60); // ON CHART
    Add(PeriodType.Minute, 20); // ON CHART
    CalculateOnBarClose = true;
    }

    protected override void OnBarUpdate()
    {
    Variable0 = SMA(Median, 200)[0];
    Variable1 = SMA(BarsArray[1].Median, 200)[0];
    Variable2 = SMA(BarsArray[2].Median, 200)[0];
    }

    #2
    Originally posted by happypappy View Post
    Merry Xmas Ninja Dev's

    I can't seem to find a way to the get the Median of a different time frame in a strategy. I know there is a way :P Can someone please point me in the right direction. Variable0 works by itself, its the Median of the other 2 time frames that I want to add.

    protected override void Initialize()
    {
    Add(PeriodType.Minute, 60); // ON CHART
    Add(PeriodType.Minute, 20); // ON CHART
    CalculateOnBarClose = true;
    }

    protected override void OnBarUpdate()
    {
    Variable0 = SMA(Median, 200)[0];
    Variable1 = SMA(BarsArray[1].Median, 200)[0];
    Variable2 = SMA(BarsArray[2].Median, 200)[0];
    }
    Are you getting any errors? If so, what are they?

    Comment


      #3
      The code doesn't work, I can't actually compile using BarsArray[1].Median

      I can't seem to find a way to use Median with any form of BarsArray[1] etc. I've tried all sorts of combinations.

      Variable0 = SMA(Median, 200)[0]; works
      Variable0 = SMA(Median[1], 200)[0]; doesn't work
      Variable0 = SMA(BarsArray[1].Median, 200)[0]; doesn't work
      Variable0 = SMA(Median(1), 200)[0]; doesn't work

      Any other ideas?

      Comment


        #4
        Originally posted by happypappy View Post
        The code doesn't work, I can't actually compile using BarsArray[1].Median

        I can't seem to find a way to use Median with any form of BarsArray[1] etc. I've tried all sorts of combinations.

        Variable0 = SMA(Median, 200)[0]; works
        Variable0 = SMA(Median[1], 200)[0]; doesn't work
        Variable0 = SMA(BarsArray[1].Median, 200)[0]; doesn't work
        Variable0 = SMA(Median(1), 200)[0]; doesn't work

        Any other ideas?
        What is the error message when you try to compile?

        Comment


          #5
          Strategy\BreakOut.cs 'NinjaTrader.Data.Bars' does not contain a definition for 'Median' and no extension method 'Median' accepting a first argument of type 'NinjaTrader.Data.Bars' could be found (are you missing a using directive or an assembly reference?) CS1061 - click for info 50 36

          I've got the Median plotted on the charts as a 20min, my indicator works over 60 min, so I just want to determine the price position compared to the SMA median over 20 minutes.
          Last edited by happypappy; 12-29-2013, 01:07 AM.

          Comment


            #6
            Originally posted by happypappy View Post
            Strategy\BreakOut.cs 'NinjaTrader.Data.Bars' does not contain a definition for 'Median' and no extension method 'Median' accepting a first argument of type 'NinjaTrader.Data.Bars' could be found (are you missing a using directive or an assembly reference?) CS1061 - click for info 50 36

            I've got the Median plotted on the charts as a 20min, my indicator works over 60 min, so I just want to determine the price position compared to the SMA median over 20 minutes.
            Try
            Code:
            Variable0 = SMA(Median[COLOR=Red][B]s[/B][/COLOR][1], 200)[0];

            Comment


              #7
              Hi Happypappy,

              Thank you for posting and thank you Koganam for answering.

              Yes, using Medians should resolve the error message.
              Cal H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by trilliantrader, Today, 03:01 PM
              0 responses
              2 views
              0 likes
              Last Post trilliantrader  
              Started by pechtri, 06-22-2023, 02:31 AM
              9 responses
              122 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by frankthearm, 04-18-2024, 09:08 AM
              16 responses
              67 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Started by habeebft, Today, 01:18 PM
              1 response
              8 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by benmarkal, Today, 12:52 PM
              2 responses
              19 views
              0 likes
              Last Post benmarkal  
              Working...
              X