Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Type conversion

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

    Type conversion

    Hi Guys

    I started to derive a Rectangle class into a alertRectangle class in the DrawingTools namespace.

    Later on, in an indicator I try to get all the drawing objects where type match this alertRectangle class:

    However, I am facing an error about type conversion

    Indicator 'ZoneAlert': Error on calling 'OnBarUpdate' method on bar 0:

    [A]NinjaTrader.NinjaScript.DrawingTools.alertRectangl e can't be converted to [B]NinjaTrader.NinjaScript.DrawingTools.alertRectangl e.
    A Type comes from '9d4d7d2f09f04fe49d12ce01eabf724f, Version=8.0.23.0, Culture=neutral, PublicKeyToken=null' in the 'LoadFrom' context at 'E:\Documents\NinjaTrader 8\tmp\9d4d7d2f09f04fe49d12ce01eabf724f.dll'.
    B type comes from '3f856e8638064373b63654f121ff80ee, Version=8.0.23.0, Culture=neutral, PublicKeyToken=null' in the 'LoadFrom' context at 'E:\Documents\NinjaTrader 8\tmp\3f856e8638064373b63654f121ff80ee.dll'.

    I already delete the tmp folder, restarting ninjatrader several times.
    However this error still persist

    Here is the code (abstract)

    Code:
        public class alertRectangle : Rectangle
        {
            protected override void OnStateChange()
            {
                base.OnStateChange();
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Design an alert rectangle.";
                    Name                                        = "alertRectangle";
    
                    ...
                    blablabla
                    ...
                }
                else if (State == State.Configure)
                {
                }
            }
    
    
            //Condition condition
            #region Properties
            [NinjaScriptProperty]
            [Display(Name = "Condition", GroupName = "Alert Condition", Order = 0)]
            public Condition condition
            { get; set; }
    
            [Range(0, int.MaxValue), NinjaScriptProperty]
            [Display(Name = "ReactivationDelay", GroupName = "Alert Condition", Order = 1)]
            public int delayBeforeReactivation
            { get; set; }
    
            [NinjaScriptProperty]
            [Display(Name = "Keep alive", GroupName = "Alert Condition", Order = 2)]
            public bool stayAlive
            { get; set; }
            #endregion
    
            public bool            Notified;
            public DateTime?    NotifiedTime;
    
        }
    
    ​
    In the indicator I just check:

    Code:
    foreach (DrawingTool draw in DrawObjects.ToList())
                {
    
                    if (draw.GetType().Name == "alertRectangle")
                    {
                       // This is failing on thje line:
                        alertRectangle globalRectangle = (DrawingTools.alertRectangle)draw; ​
    I also trid this syntax, with no more success:

    Code:
    alertRectangle globalRectangle = draw as DrawingTools.alertRectangle;
    Can't see how to solve that.
    Can you help ?




    #2
    Hello Philippe56140,

    Thanks for your post.

    An obstacle arises with traditional typecasting in a compiled assembly since the NinjaScript type you attempt to cast will be present in both your DLL and NinjaTrader's Custom.dll assembly. If you plan to compile your code into a DLL, you will need to use the dynamic type to avoid this conflict by dynamically assigning the type at runtime, using the guidelines found on the help guide page linked below under the section 'Casting Types in a DLL (Using dynamic Types)'.

    Casting Types in a DLL (Using dynamic Types): https://ninjatrader.com/support/help...assemblies.htm

    Please let me know if I may further assist. zz0.50yu3ahs269zz
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    596 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    343 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    556 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    554 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X