Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Relative price indicator

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

    Relative price indicator

    i want to compare the current price to the price of yesterday at a specific time. If the condition is satisfied, i should see 1 or 2 in the strategy analyzer. Seems like im missing something.

    Code:
         protected override void OnBarUpdate()
            {
                // Use this method for calculating your indicator values. Assign a value to each
                // plot below by replacing 'Close[0]' with your own formula.
              
                    DateTime myDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[1].Day, 8, 30, 0);
               
    int myBarsAgo = GetBar(myDateTime);            
                
                
                if ( Close[myBarsAgo] > Close[0])
                    
    
               
     
                    
                {zone =1;}
       
               
    else if ( Close[myBarsAgo] < Close[0])
                    
                {zone =2;}    
                    
                    
                    
                Plot0.Set(zone);
            }
    Last edited by markus1000; 03-26-2014, 10:49 AM.

    #2
    Hello Markus1000,

    Thank you for your note.

    Do you see any errors in the log tab of the Control Center?
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Error on calling 'OnBarUpdate' method for indicator 'GapZoneGold' on bar 0: Bar index needs to be greater/equal 0

      Comment


        #4
        Hello Markus1000,

        Please ensure that you incorporate a CurrentBar check into your OnBarUpdate() so that your script has enough data before calculating.

        example:
        if(CurrentBar < myBarsAgo)
        return;

        The reference sample below will explain in further detail as well -
        http://www.ninjatrader.com/support/f...ead.php?t=3170
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          i still get the same message in the console, even after adding adding

          if(CurrentBar < myBarsAgo)
          return;

          Comment


            #6
            Markus,

            Try using
            if(CurrentBar < 1) return; at the beginning of the OnBarUpdate()
            Cal H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Hwop38, 05-04-2026, 07:02 PM
            0 responses
            162 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Started by CaptainJack, 04-24-2026, 11:07 PM
            0 responses
            313 views
            0 likes
            Last Post CaptainJack  
            Started by Mindset, 04-21-2026, 06:46 AM
            0 responses
            245 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by M4ndoo, 04-20-2026, 05:21 PM
            0 responses
            350 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by M4ndoo, 04-19-2026, 05:54 PM
            0 responses
            179 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Working...
            X