Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plot Current Day Open & Previous Day High&Low levels on a intraday chart.

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

    Plot Current Day Open & Previous Day High&Low levels on a intraday chart.

    Hello,

    I try to plot current day open and previous day high and low levels on a intraday chart. Here is steps;

    1. Added 3 plots in SetDefaults state;
    AddPlot(new Stroke(Brushes.Gray, 2), PlotStyle.Hash, "DailyOpenLevel");
    AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.Hash, "DailyHighLevel");
    AddPlot(new Stroke(Brushes.Blue, 2), PlotStyle.Hash, "DailyLowLevel");

    2. Aded daily data series;
    AddDataSeries(BarsPeriodType.Day, 1);

    3.OnBarUpdate setting values;
    if (BarsInProgress == 0)
    {
    if (IsFirstTickOfBar)
    {
    DailyOpenLevel[0] = Opens[1][0];
    if (CurrentBars[1] > 0)
    {
    DailyHighLevel[0] = Highs[1][1];
    DailyLowLevel[0] = Lows[1][1];
    }
    }
    }

    But result did not happen as I imagined. I see that open level is actually previous day open. High and low levels are the day before yesterday's high and low. Could you please tell me where am I doing wrong?

    Also could you please tell me. When i add additional dataseries only with BarsPeriodType an value. Is it inherit other properties from primary dataseries? For example bars to load, trading hours and break EOD property?

    Thanks,
    Aytac

    #2
    Hello aytacasan,

    Thank you for your note.

    I'd suggest just calling the CurrentDayOHL indicator to retrieve those values rather than getting them from a daily data series.

    For example:

    DailyHighLevel[0] = CurrentDayOHL().CurrentHigh[0];
    DailyLowLevel[0] = CurrentDayOHL().CurrentLow[0];

    You can certainly get this from daily bars - your issue is that you're referring to the previous day bar's values. Instead you'd want to refer to the current bar like so:

    DailyHighLevel[0] = Highs[1][0];
    DailyLowLevel[0] = Lows[1][0];

    As far as using AddDataSeries with just specifying the BarsPeriodType and period value, yes, it would inherit the primary data series other values.

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

    Comment


      #3
      Dear Kate,

      It's only sample code sample indicator. I'm also interested in week's and month's open/high/low values so your CurrentDayOHL suggestion not enough for me. Please tell me why added dataseries current bar pointing previous bar and previous bar pointing the day before yesterday although indicator working OnPriceChange calculation mode? Please look at my attachment.

      Also note that;
      OpenLevel is the current session open value.
      HighLevel&LowLevel are the previous session high&low.

      Plus, Could you please tell me why you said that "just calling the CurrentDayOHL indicator to retrieve those values rather than getting them from a daily data series." What i know ninjatrader daily bars consolidated from minutes bars so intraday and daily bars are must be sync. Reason is only for simplicity or there is another important issue?

      Plus, I look at CurrentDayOHL indicator source code and convert it to the shape i want. So what is your suggestion how can i draw same values for weekly and monthly bars.
      Attached Files
      Last edited by aytacasan; 03-05-2021, 07:07 AM.

      Comment


        #4
        Hello,

        Thank you for your reply.

        You're likely seeing the previous day's values plotted until the indicator reaches real time data. This is due to the fact that on historical data, indicators are only able to calculate OnBarClose. Turning on Tick Replay will allow the indicator to calculate OnPriceChange. The advantage of using the Current Day OHL indicator here would be that it does not require TickReplay to function as it calculates on intraday data unlike using an added daily series.

        The fact that TickReplay is necessary to get the currently forming bar values from the additional data series becomes problematic when it comes to weekly or monthly bars - many data providers only offer certain amounts of tick data and some restrict your ability to receive large amounts of historical tick data during trading hours - for example, Kinetick connections restrict you to 7 days of tick data during trading hours. You may simply not be able to retrieve enough tick data to plot over such a lengthy time frame.

        That being said, on real time data, even without tick replay enabled, you should be able to use Daily/Weekly/Monthly bars and see them plot the current values, it's just on historical data where it's an issue.

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

        Comment


          #5
          Hello Kate,

          Thanks for your explanations.I wrote new indicator for daily levels with help CurrentDayOHL indicator. Any idea how can i catch weekly and monthly levels like daily levels. My opinion i can store week/month number to a variable and when they change, plot values on a chart.

          Is there a helper method that tell me you are entering new trading week/month?

          Thanks

          Comment


            #6
            Hello aytacasan,

            Thank you for your reply.

            For the month, you can compare to ensure the current bar's month is not the same as the previous bar's month:

            if (Time[0].Month != Time[1].Month)
            {
            // do something
            }

            Getting the week number of the month will require custom programming in C#. There is no supported method in NinjaScript to pull the Week's number.

            There are different ideas on how to get the week number, I would suggest doing a quick search on "C# get week number" online.

            Please let me know if I may be of further assistance.
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              Hello Kate,

              Determine current day and mounth is easy and problem is week. Actually i wrote necessary code for detect current week also. I asked question because i'm worry about is it the right way to find current week. My code like that;

              var date = sessionIterator.GetTradingDay(Time[0]);
              var weekOfYear = CultureInfo.InvariantCulture.Calendar.GetWeekOfYea r(date, CalendarWeekRule.FirstDay, DayOfWeek.Saturday);

              1. Use invariant culture is the right choice? or i have to use current culture or crete a new culture like that new CultureInfo("es-ES", false)?
              2. What is the right rule for CalendarWeekRule? FirstDay is the right one or i have to use FirstFourDayWeek or FirstFullWeek? Is it dependenr ot not to instrumen's trading hours/timezone?
              3. I'm using Saturday for DayOfWeek enum. Is this right way or for different instruemnt i have to use variable value?

              Thanks for your help

              Comment


                #8
                Hello aytacasan,

                Thank you for your reply.

                I'd recommend checking out the Microsoft Documentation on GetWeekOfYear which is publicly available here:

                https://docs.microsoft.com/en-us/dot...kofyear?view=n etframework-4.7

                ​​​​​​​The "correct" way to do this is somewhat debatable and you will need to decide for yourself which options you wish to use to calculate the week of the year. The culture you use is up to you. Invariant culture has the benefit of being standardized so you can format according to a particular culture later if you like.

                There's not a "right" option for CalendarWeekRule either. Here's the publicly available documentation from Microsoft on that:

                https://docs.microsoft.com/en-us/dot...tframework-4.7

                Generally in the US we would count from Sunday being the first day of the week. However, the choice here would be yours as when you'd like the week to begin as well.

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

                Comment


                  #9
                  Hello Kate,

                  I know that documentations. I'm not trying to learn c# from Ninjatrader forum. My questions related Ninjatrader and it's internals. I want to follow same parh so my indicators works on any market any instrument like ninja. For example you said that "we would count from Sunday being the first day of the week". But if you open BTCUSD chart you'll see friday is the last day of the week. Is this because of coin maket or ninjatrader or my regional settings i don't know. Anyway i get my questions back. I'll learn my self.

                  Thanks.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by TigerKiger, Today, 01:12 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post TigerKiger  
                  Started by tonynt, Today, 12:46 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post tonynt
                  by tonynt
                   
                  Started by ntdev, Today, 12:19 PM
                  0 responses
                  3 views
                  0 likes
                  Last Post ntdev
                  by ntdev
                   
                  Started by RubenCazorla, Today, 12:02 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post RubenCazorla  
                  Started by pkr75, Today, 11:03 AM
                  1 response
                  9 views
                  0 likes
                  Last Post pkr75
                  by pkr75
                   
                  Working...
                  X