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

custom vertical bars on CCI charts

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

    custom vertical bars on CCI charts

    how can i paint vertical bars in ninjatrader cci chart like i can do in amibroker?
    here is NT chart and amibroker side by side.


    #2
    Hello junkone,

    If you are referring to setting a plot to the bar style (or histogram style) in code (development), this would be done with PlotStyle.Bar overload parameter.
    AddPlot(Stroke stroke, PlotStyle plotStyle, string name)


    If you are asking how to draw a vertical line, this is done with Draw.VerticalLine().
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      ok, i am trying this but it does not work
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = "CustomCCI";
      Name = "CustomCCI";
      IsSuspendedWhileInactive = true;
      Period = 100;

      AddPlot(Brushes.Goldenrod, PlotStyle.Bar, "custom cci");// i get error on this line
      AddLine(Brushes.DarkGray, 200, NinjaTrader.Custom.Resource.CCILevel2);
      AddLine(Brushes.DarkGray, 100, NinjaTrader.Custom.Resource.CCILevel1);
      AddLine(Brushes.Yellow, 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZe roLine);
      AddLine(Brushes.DarkGray, -100, NinjaTrader.Custom.Resource.CCILevelMinus1);
      AddLine(Brushes.DarkGray, -200, NinjaTrader.Custom.Resource.CCILevelMinus2);
      }
      else if (State == State.DataLoaded)
      sma = SMA(Typical, Period);
      }

      Comment


        #4
        Hello junkone,

        To use the PlotStyle parameter, you will need to use the overload signature with a stroke.

        AddPlot(Stroke stroke, PlotStyle plotStyle, string name)

        There are no overload signatures with (Brush, PlotStyle, string) in the help guide that I linked.

        The Brush can be supplied to the new stroke object.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          perfect. how do I color the histo green if its above 0 and orange if its below 0?


          public class CustomCCI : Indicator
          {
          private SMA sma;

          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = "CustomCCI";
          Name = "CustomCCI";
          IsSuspendedWhileInactive = true;
          Period = 100;

          AddPlot(new Stroke(Brushes.Goldenrod), PlotStyle.Bar, "custom cci");
          AddLine(Brushes.DarkGray, 200, NinjaTrader.Custom.Resource.CCILevel2);
          AddLine(Brushes.DarkGray, 100, NinjaTrader.Custom.Resource.CCILevel1);
          AddLine(Brushes.Yellow, 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZe roLine);
          AddLine(Brushes.DarkGray, -100, NinjaTrader.Custom.Resource.CCILevelMinus1);
          AddLine(Brushes.DarkGray, -200, NinjaTrader.Custom.Resource.CCILevelMinus2);
          }
          else if (State == State.DataLoaded)
          sma = SMA(Typical, Period);
          }

          protected override void OnBarUpdate()
          {
          if (CurrentBar == 0)
          Value[0] = 0;
          else
          {
          double mean = 0;
          double sma0 = sma[0];

          for (int idx = Math.Min(CurrentBar, Period - 1); idx >= 0; idx--)
          mean += Math.Abs(Typical[idx] - sma0);

          Value[0] = (Typical[0] - sma0) / (mean.ApproxCompare(0) == 0 ? 1 : (0.015 * (mean / Math.Min(Period, CurrentBar + 1))));
          }
          }

          Comment


            #6
            Hello junkone,

            Set the PlotBrushes[plot index][bar index].
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Tin34, Today, 03:30 AM
            2 responses
            16 views
            0 likes
            Last Post Tin34
            by Tin34
             
            Started by sastrades, Yesterday, 09:59 AM
            2 responses
            30 views
            0 likes
            Last Post brucerobinson  
            Started by ETFVoyageur, Today, 12:52 AM
            1 response
            15 views
            0 likes
            Last Post Leeroy_Jenkins  
            Started by lollers, Today, 03:26 AM
            0 responses
            10 views
            0 likes
            Last Post lollers
            by lollers
             
            Started by aliyahany, Today, 03:16 AM
            0 responses
            4 views
            0 likes
            Last Post aliyahany  
            Working...
            X