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

Using one indicator within another indicator

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

    Using one indicator within another indicator

    I want to display a few indicators within my primary indicator .. (for example the EMA)
    I code the following...

    private int mAValue = 20

    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
    Add(new Plot(Color.Blue, PlotStyle.Line, "MyEMA"));
    Overlay = true;
    }


    protected override void OnBarUpdate()
    {
    MyEMA.Set(EMA(mAValue)[0]);

    yada yada yada….

    getting an error when compiling …

    An Object reference is required for the non-static field, method, or property "Ninjatrader Indicator. MyEMA.Set(double)

    What am I doing wrong?

    Thanks

    #2
    Originally posted by dinoman View Post
    I want to display a few indicators within my primary indicator .. (for example the EMA)
    I code the following...

    private int mAValue = 20

    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
    Add(new Plot(Color.Blue, PlotStyle.Line, "MyEMA"));
    Overlay = true;
    }


    protected override void OnBarUpdate()
    {
    MyEMA.Set(EMA(mAValue)[0]);

    yada yada yada….

    getting an error when compiling …

    An Object reference is required for the non-static field, method, or property "Ninjatrader Indicator. MyEMA.Set(double)

    What am I doing wrong?

    Thanks
    Where and how have you defined the access Properties of MyEMA.

    Comment


      #3
      ok .. you're probably asking the correct question .. I just don't know what access properties are? .. I copied my code from an example in the help guide .. (see below)

      Thanks,

      Richard

      ----

      protected override void Initialize()
      {
      // Add two plots
      Add(new Plot(Color.Blue, PlotStyle.Line, "Upper"));
      Add(new Plot(Color.Orange, PlotStyle.Line, "Lower"));
      }
      protected override void OnBarUpdate()
      {
      // Sets values to our two plots
      Upper.Set(SMA(High, 20)[0]);
      Lower.Set(SMA(Low, 20)[0]);
      // Color the Upper plot based on plot value
      conditions
      if (Rising(Upper))
      PlotColors[0][0] = Color.Blue;
      else if (Falling(Upper))
      PlotColors[0][0] = Color.Red;
      else
      PlotColors[0][0] = Color.Yellow;
      // Color the Lower plot based on plot value
      conditions
      if (Rising(Lower))
      PlotColors[1][0] = Color.Blue;
      else if (Falling(Lower))

      Comment


        #4
        Richard, the Plots would be defined / setup via two parts, the visualization options done in Initialize() and the actual public property done in the Properties section of your code, this is found usually in the lower bottom region and needs to be expanded first via clicking on the + sign. If you setup your script from the indicator wizard it would have created a public property for the MyEMA plot already.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Bertrand .. that did the trick! ... Thank you!

          Now, I'm having trouble geting more than one line to show ..
          When I just code the EMA plot .. it works great .. but, when I try and add in
          Bollinger bands .. only the last Bollinger shows up .. the EMA vaporizes ...

          And .. if you know how to change the color of the plots .. I tried but, they
          seem to default to Orange .. ?

          Here's what I have ..

          ====

          protected override void Initialize()
          {
          Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
          Add(new Plot(Color.FromKnownColor(KnownColor.Black), PlotStyle.Line, "MyEMA"));
          Add(new Plot(Color.Blue, PlotStyle.Line, "MyBollingerUP"));
          Add(new Plot(Color.Blue, PlotStyle.Line, "MyBollingerDN"));
          Overlay = true;
          }


          protected override void OnBarUpdate()
          {
          MyEMA.Set(EMA(mAValue)[0]);
          MyBollingerUP.Set(Bollinger(bollSD, bollPer).Upper[0]);
          MyBollingerDN.Set(Bollinger(bollSD, bollPer).Lower[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]; }
          }

          [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 MyEMA
          {
          get { return Values[0]; }
          }

          [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 MyBollingerUP
          {
          get { return Values[0]; }
          }

          [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 MyBollingerDN
          {
          get { return Values[0]; }
          }

          Comment


            #6
            Glad to hear dinoman, each plot would need it's own Value series - please try -

            #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]; }
            }

            [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 MyEMA
            {
            get { return Values[1]; }
            }

            [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 MyBollingerUP
            {
            get { return Values[2]; }
            }

            [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 MyBollingerDN
            {
            get { return Values[3]; }
            }
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Bertrand ... Another home run! ... Thank you ...!! It's now working just as I want.

              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