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

BarType as indicator parameter

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

    BarType as indicator parameter

    Hello,

    I have an indicator that plots figures on a daily chart based on intraday bars (most of the time 5 and 10 minutes charts) .

    I would like to try to compute the figures from seconds bars (say 30 seconds) .... is there anyway I could change the PeriodType in the add part ?


    What I have in mind is something like


    Add((PeriodType)("PeriodType." + typeOfBar), period);

    = > typeOfBar would be a string being Second or Minute

    This does not work as NT refuses the conversion from string to PeriodType

    Is there any way to do that ?

    Many Thanks

    #2
    Hello gabga100,

    Thank you for your post.

    Unfortunately, you cannot use a string in the manner you wish. The only way to set a user defined Period Type to be added to your chart is to add a private integer to the strategy that is used to determine the added Period Type.

    For example:
    Code:
            #region Variables
    		private int interval = 0;
            #endregion
    
            protected override void Initialize()
            {
    			if(interval == 1)
    			{
    				Add(PeriodType.Minute, 60);
    			}
            }
    
            protected override void OnBarUpdate()
            {
    			if(interval == 1 && BarsInProgress == 1)
    			{
    				Print(" 60 Minute Period Type has been added.");
    			}
            }
    
            #region Properties
    		[Description("1 = 60 Minute chart")]
    		[GridCategory("Parameters")]
    		public int Interval
    		{
    			get { return interval; }
    			set { interval = Math.Max(0, value); }
    		}
            #endregion
    Please let me know if you have any questions.

    Comment


      #3
      Originally posted by gabga100 View Post
      Hello,

      I have an indicator that plots figures on a daily chart based on intraday bars (most of the time 5 and 10 minutes charts) .

      I would like to try to compute the figures from seconds bars (say 30 seconds) .... is there anyway I could change the PeriodType in the add part ?


      What I have in mind is something like


      Add((PeriodType)("PeriodType." + typeOfBar), period);

      = > typeOfBar would be a string being Second or Minute

      This does not work as NT refuses the conversion from string to PeriodType

      Is there any way to do that ?

      Many Thanks
      PeriodType is an enum. You should be able to add a Property of type PeriodType to the indicator and select it from there.

      Comment


        #4
        Many Thanks ,

        it worked ...for the record I have used this


        switch (typeOfBar)
        {
        case barsType.Minute :
        Add(PeriodType.Minute, period);
        return;
        case barsType.Second :
        Add(PeriodType.Second, period);
        return;
        case barsType.Tick :
        Add(PeriodType.Tick, period);
        return;
        }

        I have another question .... what is the best way to plot not the price of a security but daily ratio of two securities, the OHLC of the ratio being plotted as a candle? Is it possible in the price panel and not as an indicator ?
        Many Thanks

        Comment


          #5
          Hello gabga100,

          Thank you for your update on this matter.

          You can find an example of this at the following link for a Spread Indicator with Candlesticks: http://www.ninjatrader.com/support/f...d=4&linkid=512

          You can download this indicator, import it into NinjaTrader and view the code by going to Tools > Edit NinjaScript > Indicator > SpreadCandlesticks.

          Please let me know if you have any questions.

          Comment


            #6
            Thank you , very much, very useful....

            When I try to use it to get the ratio of two instruments .... it suddenly stop to plot correctly ( see comparison enclosed)....

            I simply changed the + by / in the code

            SpreadOpen.Set(Qty1*Opens[0][0] / Qty2*Opens[1][0]);
            SpreadClose.Set(Qty1*Closes[0][0] / Qty2*Closes[1][0]);
            SpreadHigh.Set(Qty1*Highs[0][0] / Highs[1][0] );
            SpreadLow.Set(Qty1* Lows[0][0] / Lows[1][0] );

            Many Thanks
            Attached Files

            Comment


              #7
              Hello gabga100,

              Thank you for your response.

              The image you have attached looks to be correct here. Please hold down your Middle Mouse button over the last bar on the far right of your chart, does the date shown in the Mini Data Box read as the first of January 2013?
              Last edited by NinjaTrader_PatrickH; 01-03-2013, 07:21 AM.

              Comment


                #8
                Hello PatrickH,
                I have a similar question about changing the PeriodType. I followed the advice you gave in post #2. Instead of mins or seconds I used Range bars, so:
                Add(PeriodType.Range, 12);
                I added this indicator to a 4 range bar chart. I hoped that my indicator would print as if it were on a 12 range chart. It is printing differently than it would normally on a 4 range chart, but it is different than what a 12 range chart looks like. I'm thinking that I need to change the input series, but I don't know how. Any suggestions?
                Last edited by CaptainAmericaXX; 01-02-2013, 09:47 PM.

                Comment


                  #9
                  Hello CaptainAmericaXX,

                  Thank you for your post.

                  You will need to reference the BarsInProgress Index to reference when the 12 range is updating rather than whenever a bar is updated.

                  For information on BarsInProgress please visit the following link: http://www.ninjatrader.com/support/h...inprogress.htm

                  For information on using multiple instruments and timeframes in your strategy please visit the following link: http://www.ninjatrader.com/support/h...nstruments.htm

                  Please let me know if you have any questions.

                  Comment


                    #10
                    Patrick, thank you for directing me to those pages. I am certainly more educated. I am missing something though. I'm working with the TS SuperTrend indicator. I want to produce the levels it shows on a 12 range to show on a 4 range. Right now it's close, but no cigar. Would you be willing to look at both codes and offer a suggestion?
                    Attached Files

                    Comment


                      #11
                      Hello CaptainAmericaXX,

                      Thank you for your response.

                      You would either need to create a new indicator that calls the TSSuperTrend and adds the period type of 12 range to the indicator to be used in BarsArray for the TSSuperTrend and then call that on a new plot, or edit the TSSuperTrend to add in the 12 range period type and then use that as the input via BarsInProgress[1] and Closes[1][0] rather than Input[0] (anywhere Input[0] is used it would need to be replaced with Closes[1][0]).

                      For information on BarsArray please visit the following link: http://www.ninjatrader.com/support/h.../barsarray.htm
                      For information on BarsInProgress please visit the following link: http://www.ninjatrader.com/support/h...inprogress.htm
                      For information on Closes please visit the following link: http://www.ninjatrader.com/support/h...nt7/closes.htm

                      Please let me know if I may be of further assistance.

                      Comment


                        #12
                        Thank you for the suggestion Patrick. In the code I sent to you I did Add(PeriodType.Range, 12); and got an indicator on a 4 range chart similar to a 12 range, but with errors. I tried the Closes[1][0] idea and came up with similar results. Did you have a chance to look at the code I sent you?

                        Comment


                          #13
                          Hello CaptainAmericaXX,

                          Thank you for your response.

                          Please advise the name of the indicator you created as I do not believe I received that file.

                          Comment


                            #14
                            Here it is. Thanks
                            Attached Files

                            Comment


                              #15
                              Hello

                              Thank you for your response.

                              I do have those files, from the code in each file I assume you have created the RSMarketDirectionDot2.

                              The only part I see that still reflects pulling the data series the indicator is applied to is the following:
                              Code:
                                      private double Dtt(int nDay, double mult)
                                      {
                                          double hh = MAX(High, nDay)[0];
                                          double hc = MAX(Close, nDay)[0];
                                          double ll = MIN(Low, nDay)[0];
                                          double lc = MIN(Close, nDay)[0];
                                          return mult * Math.Max((hh - lc), (hc - ll));
                                      }
                              You will need to change this part of the code for the 12 range period type by adding the BarsArray[1] to the indicators MAX and MIN.

                              Please let me know if you have any additional questions.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by bortz, 11-06-2023, 08:04 AM
                              47 responses
                              1,602 views
                              0 likes
                              Last Post aligator  
                              Started by jaybedreamin, Today, 05:56 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post jaybedreamin  
                              Started by DJ888, 04-16-2024, 06:09 PM
                              6 responses
                              18 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by Jon17, Today, 04:33 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post Jon17
                              by Jon17
                               
                              Started by Javierw.ok, Today, 04:12 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post Javierw.ok  
                              Working...
                              X