NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 08-06-2012, 04:53 PM   #1
td_910
Member
 
Join Date: Dec 2011
Posts: 43
Thanks: 8
Thanked 2 times in 2 posts
Angry 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
File Type: cs a0weeklyHL.cs (7.1 KB, 8 views)
td_910 is offline  
Reply With Quote
Old 08-06-2012, 06:29 PM   #2
NinjaTrader_Matthew
NinjaTrader Customer Service
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,783
Thanks: 160
Thanked 566 times in 557 posts
Default

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);
				}
				
			}
NinjaTrader_Matthew is offline  
Reply With Quote
Old 08-07-2012, 02:43 AM   #3
td_910
Member
 
Join Date: Dec 2011
Posts: 43
Thanks: 8
Thanked 2 times in 2 posts
Default

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 at 02:50 AM.
td_910 is offline  
Reply With Quote
Old 08-07-2012, 06:08 AM   #4
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

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.
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 08-07-2012, 06:45 AM   #5
td_910
Member
 
Join Date: Dec 2011
Posts: 43
Thanks: 8
Thanked 2 times in 2 posts
Default

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
td_910 is offline  
Reply With Quote
Old 08-07-2012, 07:39 AM   #6
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

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 Images
File Type: jpg Before connecting.jpg (113.0 KB, 0 views)
File Type: jpg After connecting.jpg (115.4 KB, 0 views)
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 08-07-2012, 10:37 AM   #7
td_910
Member
 
Join Date: Dec 2011
Posts: 43
Thanks: 8
Thanked 2 times in 2 posts
Default

You mean this line is the cause:

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

Quote:
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
td_910 is offline  
Reply With Quote
Old 08-07-2012, 11:14 AM   #8
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

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.
NinjaTrader_Joydeep is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HH & HL Indicator TraderGuy NinjaScript File Sharing Discussion 21 01-08-2013 04:47 AM
One minute chart for more than a week arnonmoscona Charting 4 12-19-2011 02:50 PM
Different TF in one chart michi08 Charting 2 05-23-2011 09:48 AM
TF chart not updating Folls Charting 6 01-20-2010 11:36 AM
Why can't chart TF? max1ci6 Miscellaneous Support 1 04-15-2009 10:35 AM


All times are GMT -6. The time now is 01:47 PM.