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 usazencort, Today, 01:16 AM
    0 responses
    1 view
    0 likes
    Last Post usazencort  
    Started by kaywai, 09-01-2023, 08:44 PM
    5 responses
    603 views
    0 likes
    Last Post NinjaTrader_Jason  
    Started by xiinteractive, 04-09-2024, 08:08 AM
    6 responses
    22 views
    0 likes
    Last Post xiinteractive  
    Started by Pattontje, Yesterday, 02:10 PM
    2 responses
    21 views
    0 likes
    Last Post Pattontje  
    Started by flybuzz, 04-21-2024, 04:07 PM
    17 responses
    230 views
    0 likes
    Last Post TradingLoss  
    Working...
    X