Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Script runs to a point...

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

    Script runs to a point...

    In this line:

    Code:
    StudyBar = GetBar(Time[0].AddMinutes(-30));
    an interesting thing can happen, if I am using a tick series... if there are no ticks for 30 minutes the line will create an error: "Object reference not set to an instance of an object"

    I understand why the error occurs, my problem is how to get around it... Any suggestions?
    Last edited by Sleeping Troll; 04-17-2010, 10:01 AM. Reason: Isolated problem

    #2
    Sleeping Troll, you will need to check how much time there is between the bar you're currently running calculations on and the first bar. If that value is greater than 30 minutes, you can run that bit of code. If the value is less than 30 minutes, just skip it for now until there are enough bars.

    There is a reference sample that deals with manipulating time that you will probably find useful.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Thx Austin, haven't used Time Date this much since CPM and Dbase!

      Comment


        #4
        Every which way but loose on this!

        Code:
                protected override void OnBarUpdate()
                {
        			if(DateTime.Compare(Time[0].AddMinutes(-30),Time[1]) != 1)
        			{
        				StudyBar = GetBar(Time[0].AddMinutes(-30));
        			}
        			DrawLine("Slope",StudyBar,Open[StudyBar],0,Open[0],Color.Gray,DashStyle.Dot,3);
        			if (CurrentBar <1)return;
        			if (Filled == null && LongRunner != null && Math.Abs(EntryPrice - Input[0]) > (6 * TickSize))
        			{
        				CancelOrder(LongRunner);
        				OrderPending = null;
        			}
        			if (Filled == null && LongBank != null && Math.Abs(EntryPrice - Input[0]) > (6 * TickSize))
        			{
        				CancelOrder(LongBank);
        				OrderPending = null;
        			}
        			if (Filled == null && ShortRunner != null && Math.Abs(EntryPrice - Input[0]) > (6 * TickSize))
        			{
        				CancelOrder(ShortRunner);
        				OrderPending = null;
        			}
        			if (Filled == null && ShortBank != null && Math.Abs(EntryPrice - Input[0]) > (6 * TickSize))
        			{
        				CancelOrder(ShortBank);
        				OrderPending = null;
        			}
        			period = 14;
        			Fast = 6;
        			Slow = 13;
        			Smooth = 9;
        			numStdDev = 2;
        			Upper = Fibs().CurrentChannelUpper;
        			Lower = Fibs().CurrentChannelLower;
        			if (Slope(Open,StudyBar,0) > 0)
        Seems no matter what I try, I still get "Object reference not set to an instance of object" whenever I have no ticks for 30 minutes.

        Comment


          #5
          Sleeping Troll, please try comparing the 30 minute subtraction to Time[0] instead of Time[1].
          AustinNinjaTrader Customer Service

          Comment


            #6
            thx Austin, got it figured out, just a matter of get comfy with NJ objects and methods.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            648 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            108 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            572 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            573 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X