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

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 cre8able, 05-09-2024, 09:15 PM
    3 responses
    21 views
    0 likes
    Last Post cre8able  
    Started by jpeep, 08-16-2020, 08:31 AM
    17 responses
    502 views
    0 likes
    Last Post notenufftime  
    Started by ETFVoyageur, 05-07-2024, 07:05 PM
    15 responses
    124 views
    0 likes
    Last Post ETFVoyageur  
    Started by esmall, Today, 07:14 PM
    0 responses
    11 views
    0 likes
    Last Post esmall
    by esmall
     
    Started by Option Whisperer, 05-09-2024, 07:58 PM
    6 responses
    26 views
    0 likes
    Last Post Option Whisperer  
    Working...
    X