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

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)
    Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


    This is what I get after a couple of bars on Monday. The HL is from TWO weeks ago.
    Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


    If I press F5 to reload the NT script and start replay again I get this
    Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.

    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:
      Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


      Market Replay produces this and I have to restart NT:
      Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


      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, 02: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.


          This is what I get, if I attach it to the same chart (today's live chart with RTH session template)
          Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


          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
            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 algospoke, Yesterday, 06:40 PM
                2 responses
                23 views
                0 likes
                Last Post algospoke  
                Started by ghoul, Today, 06:02 PM
                3 responses
                14 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by jeronymite, 04-12-2024, 04:26 PM
                3 responses
                45 views
                0 likes
                Last Post jeronymite  
                Started by Barry Milan, Yesterday, 10:35 PM
                7 responses
                22 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by AttiM, 02-14-2024, 05:20 PM
                10 responses
                181 views
                0 likes
                Last Post jeronymite  
                Working...
                X