Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

New to creating indicators

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

    New to creating indicators

    Hello,

    Is there any reason why a custom indicator can't reference any bars back before [1]?

    This is my first try at coding an indicator...I took the default CCI indicator and gutted it (it was the most basic) and started experimenting with things. I was working on calculations involving the last three bars, and trial and error revealed that once I added the third bar back, I got a blank panel. I eliminated everything else and just tried to plot the RSI of three bars ago and still got a blank panel

    This is probably very obvious to veteran indicator coders out there, but I'm stumped.


    Code:
                            if (CurrentBar == 0)
    				Value.Set(0);
    			else
    			{
    				double mean = 0;
    				for (int idx = Math.Min(CurrentBar, Period - 1); idx >= 0; idx--)
    					mean += Math.Abs(Typical[idx] - SMA(Typical, Period)[0]);
    				//Value.Set((Typical[0] - SMA(Typical, Period)[0]) / (mean == 0 ? 1 : (0.015 * (mean / Math.Min(Period, CurrentBar + 1)))));
    
    
    				Value.Set(RSI(14,3)[2]);
    			}

    #2
    Hello,

    This is most likely because there is no check for data in this script.

    You have a check for the bar 0 but the bars after are not checked if there is enough data.

    What you can do, is instead of:

    Code:
     if (CurrentBar == 0)
    	Value.Set(0);

    Code:
    if(CurrentBar < 3)
    {
    Value.Set(0);
    return;
    }
    This sets 0 to the plot, but then returns after until at least 3 bars are on the chart, then you can access 3 bars ago without any error.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Bingo, thanks!

      Is it possible to plot two different lines based on two completely different calculations/input sources in the same indicator?

      Comment


        #4
        Hello,

        Yes that is certainly possible,

        you will need to add an additional Plot to do this.

        Currently you are using Value.Set which sets the default or plot at index 0.

        When working with multiple plots, you can use Values instead to specify a certain plot, here is more info on that: http://www.ninjatrader.com/support/h...ightsub=values

        Here is information on Plots http://www.ninjatrader.com/support/h...hlightsub=plot

        For a better example on this, you could look at the code used in the Bollinger indicator.
        please note the Initialize and OnBarUpdate and the Properties, all three sections tie together to show how a Plot is created and also referenced by a specific name instead of Value or Values.

        In Initialize, you create the actual plots. In the Properties section, you define a public property that is associated with the Plots Values index. Finally that public property is used in OnBarUpdate to set or get the value of the plot.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks very much for the info. I've created a very rough but functional indicator based on the structure of the Bollinger. It got me thinking, is it possible to plot a line in an indicator based on data from another chart? Does the whole BarsArray[1] thing work in indicators as well as strategies?

          Comment


            #6
            Hello,

            Yes the BarsArray is just a multi series concept, this means both strategies and indicators can Add additional data that can be used for calculations.

            If you take a look at this page:


            This shows how to Add additional data, and has a simple example on using that data. Additionally BarsInProgress is a important concept to go along with this: http://www.ninjatrader.com/support/h...inprogress.htm

            By adding additional series, you can add data for an entirely different instrument to produce calculations, this is not referencing any other charts directly but instead just adding it to the chart where the indicator or strategy is running.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by trilliantrader, 04-18-2024, 08:16 AM
            4 responses
            18 views
            0 likes
            Last Post trilliantrader  
            Started by mgco4you, Today, 09:46 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by wzgy0920, Today, 09:53 PM
            0 responses
            9 views
            0 likes
            Last Post wzgy0920  
            Started by Rapine Heihei, Today, 08:19 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by Rapine Heihei, Today, 08:25 PM
            0 responses
            10 views
            0 likes
            Last Post Rapine Heihei  
            Working...
            X