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

Why does this public bool property always return false?

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

    Why does this public bool property always return false?

    As always I am learning as a hack away at scripts, totally self taught, so forgive my ignorance.

    I am trying to expose another indicators value by way of a public property.

    Starting w/ NT's ATR Trailing Stop script from an S&C article, I tried to add a public prperty to tell me if bar[0] was the bar that hit the trailing stop, and the stops have now flipped...

    either they were above the bars, and now are under, or vice versa.

    I added some print lines, and it will print the correct bars time, and the expected true to the output window when the indicator is applied to a chart.

    But when I try to access the property from another script, like a strategy, the property always returns false.

    Why is it True in the indicator and false on the same bar as a public property?

    Script exerpt follows entire ATR stops with public property attached.

    Code:
    else if (Close[0] > Value[1])
                {
                    trail = Close[0] - loss;
                    //This bar caused StopLoss to flip from above bars to below bars, so set flippedLong to true, flippedShort to false
                    flippedLong = true;
                    flippedShort = false;
                    DrawArrowDown(CurrentBar.ToString(), false, 1, Value[1], Color.Orange);
                    
                    Print(Time[0].ToString());
                    //Public Property FlippedLong will print showing it is set to true on this bar, but when this property is accessed from another script, it always
                    //returns false  WHY?
                    Print(FlippedLong);
                }
                
                else
                {
                    trail = Close[0] + loss;
                    flippedShort = true;
                    flippedLong = false;
                    DrawArrowUp(CurrentBar.ToString(), false, 1, Value[1], Color.Orange);
                    
                    Print(Time[0].ToString());
                    //Public Property FlippedShort will print showing it is set to true on this bar, but when this property is accessed from another script, it always
                    //returns false  WHY?
                    Print(FlippedShort);
                }
    
                Value.Set(trail);
            }
            
            #region Properties
            [Description("ATR period")]
            [Category("Parameters")]
            public int Period
            {
                get { return period; }
                set { period = Math.Max(1, value); }
            }
            
            [Description("ATR multiplication")]
            [Category("Parameters")]
            public double Multi
            {
                get { return multi; }
                set { multi = Math.Max(0, value); }
            }
            
            [Description("Flipped Bullish This Bar")]
            public bool FlippedLong
            {
                get { return flippedLong; }
                //set {  }
            }
            
            [Description("Flipped Bearish This Bar")]
            public bool FlippedShort
            {
                get { return flippedShort; }
                //set {  }
            }
    Attached Files

    #2
    Hello Crassius,

    You would want to expose the variable to be able to have it accessible in other scripts. You may see the following thread for an example of this.

    JCNinjaTrader Customer Service

    Comment


      #3
      Need to call Update to Expose Variable

      On reviewing the recommended example, I realized I was not calling the Update() method in the property definition.

      Now it works as expected.

      Hope this helps someone in the future.
      Attached Files

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Jon17, Today, 04:33 PM
      0 responses
      1 view
      0 likes
      Last Post Jon17
      by Jon17
       
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      5 views
      0 likes
      Last Post Javierw.ok  
      Started by timmbbo, Today, 08:59 AM
      2 responses
      10 views
      0 likes
      Last Post bltdavid  
      Started by alifarahani, Today, 09:40 AM
      6 responses
      41 views
      0 likes
      Last Post alifarahani  
      Started by Waxavi, Today, 02:10 AM
      1 response
      20 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Working...
      X