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

Casting BarsType

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

    Casting BarsType

    Hello,

    I need to do a casting to reference to a subclass of BarsType.
    But I always get an exception and not know why.

    The issue is easy to reproduce if you load this indicator on a chart of minutes.

    Any help is welcome.

    Best Regards.

    Code:
    protected override void OnStartUp()
    {
    	try
    	{
    		// A "superclass variable" points to a "subclass object":
    		BarsType a = this.Bars.BarsType;
    		
    		// The Print is ok, because this.Bars.BarsType is of the type "MinuteBarsType"
    		Print( a.GetType().ToString() ); // ... "NinjaTrader.Data.MinuteBarsType"
    		
    		// The casting fails although the types are equals. And I dont know why.
    		NinjaTrader.Data.MinuteBarsType b = (NinjaTrader.Data.MinuteBarsType)a;
    	}
    	catch( Exception e )
    	{
    		Print( e.ToString() );
    	}
    }

    #2
    Hello,

    We do not have any documentation in this area, so I am limited on the support I can give you.

    Can you give me an idea of what you're trying to accomplish and when you need to work with the MinuteBarsType? Is there a reason you cannot stay with just bar types?

    I try the following modification to your code and it works
    Code:
    		protected override void OnStartUp()
    		{
    			
    			try
    			{
    				// A "superclass variable" points to a "subclass object":
    				BarsType a = this.Bars.BarsType;
    								
    				Print( a.ToString());  //NinjaTrader.Data.MinuteBarsType
    					
    				BarsType b = a;
    				Print(b.ToString()); // NinjaTrader.Data.MinuteBarsType
    				
    			}
    			catch( Exception e )
    			{
    				Print( e.ToString() );
    			
    			}
    		
    		}
    However whether this works for you depends on what you're trying to accomplish.
    MatthewNinjaTrader Product Management

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by TraderG23, 12-08-2023, 07:56 AM
    9 responses
    382 views
    0 likes
    Last Post Gavini
    by Gavini
     
    Started by oviejo, Today, 12:28 AM
    0 responses
    1 view
    0 likes
    Last Post oviejo
    by oviejo
     
    Started by pechtri, 06-22-2023, 02:31 AM
    10 responses
    125 views
    0 likes
    Last Post Leeroy_Jenkins  
    Started by judysamnt7, 03-13-2023, 09:11 AM
    4 responses
    59 views
    0 likes
    Last Post DynamicTest  
    Started by ScottWalsh, Yesterday, 06:52 PM
    4 responses
    36 views
    0 likes
    Last Post ScottWalsh  
    Working...
    X