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 Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            571 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            331 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            549 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            549 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X