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

trying to set alert if high>Keltner upper band

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

    trying to set alert if high>Keltner upper band

    This is the Ninja Keltner indicator I renamed for this attempt.
    I cant figure out which Ninjascript line(s) identify the upper band.
    I plan on using it on a Renko chart.
    I'll do it for Lower after I get Upper resolved.
    The code section at issue is the area above Properties encased for now in /* */
    I already defined distK and dist in variables. KELTNER is what I'll replace with your answer
    thanks
    Code:
    [FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Initialize()[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]Add([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Plot(Color.Black, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Midline"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]));[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]Add([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Plot(Color.DeepPink, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Upper"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]));[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]Add([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Plot(Color.DeepPink, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Lower"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]));[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New] [/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]diff = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] DataSeries([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]this[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New] [/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]Overlay = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New] [/FONT][/SIZE]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]<summary>[/COLOR][/SIZE][/FONT]
    [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000] Called on each bar update event (incoming tick).[/COLOR][/SIZE][/FONT]
    [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]</summary>[/COLOR][/SIZE][/FONT]
    [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] OnBarUpdate()[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]diff.Set(High[[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] - Low[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]);[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New] [/FONT][/SIZE]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] middle = SMA(Typical, Period)[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]];[/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] offset = SMA(diff, Period)[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] * offsetMultiplier;[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New] [/FONT][/SIZE]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] upper = middle + offset;[/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] lower = middle - offset;[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New] [/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]Midline.Set(middle);[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]Upper.Set(upper);[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]Lower.Set(lower);[/FONT][/SIZE]
     
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]/* if (High[0]>=KELTNER+distK) [/COLOR][/SIZE][/FONT]
    [SIZE=2][FONT=Courier New][COLOR=#008000]{[/COLOR][/FONT][/SIZE]
    [SIZE=2][FONT=Courier New][COLOR=#008000]DrawDot(" up" + CurrentBar, false, 0,Low[0]- (TickSize*dist), Color.Cyan); [/COLOR][/FONT][/SIZE]
    [SIZE=2][FONT=Courier New][COLOR=#008000]if (alertBool)PlaySound(@"C:\mysounds\Corkpop.wav");[/COLOR][/FONT][/SIZE]
    [SIZE=2][FONT=Courier New][COLOR=#008000]}[/COLOR][/FONT][/SIZE]
    [SIZE=2][FONT=Courier New][COLOR=#008000]*/[/COLOR][/FONT][/SIZE][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
    Attached Files

    #2
    Hello simpletrades,

    Thanks for your post.

    The 3 lines that use .Set are the three plots.

    So you can use, for example:

    if (High[0] >= Upper[0]) // is the high greater than or equal to the keltner upper line.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks but now I have more questions. I see it working on the ES 3 min but the Renko ES I wanted it for doesnt work.
      Also even though i have Variables including
      private int distK = 2;
      private int dist = 2;
      the indicator pulldown doesnt offer the chance to adjust those 2 distances (distK is how far from keltner and dist is how far is the dot)
      I attached the cs file in my first post.
      Thanks again.

      Comment


        #4
        Hello simpletrades,

        Thanks for your reply.

        Do you see any error messages listed in the control centers "Log" tab that relate to the indicator?

        I've attached a screenshot showing that it works here along with the code used.

        If you want to adjust the two variables from the user interface, you will need to create a pubic property for each. Study the variable period and its public variable Period in the region properties as an example of how this works. You would need to replicate that structure, one for distK which will be an int and the other will need to be a double for offsetMultiplier.
        Attached Files
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          thanks i'll try again later at least you proved it works on renko. Later I'll filter it so if last bar was above upper it wont trigger over and over.

          Comment


            #6
            Hello simpletrades,

            Thanks for your reply.

            You may want to consider using the CrossAbove() and CrossBelow() methods that would help to show only when there is a cross.

            References:

            Paul H.NinjaTrader Customer Service

            Comment


              #7
              When it reads like this no diamonds appear and even Keltner doesnt draw.
              if (High[0]>Upper[0]& High[1]<Upper[1])

              If I just use if (High[0]>Upper[0]) then Keltner draws but I get diamonds all over and at 2 ticks above the high I picked.
              Why can't I filter it to not repeat if the prior was already above?

              Comment


                #8
                Hello simpletrades,

                Thanks for your reply.

                When you are working with ninjascript and apply an indicator and it does not appears as expected, always go to the "Log" tab of the control center to check for any error messages. Do you see any error messages?
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  I also tried if (CrossAbove(High,Upper)) but got an error No overload for method CrossAbove takes 2 arguments

                  Comment


                    #10
                    Hello simpletrades,

                    Thanks for your reply.

                    In the Cross methods you would also need to specify the lookback, this would typically be a value of 1.

                    Example: if (CrossAbove(High,Upper, 1))
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      that certainly cleans it up. now tomorrow i'll see if its been worth it.
                      Is there a way to pick an alert sound from each chart or should i just save one cs file for ES and one for CL with different sounds so I know where to look.

                      Comment


                        #12
                        Hello simpletrades,

                        Thanks for your reply.

                        You can add a string property to put a user interface place to enter a sound file (path and file name) that you can change.

                        for example:

                        in region variables:

                        private string preEventSound1 = @"Alert3.wav"; // Sound files


                        in region properties:

                        [Description("Enter the sound file/path for the 1st pre-Event timer")]
                        [Gui.Design.DisplayNameAttribute("2. 1st Pre-Event Soundfile")]
                        public string PreEventSound1
                        {
                        get { return preEventSound1; }
                        set { preEventSound1 = value; }
                        }


                        By default ninjaTrader will access the sound file as located in C:\program files(x86)\sounds\. If you know the name of the sound files, such as Alert1.wav, Alert2.wav, etc. you would be able to enter those. If you have your sounds in a different folder then you would need to supply the entire path and name. If you do not hear sounds, check your "log" tab for any errors.
                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          Thanks I'll try. I got rid of the diamonds because they arent a trade signal the sound is just telling me to watch a particular chart for a move up thru or down below the lower or upper bands.
                          I added another version that alerts when price closes above the lower or below the upper so tommorrow i'll see which is better. thats 4 charts 2 types each symbol but if i can pick sounds on the chart i only need 2 types of the indicator

                          Comment


                            #14
                            Havent tried the sound option but when I saw the need to add it to properties I realized why my dist and distK options werent showing so I added them to properties. Now they both show up except of course the distance from Keltner doesnt count using CrossAbove or CrossBelow but at least I have it.

                            Comment


                              #15
                              I'm getting no sound at all now. I tried setting up a pulldown choice but the sound kept being the one with the diamond so i removed the pulldown option but now I get no soumd. I only removed the line in Variables and the section in properties The diamonds draw but no noise and I'm using Corkpop so I can hear it. I'm using crossAbove on both cs files.
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Segwin, 05-07-2018, 02:15 PM
                              10 responses
                              1,769 views
                              0 likes
                              Last Post Leafcutter  
                              Started by Rapine Heihei, 04-23-2024, 07:51 PM
                              2 responses
                              30 views
                              0 likes
                              Last Post Max238
                              by Max238
                               
                              Started by Shansen, 08-30-2019, 10:18 PM
                              24 responses
                              943 views
                              0 likes
                              Last Post spwizard  
                              Started by Max238, Today, 01:28 AM
                              0 responses
                              10 views
                              0 likes
                              Last Post Max238
                              by Max238
                               
                              Started by rocketman7, Today, 01:00 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post rocketman7  
                              Working...
                              X