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

Comparing stroke values

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

    Comparing stroke values

    Hi, I'm creating an automatic alert for horizontal lines. I plan to indicate if the alarm is armed by changing the stroke color of the line to gray, and setting it back to it's original color if the user arms it again.

    The way I'm trying to do this is by using a setter for the horizontal line's "Stroke" property, and storing the new value in a "UserDefinedStroke" property if the new value isn't equal to the disabled alert stroke. The problem is, whenever I try to compare if the brushes are equal, NinjaTrader crashes and corrupts my workspace, and I need to recreate it.


    Here's the code I'm using to do the check, the equality check is the same as the one mentioned as working in this topic: https://ninjatrader.com/support/foru...ad.php?t=90510


    Code:
    [Display(ResourceType=typeof(Custom.Resource), GroupName = "NinjaScriptGeneral", Name = "NinjaScriptDrawingToolLine", Order = 1)]
    public Stroke Stroke
    { get {
        return stroke;
    } set {
        if(Equals(value.Brush.ToString(), DisabledStroke.Brush.ToString())) {
             ChosenStroke = value;
        }
        stroke = value;
     }}

    If there's a better way to find out if the stroke change was caused by the user, like an event caused by the user applying changes, would also be really helpful to know.

    #2
    Hello,

    Thank you for the post.

    I wanted to check, are you currently setting a default for these properties in State.SetDefaults? I tried the syntax and do get an error but only if there was no default set because the object is null. A Strokes Brush cannot be accessed if the object is null which may be what you are seeing but I would not be certain without knowing the error you are getting.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      I did find another way to this which didn't require this check, but I'll provide more info as I want to understand what caused it to corrupt the workspace.



      The DisabledStroke property is a static property, initialized when it's created, and the value property comes from the setter, so I believe all of them were properly initialized. One thing to notice though, is that the crash happens as soon as the Ninjascript Editor finishes compiling, and only if I also have a chart open. Another thing I've noticed that *might* be related to the crash, is that NT calls this setter multiple times, even if there are no drawing tools plotted.

      Comment


        #4
        Hello,

        Thank you for the additional details. Yes as this was not shown in the provided sample it would not have been possible for me to test the same scenario.

        In general we do not suggest using static in NinjaScript, this could be part of the problem. It does also sound like you are not initializing the property correctly, the property should be set from OnStateChange in State.SetDefaults specifically so that the menu can have a default value when open. You are also correct, the public properties will be called multiple times when opening the menu, applying the item and when it is loaded on the chart.

        Also to clarify, the syntax you had originally posted looks to be NT8 syntax and I have answered in regard to that with NT8 answers. I see that you posted in the NT7 forum, can I confirm that this assumption was correct and this post should be moved to the NT8 forums?

        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          I understand now, thanks for the info I'll keep this in mind from now on!


          The post is related to NT8, I posted here because there was no section about Drawing Tools, and I didn't find a General Development in the NT8 section to talk about this

          Comment


            #6
            Hello,

            Thank you for confirming this was resolved.

            If you had located a specific set of syntax that was not working, I would suggest reporting that as an isolated sample export, otherwise, I will close this post as resolved.

            Please let me know if I may be of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by adeelshahzad, Today, 03:54 AM
            2 responses
            15 views
            0 likes
            Last Post adeelshahzad  
            Started by dappa, Today, 09:18 AM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by bill2023, Yesterday, 08:51 AM
            5 responses
            24 views
            0 likes
            Last Post bltdavid  
            Started by frankthearm, Today, 09:08 AM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by yertle, Today, 08:38 AM
            2 responses
            7 views
            0 likes
            Last Post yertle
            by yertle
             
            Working...
            X