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 wzgy0920, 04-20-2024, 06:09 PM
          2 responses
          26 views
          0 likes
          Last Post wzgy0920  
          Started by wzgy0920, 02-22-2024, 01:11 AM
          5 responses
          32 views
          0 likes
          Last Post wzgy0920  
          Started by wzgy0920, Yesterday, 09:53 PM
          2 responses
          49 views
          0 likes
          Last Post wzgy0920  
          Started by Kensonprib, 04-28-2021, 10:11 AM
          5 responses
          192 views
          0 likes
          Last Post Hasadafa  
          Started by GussJ, 03-04-2020, 03:11 PM
          11 responses
          3,234 views
          0 likes
          Last Post xiinteractive  
          Working...
          X