Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      557 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      324 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      545 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      547 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X