![]() |
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
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Dec 2011
Posts: 43
Thanks: 8
Thanked 2 times in 2 posts
|
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 |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,783
Thanks: 160
Thanked 566 times in 557 posts
|
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);
}
}
Matthew
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Dec 2011
Posts: 43
Thanks: 8
Thanked 2 times in 2 posts
|
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.
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
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.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Dec 2011
Posts: 43
Thanks: 8
Thanked 2 times in 2 posts
|
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);
}
}
}
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 |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
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
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#7 | |
|
Member
Join Date: Dec 2011
Posts: 43
Thanks: 8
Thanked 2 times in 2 posts
|
You mean this line is the cause:
if (BarsPeriod.Id == PeriodType.Minute && BarsPeriod.Value > 5) return; Quote:
|
|
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
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.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |