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

Need little help

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

    Need little help

    Hello programer masters

    Just created simple code. If is bar inside , there is draw text on mother candel.
    I have few simillar codes, really nothing avarage.
    Can u tell me what ist does mean ?

    Error on calling 'OnBarUpdate' method for indicator 'M5b' on bar 0: Mother50back.DrawText: startBarsAgo out of valid range 0 through 0, was 1.

    Failed to get property 'AnotherChart' for indicator '': Object reference not set to an instance of an object.

    any ideas ?

    Many Thanks
    Jake

    #2
    Hello,

    thank you for the question.

    Error on calling 'OnBarUpdate' method for indicator 'M5b' on bar 0: Mother50back.DrawText: startBarsAgo out of valid range 0 through 0, was 1.
    This first message is letting you know that in your call to DrawText, the amount of bars ago you are requesting is not yet loaded on the chart.

    For example you call this DrawText on bar 0, and it is trying to start 5 bars ago. 5 bars have not yet been loaded so this would be looking for an index location of -5 which will never exist and causes the error.

    You will need to check for bars before executing this code, for example:

    Code:
    [B]if(CurrentBar < 10) return;[/B]
    DrawText("MyText", "Sample text", [B]10[/B], High[0], Color.Blue);
    Because in this example I am requesting the drawtext 10 bars ago, I prevent the script from processing until I have 10 bars.

    For your next question:
    Failed to get property 'AnotherChart' for indicator '': Object reference not set to an instance of an object.
    This indicates that something is not set when you are checking it, this more than likely would be related to the line of code that contains "AnotherChart". If you would like to post the section of code or whole code I could take a look and see if I can see the error on this.
    Otherwise you need to ensure the object you are checking has a value before you are checking it.

    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      My set up is Text[1] . Just couldn't configure where is problem.
      Please see my PA code

      Code:
      {	// Condition set 1
                  	if (Low[1] < Low[0]
                     		&& High[1] < High[0]
                     		&& Close[1] > Close[0])
      					
                 		 	{    
                      		DrawText("My text" + CurrentBar, "X", 1, High[1] + 3 * TickSize, Color.Red);
                 			}
      			
      			// Condition set 2
      			
      				if (Low[1] < Low[0]
                      	&& High[1] < High[0]
                      	&& High[1] > Close[0]
      					&& Close[0] > Close[1])
      				
                 			 {
                     			 DrawText("My text" + CurrentBar, "X", 1, High[1] + 3 * TickSize, Color.Red);
                 			 }
      					
      			
      			
      			
      			// Condition set 4
                  	if (Low[0] < Low [1]
      					&& Close[0] > Close[1]
      					&& Close[0] <= High[1])
      				
                  
                    		{
                     		 DrawText("My text" +CurrentBar, "X", 1, Low[1] - 3 * TickSize, Color.YellowGreen);
                  		}
      			
      			// Condition set 5
      				if (Low[0] > Low[1]
      					&& High[0] < High[1])
      			
      					{
                     		 DrawText("My text" +CurrentBar, "M", 1, Low[1] - 3 * TickSize, Color.White);
               			}	
      				
      				
      			// Condition set 6	
      				
      				if (Low[0] > Low[1]
      					&& High[1] >= Close[0]	
      					&& High [0] > High [1])
      				
      					{
                    		  DrawText("My text" + CurrentBar, "T", 1, Low[1] - 3 * TickSize, Color.White);
               			}
      				
      			// Condition set 7
      				
      				if (High[1] > High[0]
      					&& Low[1] >= Close[0]
      					&& Low[0] > Low[1])
      				
      					{
                    		  DrawText("My text" + CurrentBar, "T", 1, High[1] + 3 * TickSize, Color.White);
               			}
      				
      				// Condition set 8 Mother Candel and second bar with opening gap	
      				
      				if (Low[0] > Low[1]
      					&& High[1] >= Close[0]	
      					&& High [0] > High [1]
      					&& Close[1] > Open[0] || Close[1] < Open[0])
      				
      					{
                     		 DrawText("My text" + CurrentBar, "G", 1, High[1] + 5 * TickSize, Color.Pink);
               			}
      							
              }

      Comment


        #4
        Hello,

        Thank you for the script.

        I copied what you have and placed this in the OnBarUpdate of a blank indicator and did get the error you were.

        This is related to what I had previously posted about.

        In your code you are referencing prior bars in your conditions, these prior bars will not exist when you start the script up initially. You need to check for this otherwise you get the error you are listing.

        All I have done is added the following to the top of OnBarUpdate after the brace you have in your example. I have included the // Condition set 1 so you can see exactly where in the script I am speaking of.
        Code:
        {	
         if (CurrentBar < BarsRequired) return;
        // Condition set 1
        This tells the script, if the CurrentBar is less than the BarsRequired (defaults to 20) then do not do anything.

        This will prevent the error because now on bar 20, bar 19 will exist, you are looking back 1 bar in your conditions so at least 1 bar needs to be loaded before doing your check.

        Please let me know if I may be of additional assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Yes, It works . Thank you very much. There is one more question I would like write my self code for %. I mean if current candle close 50% below previous candle. Where can I study or find how to write this code ? I mean is there any written lines already or I have to ask programmers for complete this request ? anything

          Thank you very much
          jake

          Comment


            #6
            Originally posted by Jakub View Post
            Yes, It works . Thank you very much. There is one more question I would like write my self code for %. I mean if current candle close 50% below previous candle. Where can I study or find how to write this code ? I mean is there any written lines already or I have to ask programmers for complete this request ? anything

            Thank you very much
            jake
            Very quickly because I'm in a rrrrrrrush but is this what you're looking for?

            Code:
            double p = (Close[0] - Low[1]) / (High[1] - Low[1]) * 100;
            This should give you a positive or negative %, with the previous Low[1] = 0% and the previous High[1] = 100%.

            (Substitute Close and Open or High and Low if this is what you want.)

            Hope this helps.
            Last edited by arbuthnot; 02-01-2015, 12:08 PM.

            Comment


              #7
              Hello Jakub,

              Thank you for your post.

              You could use the following code to check the current close is less than the previous low minus half the range of the previous bar.
              Code:
              			if(Close[0] < (Low[1]-(High[1]-Low[1]/2)))
              			{
              				// Do something.
              			}

              Comment


                #8
                Thank you so much! Just bit change this code. Finally
                Code:
                if[FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]( (Close[
                [FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]] < (High[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]]-Low[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]])/[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]+Low[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]])[/COLOR][/SIZE][/FONT][/SIZE][/FONT]
                [FONT=Courier New][COLOR=#000000]+ my rules[/COLOR][/FONT]
                [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
                Thank you for your time and for sharing your experiences. I really appreciates.

                Have nice day for all
                Jake

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by AveryFlynn, Today, 04:57 AM
                1 response
                10 views
                0 likes
                Last Post NinjaTrader_Erick  
                Started by Max238, Today, 01:28 AM
                4 responses
                37 views
                0 likes
                Last Post Max238
                by Max238
                 
                Started by r68cervera, Today, 05:29 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by geddyisodin, Today, 05:20 AM
                1 response
                11 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by timko, Today, 06:45 AM
                2 responses
                14 views
                0 likes
                Last Post NinjaTrader_ChristopherJ  
                Working...
                X