Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to make my indicator work?

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

    how to make my indicator work?

    Hi,

    I'm developing a simple indicator that draws a line where prior day's close price is on 1 min chart. See my code below:

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class AutoDrawLine : Indicator
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description = @"Enter the description for your new custom Indicator here.";
                    Name = "AutoDrawLine";
                    Calculate = Calculate.OnEachTick;
                    IsOverlay = false;
                    DisplayInDataBox = true;
                    DrawOnPricePanel = true;
                    PaintPriceMarkers = true;
                    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive = true;
                    AddPlot(Brushes.CornflowerBlue, "Prior Close");
                }
                else if (State == State.Configure)
                {
                    AddDataSeries(Data.BarsPeriodType.Day, 1);
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (CurrentBar < 0)
                    return;
    
                Draw.HorizontalLine(this, "Prior Close", Closes[1][1], Brushes.Red);
    
            }
        }
    }
    1. For some reason, Closes[1][1] in Draw() method is not working. Nothing shows up on chart. But if I change it to a specific value, for example:
    Draw.HorizontalLine(this, "Prior Close", 40, Brushes.Red);
    This specific value shows up. So it must be my additional data series not working. Would you please tell me how to make it work?

    2. I need it to draw just one line everytime a daily bar is closed. It looks like my code will draw a lot of lines on chart everytime primary series bar is updated. Also, when a daily bar is closed, prior close price gets updated, the old line needs to be deleted. How can I make this work?

    Thank you very much for your help!




    #2
    Hello HiddenPhilosopher,

    Are there any errors appearing on the Log tab of the Control Center when reloading the script?

    It looks like this may have index errors as there are no checks that this bar exists.
    Hello, I want to create an indicator that show data in a chart but calculate in other charttime different to the time of the chart where is showed. For example:
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    606 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    351 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