• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT8.0.15.1: Typecasting in Compiled Assembly (DLL)

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

    NT8.0.15.1: Typecasting in Compiled Assembly (DLL)

    Hi

    I'm trying to access various properties of Manually created horizontal lines on the chart through the following code [Similar to https://ninjatrader.com/support/help...wobjects.htm]:

    Code:
    //go through all objects on the chart
    foreach (DrawingTool pO_DrawingTool in DrawObjects.ToList())
    {
    	// Finds line objects that are attached globally to all charts of the same instrument
    	if (pO_DrawingTool is DrawingTools.HorizontalLine)
    	{
    		// ensure it has the desired tag name
    		if (pO_DrawingTool.Tag.CompareTo(is_TagName) == 0)
    		{
    			DrawingTools.HorizontalLine lO_HL = pO_DrawingTool as DrawingTools.HorizontalLine;
    			
    			// add this desired horizontal line's information
    			gs_List_currID.Add(pO_DrawingTool.Id);
    			gd_List_currPrice.Add(Instrument.MasterInstrument.RoundToTickSize(lO_HL.StartAnchor.Price));
    			gd_List_currWidth.Add(lO_HL.Stroke.Width);
    			gs_List_currColor.Add(lO_HL.Stroke.Brush.ToString());
    			gs_List_currStyle.Add(lO_HL.Stroke.DashStyleHelper.ToString());
    		}
    	}
    }
    It works well (if the source code is available), except, through the compiled assembly (DLL). I'm trying Reflection to extract the same features, as per the suggestion at
    HTML Code:
    https://ninjatrader.com/support/helpGuides/nt8/en-us/?considerations_for_compiled_assemblies.htm
    , but till now, I have been able to code the following:

    Code:
    //go through all objects on the chart
    foreach (dynamic pO_DrawingTool in DrawObjects.ToList())
    {
    	// Finds line objects that are attached globally to all charts of the same instrument
    	//if (pO_DrawingTool is NinjaTrader.NinjaScript.DrawingTools.HorizontalLine)
    	if (pO_DrawingTool.ToString().Equals("NinjaTrader.NinjaScript.DrawingTools.HorizontalLine") == true)
    	{
    		// ensure it has the desired tag name
    		if (pO_DrawingTool.Tag.CompareTo(is_TagName) == 0)
    		{
    			dynamic lO_HL = pO_DrawingTool as DrawingTools.HorizontalLine;
    			//
    			if (lO_HL != null)
    			{
    				// add this desired horizontal line's information
    				gs_List_currID.Add(pO_DrawingTool.Id);
    				gd_List_currPrice.Add(Instrument.MasterInstrument.RoundToTickSize(lO_HL.StartAnchor.Price));
    				gd_List_currWidth.Add(lO_HL.Stroke.Width);
    				gs_List_currColor.Add(lO_HL.Stroke.Brush.ToString());
    				gs_List_currStyle.Add(lO_HL.Stroke.DashStyleHelper.ToString());
    			}
    		}
    	}
    }
    But I'm not able to find a proper substitute for
    Code:
    dynamic lO_HL = pO_DrawingTool as DrawingTools.HorizontalLine;
    through Reflection technique.

    It will be very helpful, if someone may provide me pointers towards the solution for this.

    Thank You!

    #2
    Hello engrvivs,

    Thank you for the post.

    I do not see the help guide example using type casting while using the dynamic type. You should not need to cast the object since all of the Horizontal lines properties are available through the Dynamic type. It looks like the casting is handled by the dynamic type. The page you linked on the subject of working with dynamic types says that you can treat the object like the expected type.

    Please let me know if this does not resolve your inquiry.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thank You Chris for sharing your insight!

      You are correct. The dynamic type object does not need casting. All of the Horizontal lines properties are available through it. Hence, as per your advice, I did away with
      dynamic lO_HL = pO_DrawingTool as DrawingTools.HorizontalLine;
      and replaced lO_HL with pO_DrawingTool.

      The code imported through compiled Assembly (DLL) was able to recognize the desired horizontal lines.

      Many Thanks for the solution!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by ryanmercado, Today, 10:04 AM
      0 responses
      3 views
      0 likes
      Last Post ryanmercado  
      Started by uiwislth, Yesterday, 11:25 PM
      0 responses
      5 views
      0 likes
      Last Post uiwislth  
      Started by Steve L, Yesterday, 10:04 PM
      0 responses
      3 views
      0 likes
      Last Post Steve L
      by Steve L
       
      Started by marianfed, Yesterday, 09:47 PM
      0 responses
      5 views
      0 likes
      Last Post marianfed  
      Started by hir04068, Yesterday, 09:29 PM
      0 responses
      8 views
      0 likes
      Last Post hir04068  
      Working...
      X