Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calling an indicator within an indicator

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

    Calling an indicator within an indicator

    Ok, at the cost of sounding really dumb, I'm having trouble calling from an outside indicator.

    I followed the Sampleboolseries directions to create a public DataSeries Lastlow and Lasthigh from ZigZagUTC(show,span,true,Color.Green).

    inside ZigZagUTC is a public int dir //1 if up -1 if down.

    When I try to use it in another indicator, it does not get activated unless there is a statement that refers to the dataseries first... example (this always returns dir==0)

    Code:
    protected override void OnBarUpdate()
            {
    //            ZigZagUTC(show,span,true,Color.Green)
                if (CurrentBar < 50)   //completely arbitrary; it is high enough
                    return;
                
                if(ZigZagUTC(show,span,true,Color.Green).dir > 0)
                {
                    Print ("Dir is up " + ZigZagUTC(show,span,true,Color.Green).dir);
                    Print("Lasthigh[0] is " + ZigZagUTC(show,span,true,Color.Green).Lasthigh[CurrentBar-ZigZagUTC(show,span,true,Color.Green).lastlobar]);
                    Print("Lastlow[0] is " + ZigZagUTC(show,span,true,Color.Green).Lastlow[0]);
                }
                
                if(ZigZagUTC(show,span,true,Color.Green).dir == 0)
                    Print ("Dir is 0 " + ZigZagUTC(show,span,true,Color.Green).dir);
                    
                
                if(ZigZagUTC(show,span,true,Color.Green).dir < 0)
                {
                    Print ("Dir is down " + ZigZagUTC(show,span,true,Color.Green).dir);
                    Print("Lasthigh[0] is " + ZigZagUTC(show,span,true,Color.Green).Lasthigh[0]);
                    Print("Lastlow[0] is " + ZigZagUTC(show,span,true,Color.Green).Lastlow[CurrentBar-ZigZagUTC(show,span,true,Color.Green).lasthibar]);
                }
    However, this works perfect. Why is that?
    Code:
    protected override void OnBarUpdate()
            {
    //            ZigZagUTC(show,span,true,Color.Green)
                if (CurrentBar < 50)
                    return;
    
    Print("Dir is activated" + ZigZagUTC(show,span,true,Color.Green).Lasthigh[0]);
                
                if(ZigZagUTC(show,span,true,Color.Green).dir > 0)
                {
                    Print ("Dir is up " + ZigZagUTC(show,span,true,Color.Green).dir);
                    Print("Lasthigh[0] is " + ZigZagUTC(show,span,true,Color.Green).Lasthigh[CurrentBar-ZigZagUTC(show,span,true,Color.Green).lastlobar]);
                    Print("Lastlow[0] is " + ZigZagUTC(show,span,true,Color.Green).Lastlow[0]);
                }
                
                if(ZigZagUTC(show,span,true,Color.Green).dir == 0)
                    Print ("Dir is 0 " + ZigZagUTC(show,span,true,Color.Green).dir);
                    
                
                if(ZigZagUTC(show,span,true,Color.Green).dir < 0)
                {
                    Print ("Dir is down " + ZigZagUTC(show,span,true,Color.Green).dir);
                    Print("Lasthigh[0] is " + ZigZagUTC(show,span,true,Color.Green).Lasthigh[0]);
                    Print("Lastlow[0] is " + ZigZagUTC(show,span,true,Color.Green).Lastlow[CurrentBar-ZigZagUTC(show,span,true,Color.Green).lasthibar]);
                }

    #2
    Hello wallabee13,
    Please make sure that the property value is up to date and is return a value. For example ExposedVariable property in the SampleBoolSeries indicator calls the Update() method to make sure a value is returned.

    Code:
    [Browsable(false)]
    [XmlIgnore()]
    public double ExposedVariable
    {
    // We need to call the Update() method to ensure our exposed variable is in up-to-date.
        get { Update(); return exposedVariable; }
    }
    Also since ZigZag indicators do repaint, and it can be issues relating to that too. Please debug the custom indicator properly and confirm that the indicator is retuning proper values.

    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Ok, I added an Update() statement to the ZigZagUTC Lasthigh and Lastlow references and it is still behaving the same way.

      Code:
      //in ZigZagUTC()
      
      OnBarUpdate()
      {
      
      lasthigh.Set(lasthi);
      lastlow.Set(lastlo);
      }
      
      # region Properties
      
      [Browsable(false)] 
              [XmlIgnore()]
              public DataSeries Lasthigh
              {
                  get { Update(); return lasthigh; }
              }
              
              [Browsable(false)]    
              [XmlIgnore()]       
              public DataSeries Lastlow
              {
                  get { Update(); return lastlow; }
              }
      I am still getting dir==0 (if w/o the initial Print statement) from my other indicator. As far as I can tell, debugging the values within ZigZagUTC, they are all being defined correctly.
      Last edited by wallabee13; 03-06-2012, 03:02 PM.

      Comment


        #4
        Hello wallabee13,
        You need to change the public field “dir” into a property and call the Update method before returning it.

        Please let me know if I can assist you any further.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Still no change. Here is the source code:

          Code:
          public class FibSpreadMine : Indicator
              {
                  #region Variables
                  // Wizard generated variables
                  private int show = 3;
                  private int span = 4;
                  private double range = 0;
                  // User defined variables (add any user defined variables below)
                  #endregion
          
                  /// <summary>
                  /// This method is used to configure the indicator and is called once before any bar data is loaded.
                  /// </summary>
                  protected override void Initialize()
                  {
                      //Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                      Overlay                = false;
                  }
          
                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
                  {
          //            ZigZagUTC(show,span,true,Color.Green)
                      if (CurrentBar < 50)
                          return;
                      
                      //Print(ZigZagUTC(show,span,true,Color.Green).Lasthigh[0]);
                      if(ZigZagUTC(show,span,true,Color.Green).dir > 0)
                      {
                          Print ("Dir is up " + ZigZagUTC(show,span,true,Color.Green).dir);
                          Print("Lasthigh[0] is " +  ZigZagUTC(show,span,true,Color.Green).Lasthigh[CurrentBar-ZigZagUTC(show,span,true,Color.Green).lastlobar]);
                          Print("Lastlow[0] is " + ZigZagUTC(show,span,true,Color.Green).Lastlow[0]);
                          range =  ZigZagUTC(show,span,true,Color.Green).Lasthigh[CurrentBar-ZigZagUTC(show,span,true,Color.Green).lastlobar]-
                          ZigZagUTC(show,span,true,Color.Green).Lastlow[0];
                          Print("range up is " + range);
                      }
                      
                      if(ZigZagUTC(show,span,true,Color.Green).dir == 0)
                          Print ("Dir is 0 " + ZigZagUTC(show,span,true,Color.Green).dir);
                          
                      
                      if(ZigZagUTC(show,span,true,Color.Green).dir < 0)
                      {
                          Print ("Dir is down " + ZigZagUTC(show,span,true,Color.Green).dir);
                          Print("Lasthigh[0] is " + ZigZagUTC(show,span,true,Color.Green).Lasthigh[0]);
                          Print("Lastlow[0] is " +  ZigZagUTC(show,span,true,Color.Green).Lastlow[CurrentBar-ZigZagUTC(show,span,true,Color.Green).lasthibar]);
                          range = ZigZagUTC(show,span,true,Color.Green).Lasthigh[0] - 
                          ZigZagUTC(show,span,true,Color.Green).Lastlow[CurrentBar-ZigZagUTC(show,span,true,Color.Green).lasthibar];
                          Print("range down is " + range);
                      }
                      
                      // Use this method for calculating your indicator values. Assign a value to each
                      // plot below by replacing 'Close[0]' with your own formula.
                      //Plot0.Set(Close[0]);
                  }
          
                  #region Properties
                  [Browsable(false)]    // this line prevents the data series from  being displayed in the indicator properties dialog, do not remove
                  [XmlIgnore()]        // this line ensures that the indicator can  be saved/recovered as part of a chart template, do not remove
                  public DataSeries Plot0
                  {
                      get { return Values[0]; }
                  }
          
                  [Description("")]
                  [GridCategory("Parameters")]
                  public int Show
                  {
                      get { return show; }
                      set { show = Math.Max(1, value); }
                  }
                  
                  [Description("")]
                  [GridCategory("Parameters")]
                  public int Span
                  {
                      get { return span; }
                      set { span = Math.Max(1, value); }
                  }
                  
                  private double Range
                  {
                      get { return range; }
                      set { range= Math.Max(0, value); }
                  }
                  #endregion
              }
          and within ZigZagUTC


          Code:
          #region Properties
          
          [Browsable(false)]    // this line prevents the data series from being  displayed in the indicator properties dialog, do not remove
                  [XmlIgnore()]        // this line ensures that the indicator can  be saved/recovered as part of a chart template, do not remove
                  public DataSeries Lasthigh
                  {
                      get { Update(); return lasthigh; }
                  }
                  
                  [Browsable(false)]    // this line prevents the data series from  being displayed in the indicator properties dialog, do not remove
                  [XmlIgnore()]        // this line ensures that the indicator can  be saved/recovered as part of a chart template, do not remove
                  public DataSeries Lastlow
                  {
                      get { Update(); return lastlow; }
                  }
                  
                  public int Dir
                  {
                      get {Update(); return dir; }
                      set { dir = Math.Max(-5, value); }
                  }

          Comment


            #6
            Again, if I have the
            Code:
            Print(ZigZagUTC(show,span,true,Color.Green).Lasthigh[0]);
            active, then everything works fine...
            with an ignore
            //
            everything crashes to dir==0

            Comment


              #7
              Hello wallabee13,
              The attached indicator works fine at my end.
              Please see how I edited the dir in line 62, and added the property in line 222-227.

              Please let me know if I can assist you any further.
              Attached Files
              JoydeepNinjaTrader Customer Service

              Comment


                #8
                Capital Dir compared to lower case dir. Wow, that took me awhile.

                Comment


                  #9
                  Hello wallabe13,
                  Glad you could resolve the issue.
                  Please let me know if I can assist you any further.
                  JoydeepNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by mg.watts, Today, 03:17 PM
                  1 response
                  13 views
                  0 likes
                  Last Post NinjaTrader_ChrisL  
                  Started by JTizz, Today, 01:20 PM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by omermirza, Today, 12:39 PM
                  2 responses
                  12 views
                  0 likes
                  Last Post omermirza  
                  Started by mballagan, Today, 01:02 PM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_Kate  
                  Started by larkmail, Today, 12:30 PM
                  3 responses
                  12 views
                  0 likes
                  Last Post NinjaTrader_Kate  
                  Working...
                  X