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

Indicator Code Not Executed When Added to a Strategy

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

    Indicator Code Not Executed When Added to a Strategy

    Hi, I am using NT8 and having some difficulty accessing boolean properties for an indicator that has been added to a strategy. When attempting to access the properties exposed by the indicator, the properties only return the initialized values of the associated bool variables.

    My custom indicator, dpSlope, has two public boolean properties; "isRising" and "isFalling":
    Code:
    		[Browsable(false)]
    		[XmlIgnore]
    		public bool isRising
    		{
    			get { return SlopeRising; }
    		}
    
    		[Browsable(false)]
    		[XmlIgnore]
    		public bool isFalling
    		{
    			get { return SlopeFalling; }
    		}
    The return variables are defined as follows:
    Code:
          #region Variables
            private bool SlopeRising = false;
            private bool SlopeFalling = false;
            #endregion
    These variables are updated in the OnBarUpdate() method for the indicator:
    Code:
                if (IsRising(Values[0]))
                {
                    PlotBrushes[0][0] = Brushes.Green;
                    SlopeFalling = false;
                    SlopeRising = true;
                }
                else if (IsFalling(Values[0]))
                {
                    PlotBrushes[0][0] = Brushes.Red;
                    SlopeFalling = true;
                    SlopeRising = false;
                }
    These "if" statements are properly executed when I use Visual Studio to debug the indicator, itself. The indicator bars show the proper color on the chart window and the bool variables show the correct values within Visual Studio.

    In the Strategy, I added the indicator so that it plots it in the chart.
    Code:
    			else if (State == State.Configure)
    			{
    				AddChartIndicator(dpSlope(SlopePeriod, SlopeLookBack, false));
                                    AddChartIndicator(MACD(12, 26, 9));
     			}
    The strategy plots the dpSlope indicator properly with the correct colors for the bars.

    In the strategy OnBarUpdate method, I use the following code to access the bool properties:
    Code:
               Print("isRising " + dpSlope(SlopePeriod, SlopeLookBack, false).isRising);
               if ((dpSlope(SlopePeriod, SlopeLookBack, false).isRising) && (CrossAbove(MACD(12,29,9).Diff,0,1)))
    This code only returns the initialized value for SlopeRising defined in the indicator. For example, if I initialize this variable to "true", then dpSlope(parameter list).isRising will return "true". The same holds true if I access the isFalling property.

    If I use Visual Studio to set breakpoints at the point these variables are updated in the indicator, they will never be hit.

    I am at a loss as to why this may be happening. Any help would be appreciated.

    Regards,

    dp2002
    Last edited by dp2002; 03-27-2016, 09:25 PM.

    #2
    Without some full sample code to download and test...

    Is your issue related to this?

    Comment


      #3
      Thank you for the quick reply, Sledge.

      The attached file contains the exported files; dpSlope (Indicator) and dpSlopeTest (Strategy).

      I believe the problem is in someway related to the post you provided. I inserted a print statement which outputs the Values[0][0] of the indicator dataseries. It prints a value of zero whether I add the strategy or refresh the strategy.

      When I change the initialization values for "SlopeRising" and "SlopeFalling" in the indicator code to 'true", surprisingly the entry and exit signals are executed. The entries are on every "positive" crossover of the MACD signal since the test condition is obviously true. It appears the indicator is collecting the correct values for the dataseries, yet the output of the print statement is still zero.

      P.S. The attached code should still have the SlopeRising and the SlopeFalling variables set to "true". Also, the input properties for the UniRenko bars are not used in the code.

      Regards,

      dp2002
      Attached Files
      Last edited by dp2002; 03-28-2016, 12:26 AM.

      Comment


        #4
        Hello dp2002,

        Thanks for your posts and code.

        In your public properties you will want to call Update(). Please see: http://ninjatrader.com/support/helpG...us/?update.htm

        For example:
        Code:
        [Browsable(false)]
        		[XmlIgnore]
        		public bool isRising
        		{
        			get { [COLOR="Blue"]Update();[/COLOR] return SlopeRising; }
        		}
        
        		[Browsable(false)]
        		[XmlIgnore]
        		public bool isFalling
        		{
        			get {[COLOR="Blue"]Update();[/COLOR] return SlopeFalling; }
        		}
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thanks Paul,

          The Update() method fixed the issue.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by GLFX005, Today, 03:23 AM
          0 responses
          1 view
          0 likes
          Last Post GLFX005
          by GLFX005
           
          Started by XXtrader, Yesterday, 11:30 PM
          2 responses
          11 views
          0 likes
          Last Post XXtrader  
          Started by Waxavi, Today, 02:10 AM
          0 responses
          6 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by TradeForge, Today, 02:09 AM
          0 responses
          14 views
          0 likes
          Last Post TradeForge  
          Started by Waxavi, Today, 02:00 AM
          0 responses
          3 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Working...
          X