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

Keltner Channel with Multi and EMAs

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

    Keltner Channel with Multi and EMAs

    Hi there

    I am trying to modify the KeltnerChannel indicator to be able to use with Multi timeframes. Basically I want to plot the KC from a 10 min chart on a 3 min chart.

    The code from the KeltnerChannel is straightforward.

    But how do I use the EMA with the BarsArray[1] when there is already two parameters needed as below?

    i.e.

    double offset = EMA(diff, Period)[0] * offsetMultiplier;


    with BarArray[1]??


    EMA(IDataSeries input, int period)[int barsAgo]

    I don't see in any examples how to deal with such a case and am stumped.

    My code:

    if (BarsInProgress == 0)
    {


    //diff.Set(High[0] - Low[0]);
    diff.Set(Highs[1][0] - Lows[1][0]); // changed from above

    //double middle = EMA(Typical, Period)[0];
    double middle = EMA(BarsArray[1],Period)[0];


    double offset = EMA(diff, Period)[0] * offsetMultiplier;
    //double offset = EMA(diff, Period)[0] * offsetMultiplier;

    double upper = middle + offset;
    double lower = middle - offset;

    Midline.Set(middle);
    Upper.Set(upper);
    Lower.Set(lower);


    }

    #2
    Hello,

    Perhaps there is more to your goal than I am aware but you can have the 10 minute KC plot on a 3 minute chart without custom coding.

    See attached image and notice the sections boxed in red.

    Additionally if you didn't want the 10 min bars to be visibly showing you could right click the Y axis of the 3 min and click maximize

    For more information on input series see "How to edit an indicator's parameters": http://www.ninjatrader.com/support/h...indicators.htm

    Let me know if I can be of further assistance.
    Attached Files
    LanceNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Lance View Post
      Hello,

      Perhaps there is more to your goal than I am aware but you can have the 10 minute KC plot on a 3 minute chart without custom coding.

      See attached image and notice the sections boxed in red.

      Additionally if you didn't want the 10 min bars to be visibly showing you could right click the Y axis of the 3 min and click maximize

      For more information on input series see "How to edit an indicator's parameters": http://www.ninjatrader.com/support/h...indicators.htm

      Let me know if I can be of further assistance.
      Hi Lance

      That works great except I have other plots so when I click maximize those are minimized as well. Is there a work around for that?

      Also can you clarify how to use the EMA with the multi?

      EMA(IDataSeries input, int period)[int barsAgo]

      so middle = EMA(BarsArray[1],Period)[0]; is fine

      but

      offset = EMA(diff, Period)[0] * offsetMultiplier;

      and we need the "diff" for the calculation.

      I diff to Highs[1][0] - Lows[1][0])....

      Comment


        #4
        Originally posted by ij001 View Post
        Hi Lance

        That works great except I have other plots so when I click maximize those are minimized as well. Is there a work around for that?
        Attached is an example of how you could arrange it. Unfortunately you can't completely hide the 10 minute but it's also not cluttering up any space. I drug the 10 min to the bottom of the chart and then shrunk it's panel size so that it's not taking up space.

        (you can drag series by left clicking them such that the black anchor points appear, once those show you can drag and drop the panel)

        You will also be able to do this with the EMA. You can set the EMA to use the 10min bars (or whatever series you'd like) and plot it on the 3min panel

        If you're set on making a custom indicator which takes a different time frame as input I would suggest reading through the following as it covers the usage of BarsInProgress: http://www.ninjatrader.com/support/h...nstruments.htm

        Please let me know if I can be of further assistance.
        Attached Files
        LanceNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Lance View Post
          Attached is an example of how you could arrange it. Unfortunately you can't completely hide the 10 minute but it's also not cluttering up any space. I drug the 10 min to the bottom of the chart and then shrunk it's panel size so that it's not taking up space.

          (you can drag series by left clicking them such that the black anchor points appear, once those show you can drag and drop the panel)

          You will also be able to do this with the EMA. You can set the EMA to use the 10min bars (or whatever series you'd like) and plot it on the 3min panel

          If you're set on making a custom indicator which takes a different time frame as input I would suggest reading through the following as it covers the usage of BarsInProgress: http://www.ninjatrader.com/support/h...nstruments.htm

          Please let me know if I can be of further assistance.
          Hi Lance

          Thanks.

          Now I have gone through the BIP documentation to see if there was something I was missing. Unfortantely, I can't find any examples on how to work with this.

          Would I have to overload the EMA or something to get it to work with the multi or is it okay as is?

          offset = EMA(diff, Period)[0] * offsetMultiplier;

          As I said I'm confused because of the need for the BarsArray[1]. I still think working inside BIP == 0 the primary timeframe is the best choice.

          Keltner Code with multi.

          if (BarsInProgress == 0)
          {


          //diff.Set(High[0] - Low[0]);
          diff.Set(Highs[1][0] - Lows[1][0]); // changed from above

          //double middle = EMA(Typical, Period)[0];
          double middle = EMA(BarsArray[1],Period)[0];


          double offset = EMA(diff, Period)[0] * offsetMultiplier;
          //double offset = EMA(diff, Period)[0] * offsetMultiplier;

          double upper = middle + offset;
          double lower = middle - offset;

          Midline.Set(middle);
          Upper.Set(upper);
          Lower.Set(lower);


          }

          Comment


            #6
            Hello,

            I went ahead and created a custom EMA indicator that uses the default time frame and a 10minute time frame.

            It draws 2 EMAs. One based on the primary and one based on the 10 minute.

            Note, due to the sloppy programming logic I used it will only work when COBC is true but should help you better understand how this can be done.

            I've re-read your post a couple times now and I'm not entirely sure I understand what you're trying to accomplish. Perhaps I can better explain with some more information.

            Please let me know if I can be of further assistance.
            Attached Files
            Last edited by NinjaTrader_Lance; 01-14-2013, 03:31 PM.
            LanceNinjaTrader Customer Service

            Comment


              #7
              Originally posted by ij001 View Post
              Hi Lance

              Thanks.

              Now I have gone through the BIP documentation to see if there was something I was missing. Unfortantely, I can't find any examples on how to work with this.

              Would I have to overload the EMA or something to get it to work with the multi or is it okay as is?

              offset = EMA(diff, Period)[0] * offsetMultiplier;

              As I said I'm confused because of the need for the BarsArray[1]. I still think working inside BIP == 0 the primary timeframe is the best choice.

              Keltner Code with multi.

              if (BarsInProgress == 0)
              {


              //diff.Set(High[0] - Low[0]);
              diff.Set(Highs[1][0] - Lows[1][0]); // changed from above

              //double middle = EMA(Typical, Period)[0];
              double middle = EMA(BarsArray[1],Period)[0];


              double offset = EMA(diff, Period)[0] * offsetMultiplier;
              //double offset = EMA(diff, Period)[0] * offsetMultiplier;

              double upper = middle + offset;
              double lower = middle - offset;

              Midline.Set(middle);
              Upper.Set(upper);
              Lower.Set(lower);


              }
              What is the error in your log? It seems you must be hitting some initial or boundary condition that is causing an exception.

              Comment


                #8
                Originally posted by NinjaTrader_Lance View Post
                Hello,

                I went ahead and created a custom EMA indicator that uses the default time frame and a 10minute time frame.

                It draws 2 EMAs. One based on the primary and one based on the 10 minute.

                Note, due to the sloppy programming logic I used it will only work when COBC is true but should help you better understand how this can be done.

                I've re-read your post a couple times now and I'm not entirely sure I understand what you're trying to accomplish. Perhaps I can better explain with some more information.

                Please let me know if I can be of further assistance.
                Hi Lance

                Thanks for your sample.

                What I got from it is that you can use BIP == 0 and BIP == 1 together.

                What I'm trying to do is use the pre-existing Keltner Channel indicator and plot 10 min Keltner channels on a smaller time frame.

                In this indicator there is an upper, middle, lower EMA. The middle EMA was the plotting of the 10 min EMA.

                I'm still a little confused to how we use the Values[0], Values[1], etc. That is probably why my updated code below is still a bit off compared to a regular 10 min chart plotting the Keltner channels when compared.
                Attached Files

                Comment


                  #9
                  Hello,

                  Originally posted by ij001 View Post
                  I'm still a little confused to how we use the Values[0], Values[1], etc. That is probably why my updated code below is still a bit off compared to a regular 10 min chart plotting the Keltner channels when compared.
                  Values[x] will refer to the
                  Midline is what you will get when you call Values[0]
                  Upper
                  Lower

                  I've attached an updated version which should help illustrate how you can use a secondary data series to plot the values.

                  For a forum example: http://www.ninjatrader.com/support/f...ead.php?t=3572

                  Please let me know if I can be of further assistance.
                  Attached Files
                  LanceNinjaTrader Customer Service

                  Comment


                    #10
                    Hi Lance

                    Thanks for all your help. Both examples were really helpful.

                    Last question in general why do we need to use

                    EMA(Typical, period)[0] ?

                    Can't we just call EMA(period)[0]?

                    Don't we need just the closing price of the EMA?

                    Irvin

                    Comment


                      #11
                      Hello,

                      Originally posted by ij001 View Post
                      Last question in general why do we need to use

                      EMA(Typical, period)[0] ?

                      Can't we just call EMA(period)[0]?

                      Don't we need just the closing price of the EMA?
                      You could do this however it would not be the same result. EMA can take either a period or period and an input series for its inputs.

                      The KC uses Typical in its calculations as this is (High + Low + Close) / 3 instead of the Close price which would be used in your example.
                      LanceNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by yertle, Yesterday, 08:38 AM
                      7 responses
                      28 views
                      0 likes
                      Last Post yertle
                      by yertle
                       
                      Started by bmartz, 03-12-2024, 06:12 AM
                      2 responses
                      21 views
                      0 likes
                      Last Post bmartz
                      by bmartz
                       
                      Started by funk10101, Today, 12:02 AM
                      0 responses
                      5 views
                      0 likes
                      Last Post funk10101  
                      Started by gravdigaz6, Yesterday, 11:40 PM
                      1 response
                      9 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by MarianApalaghiei, Yesterday, 10:49 PM
                      3 responses
                      11 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Working...
                      X