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

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.

    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,
        BertrandNinjaTrader Customer Service

        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 judysamnt7, 03-13-2023, 09:11 AM
          4 responses
          59 views
          0 likes
          Last Post DynamicTest  
          Started by ScottWalsh, Today, 06:52 PM
          4 responses
          36 views
          0 likes
          Last Post ScottWalsh  
          Started by olisav57, Today, 07:39 PM
          0 responses
          7 views
          0 likes
          Last Post olisav57  
          Started by trilliantrader, Today, 03:01 PM
          2 responses
          21 views
          0 likes
          Last Post helpwanted  
          Started by cre8able, Today, 07:24 PM
          0 responses
          10 views
          0 likes
          Last Post cre8able  
          Working...
          X