PDA

View Full Version : weekly Open


Eklavya
07-08-2010, 07:18 AM
Hi,

I am trying to write a simple indicator to plot weekly open lines but am getting a run time error on index. Can someone help me here please?

protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "CurrentOpen"));
Add(PeriodType.Minute, 10080);
CalculateOnBarClose = false;
Overlay = true;
}

protected override void OnBarUpdate()
{
double currentOpen;
if (CurrentBars[1] < 1)
return;

currentOpen=Opens[1][0];
if (ShowOpen)
CurrentOpen.Set(currentOpen);
}

NinjaTrader_Tim
07-08-2010, 08:08 AM
Hi Eklavya,

Try add a CurrentBars check for the primary series as well.

Perhaps...
if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
return;

Eklavya
07-08-2010, 09:22 AM
Hi Tim,

Thanks..this solved the runtime problem. However I am getting another issue.

My indicator is just supposed to plot a horizontal line at the daily open. But what is happening is that for the current bar in progress, it is getting the properly daily open value from Opens[1][0] but for the past bars it is getting the value of Opens[1][1] (previous days open).

You can see it evident in the attached screenshot. For the current bar in progress, it is getting the open value of the latest in progress daily bar but for the previous bar, it gets the open value of the previous days bar.

FYI..I have superimposed a daily chart of the 4hr chart in the attached screenshot so the problem is clear.

I also have a second issue...I actually want to plot weekly open but when I add a new data series of 10080 mins, it is adding the 1440 min data series and not the 10080 min.

NinjaTrader_Tim
07-08-2010, 11:06 AM
Hi Eklavya,

Can you try changing your CalculateOnBarClose setting in the Initialize() section of your code, that is likely causing the different in live vs. historical plotting.
http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?CalculateOnBarClose1

Sounds like it's set to false now, try setting this to true to see the difference.

Is this using NT7? What provider are you connected to?

Eklavya
07-08-2010, 11:31 AM
Hi Tim,

I am on NT7 and using GAIN as the data provider.

Setting CalculateOnBarClose to true does not make any difference...

Eklavya
07-08-2010, 11:49 AM
I think I found the issue but not sure how to correct it. When the indicator runs for the first time, the behavior of the indicator is the same as the code CalculateOnBarClose=true. So when add daily dataseries to the 4Hr dataseries here is what happens.

When the first bar of the day on the 4Hr chart begins, at this time Opens[1][0] = open of the previous day as at this time the daily bar for today has not yet formed. the daily bar is formed only at the end of the day for historical data. Hence the issue with my indicator.

Do you have any ideas as to how to fix it?

NinjaTrader_Tim
07-08-2010, 12:47 PM
Hi Eklavya,

With CalculateOnBarClose = true, this is expected, however, you may find it useful in this case to use COBC = false, then separate necessary sections to operate as if COBC=true.

This is done in this example - http://www.ninjatrader.com/support/forum/showthread.php?t=19387