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

Strange Problem On NJ7 Compiled Indicator

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

    Strange Problem On NJ7 Compiled Indicator

    Good Morning

    I have a strange problem.

    I copied and paste text of a test indicator that I have on NJ7 in an old PC.

    Steps

    1) Created new indicator MyCustomIndicator
    2) DELETED all the source code and stuck the My Old Source Code
    3) Compiled 100% succesfull
    4) I cannot found file MyCustomIndicator3 for attach to the chart

    I posted some scrcreenshot about this strange think

    Why in the Indicator List I cannot found the file 100% compiled?
    Attached Files

    #2
    Hello ketron82, and thank you for your question. In your new file, find the line of code that reads

    Code:
    [FONT=Courier New]    public class MyCustomIndicator: Indicator[/FONT]
    Change this to

    Code:
    [FONT=Courier New]    public class MyCustomIndicator[B]3[/B]: Indicator[/FONT]
    Please let us know if there is any other way we can help.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_JessicaP View Post
      Hello ketron82, and thank you for your question. In your new file, find the line of code that reads

      Code:
      [FONT=Courier New]    public class MyCustomIndicator: Indicator[/FONT]
      Change this to

      Code:
      [FONT=Courier New]    public class MyCustomIndicator[B]3[/B]: Indicator[/FONT]
      Please let us know if there is any other way we can help.
      oohh great

      Many thanks..YESS...exactly...copy and paste .....copy and paste ahhaha I forgot to rename the text of

      public class: indicator

      Again Many Thanks

      P.s. I have another question

      I SEE THIS ERROR
      Error on calling 'OnMarketDepth' method for indicator 'MyCustomIndicator': You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

      Code:
              protected override void OnMarketDepth(MarketDepthEventArgs e)
              {
      		
      			//Print("DENTRO funziona market depth");
      				for (int idx = 0; idx < askRows.Count; idx++)
      					{
      						//Print("Ask Price=" + askRows[idx].Price + " Volume=" + askRows[idx].Volume + " Position=" + idx);
      				      
      						if (1==1)
      						{
      						DrawText("Bar"+ CurrentBar,"#",1,High[0]+TickSize*2,Color.Blue);
      						}			
      						if (askRows[idx].Volume<200)
      						{
      						DrawText("Bar2"+ CurrentBar,"X",1,High[0]+TickSize*3,Color.Blue);
      						}	
      						
      						
      				
      						
      						
      					}
      		
      			
      			List<LadderRow> rows = null;
      
      			// Checks to see if the Market Data is of the Ask type
      			if (e.MarketDataType == MarketDataType.Ask)
      			{
      				rows = askRows;
      				
      				// Due to race conditions, it is possible the first event is an Update operation instead of an Insert. When this happens, populate your Lists via e.MarketDepth first.
      				if (firstAskEvent)
      				{
      					if (e.Operation == Operation.Update)
      					{
      						// Lock the MarketDepth collection to prevent modification to the collection while we are still processing it
      						lock (e.MarketDepth.Ask)
      						{
      							for (int idx = 0; idx < e.MarketDepth.Ask.Count; idx++)
      								rows.Add(new LadderRow(e.MarketDepth.Ask[idx].Price, e.MarketDepth.Ask[idx].Volume, e.MarketDepth.Ask[idx].MarketMaker));
      						}
      					}
      					firstAskEvent = false;
      				}
      			}
      			
      			// Checks to see if the Market Data is of the Bid type
      			else if (e.MarketDataType == MarketDataType.Bid)
      			{
      				rows = bidRows;
      				
      				// Due to race conditions, it is possible the first event is an Update operation instead of an Insert. When this happens, populate your Lists via e.MarketDepth first.
      				if (firstBidEvent)
      				{
      					if (e.Operation == Operation.Update)
      					{
      						// Lock the MarketDepth collection to prevent modification to the collection while we are still processing it
      						lock (e.MarketDepth.Bid)
      						{
      							for (int idx = 0; idx < e.MarketDepth.Bid.Count; idx++)
      								rows.Add(new LadderRow(e.MarketDepth.Bid[idx].Price, e.MarketDepth.Bid[idx].Volume, e.MarketDepth.Bid[idx].MarketMaker));
      						}
      					}
      					firstBidEvent = false;
      				}
      			}
      
      			if (rows == null)
      				return;
      
      			// Checks to see if the action taken was an insertion into the ladder
      			if (e.Operation == Operation.Insert)
      			{
      				// Add a new row at the end if the designated position is greater than our current ladder size
      				if (e.Position >= rows.Count)
      					rows.Add(new LadderRow(e.Price, e.Volume, e.MarketMaker));
      				
      				// Insert a new row into our ladder at the designated position
      				else
      					rows.Insert(e.Position, new LadderRow(e.Price, e.Volume, e.MarketMaker));
      			}
      			
      			/* Checks to see if the action taken was a removal of itself from the ladder
      			Note: Due to the multi threaded architecture of the NT core, race conditions could occur
      			-> check if e.Position is within valid range */
      			else if (e.Operation == Operation.Remove && e.Position < rows.Count)
      				rows.RemoveAt(e.Position);
      			
      			/* Checks to see if the action taken was to update a data already on the ladder
      			Note: Due to the multi threaded architecture of the NT core, race conditions could occur
      			-> check if e.Position is within valid range */
      			else if (e.Operation == Operation.Update)
      			{
      				rows[e.Position].MarketMaker	= e.MarketMaker;
      				rows[e.Position].Price			= e.Price;
      				rows[e.Position].Volume			= e.Volume;
      			}
      			
      			
      
      			
              }
      Last edited by ketron82; 02-03-2017, 09:36 AM.

      Comment


        #4

        Error on calling 'OnMarketDepth' method for indicator 'MyCustomIndicator': MyCustomIndicator.DrawText: startBarsAgo out of valid range 0 through -1, was 1.
        This is the error.....and I cannot solve it. I made some test but nothing. I test 0, 1, -1 but also the same error in drawing a simple TEST under the price or upper Price.
        Logically....the last bar is problematic because we do not know the close price so drawing is difficult but I can write text on the other bars before the lastest but I cannot find a solution.

        The Software is minimal semplified ...this is the incriminated function

        Code:
                protected override void OnMarketDepth(MarketDepthEventArgs e)
                {
        			
        			
        				for (int idx = 0; idx == askRows.Count; idx++)
        					{
        						
        					DrawText("Bar"+ CurrentBar,"#",1,askRows[idx].Price,Color.Blue);
        						
        						
        					}
        		
        				for (int idx = 0; idx == askRows.Count; idx++)
        					{
        
        					DrawText("Bar"+ CurrentBar,"*",1,bidRows[idx].Price,Color.Blue);
        					
        					}
        			
        			
        			
        			List<LadderRow> rows = null;
        
        			// Checks to see if the Market Data is of the Ask type
        			if (e.MarketDataType == MarketDataType.Ask)
        			{
        				rows = askRows;
        				
        				// Due to race conditions, it is possible the first event is an Update operation instead of an Insert. When this happens, populate your Lists via e.MarketDepth first.
        				if (firstAskEvent)
        				{
        					if (e.Operation == Operation.Update)
        					{
        						// Lock the MarketDepth collection to prevent modification to the collection while we are still processing it
        						lock (e.MarketDepth.Ask)
        						{
        							for (int idx = 0; idx < e.MarketDepth.Ask.Count; idx++)
        								rows.Add(new LadderRow(e.MarketDepth.Ask[idx].Price, e.MarketDepth.Ask[idx].Volume, e.MarketDepth.Ask[idx].MarketMaker));
        						}
        					}
        					firstAskEvent = false;
        				}
        			}
        			
        			// Checks to see if the Market Data is of the Bid type
        			else if (e.MarketDataType == MarketDataType.Bid)
        			{
        				rows = bidRows;
        				
        				// Due to race conditions, it is possible the first event is an Update operation instead of an Insert. When this happens, populate your Lists via e.MarketDepth first.
        				if (firstBidEvent)
        				{
        					if (e.Operation == Operation.Update)
        					{
        						// Lock the MarketDepth collection to prevent modification to the collection while we are still processing it
        						lock (e.MarketDepth.Bid)
        						{
        							for (int idx = 0; idx < e.MarketDepth.Bid.Count; idx++)
        								rows.Add(new LadderRow(e.MarketDepth.Bid[idx].Price, e.MarketDepth.Bid[idx].Volume, e.MarketDepth.Bid[idx].MarketMaker));
        						}
        					}
        					firstBidEvent = false;
        				}
        			}
        
        			if (rows == null)
        				return;
        
        			// Checks to see if the action taken was an insertion into the ladder
        			if (e.Operation == Operation.Insert)
        			{
        				// Add a new row at the end if the designated position is greater than our current ladder size
        				if (e.Position >= rows.Count)
        					rows.Add(new LadderRow(e.Price, e.Volume, e.MarketMaker));
        				
        				// Insert a new row into our ladder at the designated position
        				else
        					rows.Insert(e.Position, new LadderRow(e.Price, e.Volume, e.MarketMaker));
        			}
        			
        			/* Checks to see if the action taken was a removal of itself from the ladder
        			Note: Due to the multi threaded architecture of the NT core, race conditions could occur
        			-> check if e.Position is within valid range */
        			else if (e.Operation == Operation.Remove && e.Position < rows.Count)
        				rows.RemoveAt(e.Position);
        			
        			/* Checks to see if the action taken was to update a data already on the ladder
        			Note: Due to the multi threaded architecture of the NT core, race conditions could occur
        			-> check if e.Position is within valid range */
        			else if (e.Operation == Operation.Update)
        			{
        				rows[e.Position].MarketMaker	= e.MarketMaker;
        				rows[e.Position].Price			= e.Price;
        				rows[e.Position].Volume			= e.Volume;
        			}
                }
        Last edited by ketron82; 02-03-2017, 01:59 PM.

        Comment


          #5
          What I want to do is on this screenshot

          http://clip2net.com/s/3H8Gi7B

          Comment


            #6
            Thank you for this additional information ketron82. To answer your questions directly,

            You are accessing an index with a value that is invalid since its out of range.
            While fully debugging user code is beyond the scope of the support we may provide, I did notice the bolded text in the below code,

            Code:
                            for (int idx = 0; idx == [B]askRows[/B].Count; idx++)
                                {
                                    
                                DrawText("Bar"+ CurrentBar,"#",1,[B]askRows[/B][idx].Price,Color.Blue);
                                    
                                    
                                }
                    
                            for (int idx = 0; idx == [I][B]askRows[/B][/I].Count; idx++)
                                {
            
                                DrawText("Bar"+ CurrentBar,"*",1,[B]bidRows[/B][idx].Price,Color.Blue);
                                
                                }
            In the second loop, you request information from bidRows, but check against the size of askRows. I believe reviewing your code for instances like this will make this message disappear.

            That said, while this is an advanced topic, I would like to invite you to try to review the code inside (My) Documents\NinjaTrader 7\bin\Custom\Type\@BarsTypes.cs . This contains a PointAndFigure bar type. I would like to invite you to try a PointAndFigure bar type on your own chart, as this may be exactly what you were looking for without any coding work. If it isn't quite what you were looking for, you can create a copy of the PointAndFigure bar type in this file. Once you have made an independent copy with the same name that works in a chart, you can then experiment with modifying this bar type's code until it does what we would like.

            Should anything come up during the development process we may help with please let us know.
            Jessica P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by timmbbo, 07-05-2023, 10:21 PM
            4 responses
            158 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by tkaboris, Today, 08:01 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by Lumbeezl, 01-11-2022, 06:50 PM
            31 responses
            817 views
            1 like
            Last Post NinjaTrader_Adrian  
            Started by xiinteractive, 04-09-2024, 08:08 AM
            5 responses
            15 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by swestendorf, Today, 11:14 AM
            2 responses
            6 views
            0 likes
            Last Post NinjaTrader_Kimberly  
            Working...
            X