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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    35 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    12 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    18 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    20 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X