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

What is the best way to pass an indicator value as series to Draw.Region?

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

    What is the best way to pass an indicator value as series to Draw.Region?


    Draw.Region(this, "TMA Band", CurrentBar, 0, TMA(High, Period)[0], TMA(Low, Period)[0], Color, Opacity);​

    #2
    Hello, thanks for writing in. That is the correct way to reference the latest indicator value. Are you getting any errors in the Log tab of the Control Center about the indicator? Also use Print() to print the values to confirm the indicator is seeing these values properly.
    //right before calling Draw.Region:
    Print("TMA(High, Period)[0] " + TMA(High, Period)[0]);
    Print("TMA(Low, Period)[0] " + TMA(Low, Period)[0]);
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Getting CS1502 and CS1503 error... Can't compile...

      Comment


        #4
        namespace NinjaTrader.NinjaScript.Indicators.My
        {
        public class MyTMABand : Indicator
        {
        protected override void OnStateChange()
        {
        if (State == State.SetDefaults)
        {
        Description = @"My TMA Band.";
        Name = "MyTMABand";
        Calculate = Calculate.OnPriceChange;
        IsOverlay = true;
        DisplayInDataBox = true;
        DrawOnPricePanel = true;
        DrawHorizontalGridLines = true;
        DrawVerticalGridLines = true;
        PaintPriceMarkers = true;
        ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
        IsSuspendedWhileInactive = true;

        Period = 13;
        Color = Brushes.White;
        Opacity = 50;

        }
        else if (State == State.Configure)
        {
        }

        else if (State == State.DataLoaded)
        {
        }
        }

        protected override void OnBarUpdate()
        {
        Draw.Region(this, "TMA Band", CurrentBar, 0, TMA(High, Period)[0], TMA(Low, Period)[0], Color, Opacity);
        }

        region Properties

        [NinjaScriptProperty]
        [Range(1, int.MaxValue)]
        [Display(Name="Period", Description="Period", Order=1, GroupName="Parameters")]
        public int Period
        { get; set; }

        [NinjaScriptProperty]
        [XmlIgnore]
        [Display(Name="Color", Description="Color", Order=2, GroupName="Parameters")]
        public Brush Color
        { get; set; }

        [Browsable(false)]
        public string ColorSerializable
        {
        get { return Serialize.BrushToString(Color); }
        set { Color = Serialize.StringToBrush(value); }
        }

        [NinjaScriptProperty]
        [Range(0, 100)]
        [Display(Name="Opacity", Description="Opacity", Order=3, GroupName="Parameters")]
        public int Opacity
        { get; set; }

        #endregion

        }
        }​

        Comment


          #5
          Hi, this means you have the parameter list for Draw.Region incorrect. See all the valid overloads here:



          Make sure you are using a valid override for this method:

          Code:
          Draw.Region(NinjaScriptBase owner, string tag, int startBarsAgo,
                  int endBarsAgo, ISeries<double> series, double price, Brush areaBrush, int areaOpacity, int displacement = 0)
          Draw.Region(NinjaScriptBase owner, string tag, int startBarsAgo,
                  int endBarsAgo, ISeries<double> series1, ISeries<double> series2, Brush outlineBrush,
                  Brush areaBrush, int areaOpacity, [int displacement])
          Draw.Region(NinjaScriptBase owner, string tag, DateTime startTime,
                  DateTime endTime, ISeries<double> series, double price, Brush areaBrush, int areaOpacity)
          Draw.Region(NinjaScriptBase owner, string tag, DateTime startTime,
                  DateTime endTime, ISeries<double> series1, ISeries<double> series2, Brush outlineBrush, Brush areaBrush, int areaOpacity)​
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            Still isn't working, can you look at my simple code.

            Comment


              #7
              Hi, Please look at the first overload. The Region method needs two series, not a singular indicator value, which is a double value. It is also missing one more Brush color:

              Draw.Region(this, "TMA Band", CurrentBar, 0, TMA(High, 14), TMA(Low, 14), Brushes.Red, Brushes.Blue, 10);
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                Yup, thank you so much...

                Draw.Region(this, "TMA Band", CurrentBar, 0, TMA(High, Period), TMA(Low, Period), null, Color, Opacity);

                I apparently deleted it the first couple of go arounds, but that did the trick.​

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by CortexZenUSA, Today, 12:53 AM
                0 responses
                1 view
                0 likes
                Last Post CortexZenUSA  
                Started by CortexZenUSA, Today, 12:46 AM
                0 responses
                1 view
                0 likes
                Last Post CortexZenUSA  
                Started by usazencortex, Today, 12:43 AM
                0 responses
                5 views
                0 likes
                Last Post usazencortex  
                Started by sidlercom80, 10-28-2023, 08:49 AM
                168 responses
                2,265 views
                0 likes
                Last Post sidlercom80  
                Started by Barry Milan, Yesterday, 10:35 PM
                3 responses
                12 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Working...
                X