Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to plot more than 1 plot in one indicator?

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

    How to plot more than 1 plot in one indicator?

    Hi;

    Would you please explain to me why this code won't plot 2 plots on a chart:

    #region Variables
    Double MA3Len = 34;
    Double MA5Len =
    8;
    #endregion

    protectedoverridevoid Initialize()
    {
    Add(
    new Plot(Color.FromKnownColor(KnownColor.Fuchsia), PlotStyle.Line, "MA3"));
    Add(
    new Plot(Color.FromKnownColor(KnownColor.Fuchsia), PlotStyle.Line, "MA5"));
    Overlay =
    false;
    }
    protectedoverridevoid OnBarUpdate()
    {
    Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + MA3Len)) + (1 - (2.0 / (1 + MA3Len))) * Value[1]);
    Value.Set(CurrentBar ==
    0 ? Input[0] : Input[0] * (2.0 / (1 + MA5Len)) + (1 - (2.0 / (1 + MA5Len))) * Value[1]);
    }

    Thank you

    #2
    Hello,

    Thanks for the forum post and welcome to the NinjaTrader support forum.

    You would need to make the following change.

    MA3.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + MA3Len)) + (1 - (2.0 / (1 + MA3Len))) * Value[1]);

    MA5.Set(CurrentBar ==
    0 ? Input[0] : Input[0] * (2.0 / (1 + MA5Len)) + (1 - (2.0 / (1 + MA5Len))) * Value[1]);

    You need to name it the same as the name you gave the plot up in Initialize.

    Let me know if I can be of further assistance.
    BrettNinjaTrader Product Management

    Comment


      #3
      Hi; thank you for your help;

      When I change the code as you said (change Value to MA3 & MA5) I get error code CS0103. In the help for this error it says to be sure and declare the variables before you use them. So I tried that and that gives me error CS1061. What am I not getting? thanks

      Comment


        #4
        user721, please have a look into your properties section as well in the code as the public properties of the plots would need defining there as well, this could be easiest seen if you review some of the default NT indicators or create the raw indicator structure needed in our indicator wizard.

        Thanks,

        Comment


          #5
          Originally posted by user721 View Post
          Hi; thank you for your help;

          When I change the code as you said (change Value to MA3 & MA5) I get error code CS0103. In the help for this error it says to be sure and declare the variables before you use them. So I tried that and that gives me error CS1061. What am I not getting? thanks
          To use that code, you must define the properties of the plots correctly. If you do not want to define the plots in the properties, then you have to use the in-built Values DataSeries collection thus:

          Code:
          Values[0].Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + MA3Len)) + (1 - (2.0 / (1 + MA3Len))) * Value[1]);
          
          Values[1].Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + MA5Len)) + (1 - (2.0 / (1 + MA5Len))) * Value[1]);

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          607 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          353 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          105 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          560 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          561 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X