Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

get the weekly high of the last three weeks

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

    get the weekly high of the last three weeks


    Good morning to everybody, My idea is to obtain the weekly high of the last three weeks and the weekly low of the last three weeks to average them. I've read quite a bit on the matter, but haven't found a valid answer to what I need and that apparently shouldn't be too complicated, although it finally seems so. I have seen that there are several indicators, for example ana, but what I want is not to paint the signals, but to obtain the values ​​to use them mathematically. I have tried to add a weekly data series, but including the strategy in the chart gives an error, which I am not able to solve, so I would like to know if there is a simpler way, which does not require adding additional data series . Thank you very much and greetings

    #2
    Hello danakede,

    Thank you for your post.

    It would be simplest to do with an added weekly data series. The trick with that is, you need to check to make sure enough weekly bars are available for it to calculate.

    Here's a quick example script that will plot the weekly high and weekly low (It must have a minimum of 21 days loaded on the chart to work):


    Code:
        public class Example3WeekHighLowAvg : Indicator
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Indicator here.";
                    Name                                        = "Example3WeekHighLowAvg";
                    Calculate                                    = Calculate.OnBarClose;
                    IsOverlay                                    = true;
                    DisplayInDataBox                            = true;
                    DrawOnPricePanel                            = true;
                    DrawHorizontalGridLines                        = true;
                    DrawVerticalGridLines                        = true;
                    PaintPriceMarkers                            = true;
                    ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive                    = true;
                    AddPlot(Brushes.OrangeRed, "AverageHigh");
                    AddPlot(Brushes.DodgerBlue, "AverageLow");
                }
                else if (State == State.Configure)
                {
                    AddDataSeries(Data.BarsPeriodType.Week, 1);
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (CurrentBars[1] < 3)
                    return;
    
                Values[0][0] = (Highs[1][0]+ Highs[1][1] + Highs[1][2])/3;
                Values[1][0] = (Lows[1][0] + Lows[1][1] + Lows[1][2])/3;
            }
    
            #region Properties
    
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> AverageHigh
            {
                get { return Values[0]; }
            }
    
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> AverageLow
            {
                get { return Values[1]; }
            }
            #endregion
    
        }
    This could be adapted so instead of assigning the averages to a plot you do whatever calculations you like with those values.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3

      Good morning Kate, your information has been of great help. I have managed to make the code you sent me work as an indicator by itself. On the other hand, I have verified that when adding an additional data series to my strategy, it cannot be executed on every tick, it does not work with Resolution: "High", only an additional data series can be added to a strategy and it will have to run Resolution: "Standard". My strategy is designed to only work with Resolution: "High, tick, 1", so I cannot incorporate additional data set into my strategy. The indicator that you have provided is perfect for me, so my question is ... can I take the values ​​of the indicator "AverageHigh" and "AverageLow" to use in my strategy? If possible, what is the method to call them from the strategy? Thank you

      Comment


        #4
        Hello danakede,

        Thank you for your reply.

        You wouldn't be able to use it without adding the additional data series in the strategy as well.

        To maximize data loading performance, any NinjaScript object (indicator or strategy as host) which references a multi-series indicator which calls AddDataSeries must include it's own calls to AddDataSeries(). For example, if the code below was included in an indicator, and that indicator was referenced in a NinjaScript strategy, then the hosting strategy will need to include the same calls to AddDataSeries().

        When the strategy adds the additional Bars objects, the calls to AddDataSeries() within the indicator will be ignored. If the Bars objects are not added by the strategy in such cases, and error will be thrown in the Log tab of the Control Center that would read - "A hosted indicator tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state."

        So you would need to add the additional data series, which would preclude you from running the strategy on high resolution. You would need to manually add that secondary data series and code in the more granular resolution into the strategy with a single tick series as well.

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5

          Buenos dias Kate No entiendo lo que quieres decir con esta frase: " Debería agregar manualmente esa serie de datos secundarios y el código en la resolución más granular en la estrategia con una sola serie de ticks".

          ¿Esta solución que me brinda me permite operar con mi estrategia en alta resolución? and at the same time be able to take the data from the indicator? ¿Me podría explicar mejor lo que quiere decir? Muchas gracias y un saludo.

          Comment


            #6
            Good morning Kate I don't understand what you mean by this sentence: "You should manually add that secondary data set and the code in the most granular resolution in the strategy with a single set of ticks".

            Does this solution allow me to operate with my strategy in high resolution? and at the same time be able to take the data from the indicator? Could you explain to me better what you mean? Thank you very much and a greeting

            Translated with www.DeepL.com/Translator (free version)
            Hello danakede,

            Thank you for your note.

            I've translated your previous post above. You would not use high resolution when using a single tick series to manually add the high resolution. You would need to add both a weekly series just like in the indicator so you can then successfully call the indicator as well as a 1 tick series. You would then use the single tick series to provide the higher resolution.

            This example from the help guide goes into how you can use a more granular series to provide intrabar actions so you don't need to use high order resolution:

            https://ninjatrader.com/support/help...ipt_strate.htm

            Please let us know if we may be of further assistance to you.
            Kate W.NinjaTrader Customer Service

            Comment


              #7

              thank you very much for your help i have already achieved my purpose

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by krpkevin, Today, 07:50 AM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_Jim  
              Started by robforee2, Yesterday, 06:11 PM
              2 responses
              18 views
              1 like
              Last Post NinjaTrader_ChrisL  
              Started by minds2010, Today, 03:38 AM
              1 response
              11 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by DTSSTS, Yesterday, 07:11 PM
              2 responses
              32 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by ntbone, Yesterday, 11:42 PM
              3 responses
              19 views
              0 likes
              Last Post NinjaTrader_PaulH  
              Working...
              X