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 charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    70 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    152 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    162 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    100 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    288 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X