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

Drawing zones in different time frames

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

    Drawing zones in different time frames

    Hello,

    I am working on different time frames, and i want to draw zones ( like supply && demand zones )

    for example I am in 15min Chart,
    - i want to access daily bars to draw yesterday's High and low + 2 days ago high and low
    - i want to access weekly bars to draw last week's High and low + 2 weeks ago high and low
    - i want to access monthly bars to draw last month's High and low + 2 months ago high and low
    - i want to access yearly bars to draw last year's High and low .


    i used

    -AddDataSeries(BarsPeriodType.Day, 1);
    -AddDataSeries(BarsPeriodType.Week, 1);
    -AddDataSeries(BarsPeriodType.Month, 1);
    -AddDataSeries(BarsPeriodType.Year, 1);

    and i wanted to access it with Highs[1][1] for daily bars to get Last day's High .....

    Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

    I also tried BarsArray[1].GetHigh(CurrentBar); it work but it shows this error when it comes to our current day now..

    Error on calling 'OnBarUpdate' method on bar 248: Object reference not set to an instance of an object.

    #2
    Hello pechtri,

    Using using barsAgo values, have you ensured CurrentBars[1] is greater than 1 (to access 1 bar ago)?
    Hello, I want to create an indicator that show data in a chart but calculate in other charttime different to the time of the chart where is showed. For example:


    When using .GetHigh() supply CurrentBars[1] for the proper bar number on BarsArray[1].
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      my condition is if (CurrentBars[0] < 0)


      protected override void OnBarUpdate()
      {
      //Add your custom strategy logic here.
      if (BarsInProgress != 0)
      return;

      if (CurrentBars[0] < 0)
      return;

      double highLastDay = BarsArray[1].GetHigh(CurrentBar);
      Print("High of "+ CurrentBar + " is : " + highLastDay);
      }​

      Comment


        #4
        Hello pechtri,

        This would cause an error. CurrentBars[1] is the series you are getting information from (Highs[1][1]). This means CurrentBars[1] must be greater than 1, not CurrentBars[0].

        Please review the forum post I have linked in post # 3.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Oh Thank you very much Chelsea, very generous.

          Now i want to draw a zone from that high to the current bar or more extended, similar to this
          Attached Files

          Comment


            #6
            Hello pechtri,

            If you want to render in the blank area where there are no bars, you should custom render this in OnRender().

            Below is a link to an example that renders based on bar coordinates.


            Use the chartPanel.Width for the X coordinate on the right of the chart.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thank you again chelsea for your help,

              just one more thing i could start drawing from the points like in the picture,...
              Attached Files

              Comment


                #8
                because I am on multi time frame, i need to get the bar of the daily chart

                AddDataSeries(BarsPeriodType.Day, 1);

                now im getting the price of the high and low like this :

                if ( Bars.IsFirstBarOfSession )
                {
                Zones.Clear();
                Zones.Add(new Zone("yesterday", Highs[1][0], Lows[1][0], CurrentBar));
                Zones.Add(new Zone("twoDay", Highs[1][1], Lows[1][1], CurrentBar));

                }

                the problem is with CurrentBar, i need to get the bar of the daily chart, and i don't know how

                Comment


                  #9
                  Hello pechtri,

                  CurrentBars[1] would be the CurrentBars for BarsArray[1].
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello Chelsea,

                    I getting the last week data like this

                    Zones.Add(new Zone("lastWeek", Highs[2][0], Lows[2][0], CurrentBars[2])); and when i am rendering the zone with SharpDX.RectangleF, im calculating x like this

                    int totalBarsPerWeek = ((1380 /15 ) - 5) * 5 //for 15min Chart
                    float x = ChartControl.GetXByBarIndex(ChartBars, (Zon​es[i].bar) * (totalBarsPerWeek));

                    but the problem is when in a week there is a day where the market closed early the zone start drawing before the week starts, like in the picture and if i change to 5min chart or 1 min chart it becomes worse( because i used that mathematical formula), also there is a difference in drawing between when i load 50 days and when i load 100 days in the chart,

                    so my question is there a way to start drawing from the start of the week wether is a week that has 4 days, or early closing days or whatever

                    thank you in advance,

                    Attached Files

                    Comment


                      #11
                      Hello pechtri,

                      AddDataSeries() does not add the additional series as chart bars on the chart. These are available for internal calculations in the script only, and there are no chart slots on the chart.

                      The chart bars on the chart are the primary bars only.

                      If you want to get an X value from ChartControl.GetXByBarIndex, it will need to be an index of the chart bars.

                      You can try getting the closest primary bar by the time of the additional series bar.
                      BarsArray[0].GetBar(Times[2][0])

                      You code does not specify what Zon​es[i].bar is. It looks like a list of a custom class.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        You must use NDX symbol to use the for Nasdaq, instead of NQ, it will be confusing to use NQ

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by sugalt, 04-30-2024, 04:02 AM
                        2 responses
                        13 views
                        0 likes
                        Last Post sugalt
                        by sugalt
                         
                        Started by merc410, Today, 03:41 AM
                        0 responses
                        3 views
                        0 likes
                        Last Post merc410
                        by merc410
                         
                        Started by Ndakotan1313, 03-14-2024, 05:02 PM
                        2 responses
                        60 views
                        0 likes
                        Last Post blaise_code  
                        Started by claxxical, 05-30-2017, 12:30 PM
                        37 responses
                        4,457 views
                        0 likes
                        Last Post Padan
                        by Padan
                         
                        Started by SugarDefwebsite, Today, 02:18 AM
                        0 responses
                        4 views
                        0 likes
                        Last Post SugarDefwebsite  
                        Working...
                        X