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

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 Rapine Heihei, Yesterday, 07:51 PM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by kaywai, Today, 06:26 AM
            1 response
            6 views
            0 likes
            Last Post kaywai
            by kaywai
             
            Started by ct, 05-07-2023, 12:31 PM
            6 responses
            205 views
            0 likes
            Last Post wisconsinpat  
            Started by kevinenergy, 02-17-2023, 12:42 PM
            118 responses
            2,780 views
            1 like
            Last Post kevinenergy  
            Started by briansaul, Today, 05:31 AM
            0 responses
            10 views
            0 likes
            Last Post briansaul  
            Working...
            X