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

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 Barry Milan, Today, 10:35 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by WeyldFalcon, 12-10-2020, 06:48 PM
      14 responses
      1,428 views
      0 likes
      Last Post Handclap0241  
      Started by DJ888, Yesterday, 06:09 PM
      2 responses
      9 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      40 views
      0 likes
      Last Post jeronymite  
      Started by bill2023, Today, 08:51 AM
      2 responses
      16 views
      0 likes
      Last Post bill2023  
      Working...
      X