• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

prevoius week HL on smaller TF chart

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

    prevoius week HL on smaller TF chart

    Hi,

    I'm trying to show previous weeks H/L on a 5min chart.
    All charts are done in market replay.

    This is how the indicator should print (H/L of ONE week ago)
    http://screencast.com/t/klhdydlvZ1Cd

    This is what I get after a couple of bars on Monday. The HL is from TWO weeks ago.
    http://screencast.com/t/wvzpai76He

    If I press F5 to reload the NT script and start replay again I get this
    http://screencast.com/t/363ZL65IjOA
    The levels are ok again.

    What is wrong here. I'm attaching the indicator for review.
    I really would appreciate a clarification here.

    Thomas
    Attached Files

    #2
    I believe this has to do with the BIP and CurrentBars error handling you are using.

    I have simplified your script to only check for BIP on the main series and to only return if there is less than 1 Weekly bar.

    After running this on market replay, I did not have to reload NinjaScript in order to update these values. Please let me know if this does not work the same for you.

    Code:
    protected override void OnBarUpdate()
            {
    			
    			if (BarsPeriod.Id == PeriodType.Minute && BarsPeriod.Value > 5) return;
    			if (BarsInProgress == 0)
    			{
    			
    				bool showHLCY = true;
    				if(CurrentBars[1] < 1) return;
    			
    				if (showHLCY==true)
    				{
    					PriorWeekHigh = Highs[1][1]; PriorWeekLow = Lows[1][1];
    					int BarsBack = 5*81;
    					if (Time[0].DayOfWeek == DayOfWeek.Monday)		BarsBack = 5*81;
    					if (Time[0].DayOfWeek == DayOfWeek.Tuesday)		BarsBack = 6*81;
    					if (Time[0].DayOfWeek == DayOfWeek.Wednesday)	BarsBack = 7*81;
    					if (Time[0].DayOfWeek == DayOfWeek.Thursday)	BarsBack = 8*81;
    					if (Time[0].DayOfWeek == DayOfWeek.Friday)		BarsBack = 9*81;
    					DrawLine("PriorWeekHigh", false, Bars.BarsSinceSession+BarsBack, PriorWeekHigh, -3, PriorWeekHigh, Color.Red, DashStyle.Dash, 2);
    					DrawText("PriorWeekHighText", false, "H1W", -5, PriorWeekHigh-2*TickSize, 0, Color.Red, new Font ("Arial", 10), StringAlignment.Center, Color.Empty, Color.Empty, 0);
    					DrawLine("PriorWeekLow", false, Bars.BarsSinceSession+BarsBack, PriorWeekLow, -3, PriorWeekLow, Color.Red, DashStyle.Dash, 2);
    					DrawText("PriorWeekLowText", false, "L1W", -5, PriorWeekLow+2*TickSize, 0, Color.Red, new Font ("Arial", 10), StringAlignment.Center, Color.Empty, Color.Empty, 0);
    				}
    				
    			}
    MatthewNinjaTrader Product Management

    Comment


      #3
      Matthew, Thanks for your reply.

      I added this line within the BIP==0 condition "if(CurrentBars[0] < 2000) return; " because of the lines I draw in the script.

      This is what I get if I connect to Vision - again H/L of TWO weeks ago:
      http://screencast.com/t/QcjzLTpn

      Market Replay produces this and I have to restart NT:
      http://screencast.com/t/C0syI5uY

      Code:
              protected override void OnBarUpdate()
              {
                  
                  if (BarsPeriod.Id == PeriodType.Minute && BarsPeriod.Value > 5) return;
                  
                  if (BarsInProgress == 0)
                  {
                  
                      bool showHLCY = true;
                      
                      if(CurrentBars[1] < 3) return;
                      if(CurrentBars[0] < 2000) return;
                  
                      if (showHLCY==true)
                      {
                          PriorWeekHigh = Highs[1][1]; PriorWeekLow = Lows[1][1];
                          int BarsBack = 5*81;
                          if (Time[0].DayOfWeek == DayOfWeek.Monday)        BarsBack = 5*81;
                          if (Time[0].DayOfWeek == DayOfWeek.Tuesday)        BarsBack = 6*81;
                          if (Time[0].DayOfWeek == DayOfWeek.Wednesday)    BarsBack = 7*81;
                          if (Time[0].DayOfWeek == DayOfWeek.Thursday)    BarsBack = 8*81;
                          if (Time[0].DayOfWeek == DayOfWeek.Friday)        BarsBack = 9*81;
                          DrawLine("PriorWeekHigh", false, Bars.BarsSinceSession+BarsBack, PriorWeekHigh, -3, PriorWeekHigh, Color.Red, DashStyle.Dash, 2);
                          DrawText("PriorWeekHighText", false, "H1W", -5, PriorWeekHigh-2*TickSize, 0, Color.Red, new Font ("Arial", 10), StringAlignment.Center, Color.Empty, Color.Empty, 0);
                          DrawLine("PriorWeekLow", false, Bars.BarsSinceSession+BarsBack, PriorWeekLow, -3, PriorWeekLow, Color.Red, DashStyle.Dash, 2);
                          DrawText("PriorWeekLowText", false, "L1W", -5, PriorWeekLow+2*TickSize, 0, Color.Red, new Font ("Arial", 10), StringAlignment.Center, Color.Empty, Color.Empty, 0);
                      }
                      
                  }
      
              }
      Last edited by td_910; 08-07-2012, 01:50 AM.

      Comment


        #4
        Hello td_910,
        Thanks for your note and I am replying for Matthew.

        Unfortunately I cannot replicate the error.

        Can you please tell me a step-by-step procedure to replicate the scenario.

        Also please make sure you have enough replay/historical data.

        I look forward to assisting you further.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Hi Joydeep,

          this is the code I use:

          Code:
                  protected override void Initialize()
                  {
                      Add(PeriodType.Week, 1);
                      CalculateOnBarClose    = false;  Overlay = true;  PriceTypeSupported = false;  ZOrder = 600;
                      AutoScale = false;
                  }
          
                  protected override void OnBarUpdate()
                  {
                      
                      if (BarsPeriod.Id == PeriodType.Minute && BarsPeriod.Value > 5) return;
                      
                      if (BarsInProgress == 0)
                      {
                      
                          bool showHLCY = true;
                          
                          if(CurrentBars[1] < 5) return;
                          if(CurrentBars[0] < 2000) return;
                      
                          if (showHLCY==true)
                          {
                              PriorWeekHigh = Highs[1][1]; PriorWeekLow = Lows[1][1];
                              int BarsBack = 5*81;
                              if (Time[0].DayOfWeek == DayOfWeek.Tuesday)        BarsBack = 6*81;
                              if (Time[0].DayOfWeek == DayOfWeek.Wednesday)    BarsBack = 7*81;
                              if (Time[0].DayOfWeek == DayOfWeek.Thursday)    BarsBack = 8*81;
                              if (Time[0].DayOfWeek == DayOfWeek.Friday)        BarsBack = 9*81;
                              DrawLine("PriorWeekHigh", false, Bars.BarsSinceSession+BarsBack, PriorWeekHigh, -3, PriorWeekHigh, Color.Red, DashStyle.Dash, 2);
                              DrawText("PriorWeekHighText", false, "H1W", -5, PriorWeekHigh-2*TickSize, 0, Color.Red, new Font ("Arial", 10), StringAlignment.Center, Color.Empty, Color.Empty, 0);
                              DrawLine("PriorWeekLow", false, Bars.BarsSinceSession+BarsBack, PriorWeekLow, -3, PriorWeekLow, Color.Red, DashStyle.Dash, 2);
                              DrawText("PriorWeekLowText", false, "L1W", -5, PriorWeekLow+2*TickSize, 0, Color.Red, new Font ("Arial", 10), StringAlignment.Center, Color.Empty, Color.Empty, 0);
                          }
                          
                      }
          
                  }
          I switched the time frame to weekly before attaching the indicator.
          http://screencast.com/t/1I7bkrlc

          This is what I get, if I attach it to the same chart (today's live chart with RTH session template)
          http://screencast.com/t/gP3ScrA9w

          The blue lines show the proper levels.

          I have replay data reaching back to 6/8.

          Cheers

          Thomas

          Comment


            #6
            Hello td_910,
            The attached screenshot depicts what I get if I am not connected to my data feed (i.e. bars are evaluated only on historical bars) and when I am connected to my data feed.

            When you are not connected then the most recent weekly bar is never evaluated. This is because the bars array in the primary series are built first, and the secondary bars are then built subsequently. You are filtering your code with the BarsInProgress property (rightly so). However the primary series never gets triggered once the LAST weekly bar forms and thus your code never gets evaluated for the latest weekly bar.

            Once you get connected this anomaly gets rectified (as the primary bar series gets updated again).

            Please refer to our help guide to know more about how the bars are referenced etc
            http://www.ninjatrader.com/support/h...nstruments.htm
            Attached Files
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              You mean this line is the cause:

              if (BarsPeriod.Id == PeriodType.Minute && BarsPeriod.Value > 5) return;

              Originally posted by NinjaTrader_Joydeep View Post
              Hello td_910,
              The attached screenshot depicts what I get if I am not connected to my data feed (i.e. bars are evaluated only on historical bars) and when I am connected to my data feed.

              When you are not connected then the most recent weekly bar is never evaluated. This is because the bars array in the primary series are built first, and the secondary bars are then built subsequently. You are filtering your code with the BarsInProgress property (rightly so). However the primary series never gets triggered once the LAST weekly bar forms and thus your code never gets evaluated for the latest weekly bar.

              Once you get connected this anomaly gets rectified (as the primary bar series gets updated again).

              Please refer to our help guide to know more about how the bars are referenced etc
              http://www.ninjatrader.com/support/h...nstruments.htm

              Comment


                #8
                Hello td_910,
                No, the code is fine.

                It is how Bars Array are called in an multi-series NinjaScript code that matters

                Say you are watching a minute chart then the OnBarUpdate event is processed as such:

                All the Minute bar (from week start to week end) is updated (you codes gets evaluated here)
                One weekly bar gets updated
                All the Minute bar (from week start to week end) is updated (you codes gets evaluated here)
                One weekly bar gets updated
                .....
                {in the last week}
                All the Minute bar (from week start to week end) is updated (you codes gets evaluated here)
                One weekly bar gets updated (the weekly bar is not evaluated by your code).


                The last weekly bar series never gets updated when you are NOT connected to your data feed provider.
                JoydeepNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Papercut110, Today, 09:08 PM
                0 responses
                2 views
                0 likes
                Last Post Papercut110  
                Started by iq200, 11-09-2019, 08:26 AM
                5 responses
                56 views
                0 likes
                Last Post koganam
                by koganam
                 
                Started by johng964, Today, 02:57 PM
                1 response
                11 views
                0 likes
                Last Post NinjaTrader_RyanS  
                Started by spamula, Today, 03:00 PM
                2 responses
                16 views
                0 likes
                Last Post spamula
                by spamula
                 
                Started by MARTIN MARTIN, Today, 01:01 PM
                0 responses
                16 views
                0 likes
                Last Post MARTIN MARTIN  
                Working...
                X