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

weekly Open

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

    weekly Open

    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?

    Code:
    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);
    	}

    #2
    Hi Eklavya,

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

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

    Comment


      #3
      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.
      Attached Files

      Comment


        #4
        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.


        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?
        TimNinjaTrader Customer Service

        Comment


          #5
          Hi Tim,

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

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

          Comment


            #6
            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?

            Comment


              #7
              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/f...ad.php?t=19387
              TimNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Shansen, 08-30-2019, 10:18 PM
              24 responses
              938 views
              0 likes
              Last Post spwizard  
              Started by Max238, Today, 01:28 AM
              0 responses
              3 views
              0 likes
              Last Post Max238
              by Max238
               
              Started by rocketman7, Today, 01:00 AM
              0 responses
              1 view
              0 likes
              Last Post rocketman7  
              Started by wzgy0920, 04-20-2024, 06:09 PM
              2 responses
              27 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, 02-22-2024, 01:11 AM
              5 responses
              32 views
              0 likes
              Last Post wzgy0920  
              Working...
              X