Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Price Alert - starting

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

    Price Alert - starting

    Hello,

    how can one modify NT price alert indicator so that it comes up per default eg 20 ticks above current price? (when connecting to datafeed)

    Thank you
    Tony

    #2
    Hello tonynt,

    For the default indicators that come with NinjaTrader, the defaults are not editable but you can save a copy of it that is editable.

    To do this you would need to open the original in the NinjaScript editor, so :
    Tools -> Edit NinjaScript -> Indicator -> PriceAlert

    Once the editor window comes up, simply Right click in the window and click Save As..

    Give the file a new name and click ok.

    The editor window will be updated to reflect the new file that was created, no need to re open the file.

    For the changes you are looking for, I believe if you just change

    Code:
    protected override void OnStartUp()
    {
          triggered = fixedPrice > 0 ? false : true;
          price     = Instrument.MasterInstrument.Round2TickSize(fixedPrice);
    }
    to

    Code:
    protected override void OnStartUp()
    {
         triggered = fixedPrice > 0 ? false : true;
         price     = Instrument.MasterInstrument.Round2TickSize(Close[0] +(20 * TickSize));
    }
    That should do it, this will list a 0 price in the properties when you add the indicator, but when you click ok or apply it will apply the line 20 ticks above the Close[0] price.

    This would work for when you load your charts, for a update on the last price when connected to the data feed that may require some logic and using the OnMarketData method, although if you change the price depending on incoming ticks the alert would always be 20 ticks above the price, meaning the price could never be touched.

    Here is more information on the OnMarketData method in case you would like to try that.



    Please let me know if I may be of additional assistance.
    Last edited by NinjaTrader_Jesse; 07-15-2014, 10:53 AM.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse,

      thank you very much for your accurate information.

      I had saved the chart already as I do usually when modifiying indicators.
      Then I have changed referring to your instructions. But when clicking on apply or OK the line again is plotted at the current price.

      And another idea if this will not work - or even when work: how can I add this indicator within my script strategy please?

      if (condtion...)
      {"plot pricealert"}//in this case it can be at current price because I define the distance in the script


      Thank you in advance for your support!
      Tony



      Originally posted by NinjaTrader_Jesse View Post
      Hello tonynt,

      For the default indicators that come with NinjaTrader, the defaults are not editable but you can save a copy of it that is editable.

      To do this you would need to open the original in the NinjaScript editor, so :
      Tools -> Edit NinjaScript -> Indicator -> PriceAlert

      Once the editor window comes up, simply Right click in the window and click Save As..

      Give the file a new name and click ok.

      The editor window will be updated to reflect the new file that was created, no need to re open the file.

      For the changes you are looking for, I believe if you just change

      Code:
      protected override void OnStartUp()
      {
            triggered = fixedPrice > 0 ? false : true;
            price     = Instrument.MasterInstrument.Round2TickSize(fixedPrice);
      }
      to

      Code:
      protected override void OnStartUp()
      {
           triggered = fixedPrice > 0 ? false : true;
           price     = Instrument.MasterInstrument.Round2TickSize(Close[0] +(20 * TickSize));
      }
      That should do it, this will list a 0 price in the properties when you add the indicator, but when you click ok or apply it will apply the line 20 ticks above the Close[0] price.

      This would work for when you load your charts, for a update on the last price when connected to the data feed that may require some logic and using the OnMarketData method, although if you change the price depending on incoming ticks the alert would always be 20 ticks above the price, meaning the price could never be touched.

      Here is more information on the OnMarketData method in case you would like to try that.



      Please let me know if I may be of additional assistance.
      Last edited by tonynt; 07-15-2014, 01:00 PM.

      Comment


        #4
        Hello tonynt,

        You are correct, refreshing the chart or applying new indicators would reset the line as it is in the OnStartUp so every time the indicator starts, it would be reset.

        For this to work correctly, this would be best used as an alert when your chart is all set and ready to go, when you are not going to make changes to the chart. Because this is just a simple fix it can only do exactly what we told it to do which is to fill in the price as Close[0] + 20 * TickSize one time at start up.


        To add an indicator from a strategy you can use the Add method,
        Here is information regarding how to use the Add method in a strategy:


        Please let me know if I may be of additional assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello Jesse,

          thank you for your reply. Sorryif I caused some misunderstanding: yes, when refreshing it resets as in startup. But this is not what I meant: when i change the conditions to close[0]+20TickSize the line is applied at the current price and not 20Ticks away! I do not add indicators or refresh after having applied the pricealert, but at the start it is at the currentprice and not 20 Ticks away)

          This works for you?

          And another question please: when adding this indicator to my scriptstrategy can I use it as a trigger then for my exit eg "if low[0]<pricealertindicator && close[0]>pricealertindicator then exitlong()"? (same way as using eg an sma? and when moving the pricealertindicator can I work with this actual level then to use this as exitcondition as shown above?)


          Thank you
          Tony
          Last edited by tonynt; 07-15-2014, 03:33 PM. Reason: translation error

          Comment


            #6
            Hello,

            Thank you for the reply.

            After further review on the change to the PriceAlert indicator I have deemed that there is a better way to do it than I previously posted. I have attached the .cs file for you to use or take a look at.

            I changed from setting the value in OnStartUp to only calling it once when all the bars are loaded, guaranteeing that we get the last available price.

            I have also put a bool check to make sure this only happens one time for every time you load the indicator.



            For using values from an indicator in a strategy

            it’s actually really simple, let’s use the SMA as our test subject,

            In your strategy if you wanted to get the value of the SMA on the current bar you would simply need to do the following

            Code:
            SMA(14)[0];
            Let me break down what this is doing:

            In the line SMA(14)[0] we call the sma by its name that you see in the indicator list so SMA

            Next we provide the "overloads" or the properties that you can set when you apply the indicator to a chart so this would be the period for the sma so now we have SMA(14)

            This will give us the SMA dataseries but we want the double value, finally we just add [0] to get the current bars value leaving us with SMA(14)[0]

            The finished statement would look like this; this is a double variable that is equal to the value of the SMA 14 period for the current bar

            Code:
            double valueFromIndicator = SMA(14)[0];
            Some notes to assist in programming in the NinjaScript editor:

            I have attached a screenshot of what the intellesense dropdown looks like, if you have not used this before I would recommend it as it speeds things up.

            If you type SMA( into a strategy you should have the intellisense drop down telling you what overloads are required

            When you have the dropdown listed you can press the up or down arrow to scroll through the available overloads

            another way to get this menu to pop up is to click between the ( ) and press control+space on the keyboard.

            For your final question regarding working with the moving line in the price alert indicator, I will have to check into that and see if the default indicator is capable of this or if it would need to be modified.


            Please let me know if I may be of additional assistance.
            Attached Files
            Last edited by NinjaTrader_Jesse; 07-15-2014, 03:56 PM.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Hello Jesse,

              thank you for your reply!

              It works now and it would be great if the last part of my idea would work also. Can you please tell me if I can use the pricealertindicator same as an MA to be triggered. When I move the indicator will the new value of the indicator be related to the indicator and does the indicator has to be called from inside the script strategy to work with? like

              "if Open[0] < SMA(20)[0] && Close[0] > SMA(20)[0] then exitlong()"
              "if Open[0] < pricealert[0] && Close[0] > pricealert[0] then exitlong()"

              Thank you for your great support!


              Best regards
              Tony
              Last edited by tonynt; 07-16-2014, 02:28 PM. Reason: translation error

              Comment


                #8
                Hello,

                I looked into how the PriceAlert indicator is made and currently the way it is would not let you use the price value from the indicator.

                I tried modifying the PriceAlert2 indicator I posted previously but upon testing I was able to get the initial value from the indicator as far as what price I specify in its overloads, but when the line is moved the strategy is unable to catch this event.

                I don't think this would be an item that is an easy fix as it was originally not intended for this purpose. It would most likely require you to create a custom indicator partially using the code from the PriceAlert indicator for your line.

                I would not be able to create this indicator directly for you as this would take quite a bit of time but I will be happy to provide the resources to help you along the way if you so choose to create this.

                Please let me know if I may be of additional assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Hello Jesse,

                  thank you for you time and your help!

                  Then let me do 2 short questions please to have this indicator working without modifying values:

                  * when adding from my script strategy eg " Add(SMA(100));" this works
                  but with " Add(PriceAlert2(0, true, 20));" this doesn´t work and the price alert indicator is not plotted.

                  * I added
                  in line 120: SendMail("[email protected]", "[email protected]", "LTA", "Close Trade"); (but it doesn´t send)
                  and to control I did also "PlaySound(@"C:\Programme\NinjaTrader 7\sounds\AutoTrail.wav");" (but it doesn´t play) in line 121.

                  What might be the reason?

                  Thank you for all your help.

                  Best regards
                  Tony

                  Comment


                    #10
                    Hello tonynt,

                    You are correct, when adding the PriceAlert2 indicator using the Add() method, it does not plot a line and creates a non editable 0 value on the chart.

                    I don't believe you will be able to add the PriceAlert indicator using the Add method with the way it is created.

                    For your second question, it sounds like the segment of the script where you put the two lines is not being reached possibly, a quick way to check would be placing a
                    Code:
                    Print("test print");
                    statement before the two lines and then check the Tools -> Output panel to see if it printed.

                    I believe its most likely this line that may be causing this for you

                    Code:
                    if (Historical || triggered)
                                    return;
                    essentially if the line has been triggered or if the bars are historical the code below this statement would be ignored.

                    If you want to post the code with your changes I would be happy to take a look at it and see why it is not firing.

                    Please let me know if I may be of additional assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Hello Jesse,

                      thank you for your reply. Referring to your offer to have a look on I add the code where you can see that I have added only the lines to do the other sound to check and the email-message to send. Both are not done (only the sound in the alert line is done)

                      (I only changed the emailaddresses here to [email protected]) Usually my email-messages with Ninjatrader work fine with other indicators.

                      Thank you for your support.

                      Best regards
                      Tony
                      Attached Files

                      Comment


                        #12
                        Hello tonynt,

                        I took a look into the code, I am not entirely sure where the hangup was but I noticed when I compiled and loaded the test you posted I was unable to get the line to draw.

                        Rather than troubleshooting it I just took the previous edit I had posted and placed your sendmail and playsound in it so the line would come back and also changed the way you were specifying where the .wav file is located to the NinjaTrader equivalent.

                        Code:
                        PlaySound(Cbi.Core.InstallDir + @"\sounds\AutoTrail.wav");
                        I think possibly you may have had an error in the wav files location causing it to fail so the statement above insures that the correct directory is located.

                        Give this one a try and let me know if you run into any problems.

                        Please let me know if I may be of additional assistance.
                        Attached Files
                        JesseNinjaTrader Customer Service

                        Comment


                          #13
                          Hello Jesse,

                          thank you for your reply. When the indicator is set to COBC=false then referring description it is CPU intensive. But when set to COBC=true then there are only the pricemarkers on the y-axis visible but not the lines, not even at close of bar(??)

                          And one question more please: is it possbile to have the lines attached to all charts of an instrument per default (as it is possible with normal horizontal lines)?

                          Thank you so much for your support.

                          Best regards
                          Tony
                          Last edited by tonynt; 07-17-2014, 04:02 PM. Reason: typing error

                          Comment


                            #14
                            Hello tonynt,

                            The message about COBC being cpu intensive is true, although in this case this is ok as that is the setting from the original indicator and how it is intended to be used.

                            When you are working with more complex indicators that are processing large about of bars or calculations this can certainly play a role in how the chart performs.

                            For your second question, currently there is no supported way to do this unfortunately.

                            Please let me know if I may be of additional assistance.
                            JesseNinjaTrader Customer Service

                            Comment


                              #15
                              Hello Jesse,

                              thank you for all your support!

                              Have a great weekend.

                              Best regards
                              Tony

                              Originally posted by NinjaTrader_Jesse View Post
                              Hello tonynt,

                              The message about COBC being cpu intensive is true, although in this case this is ok as that is the setting from the original indicator and how it is intended to be used.

                              When you are working with more complex indicators that are processing large about of bars or calculations this can certainly play a role in how the chart performs.

                              For your second question, currently there is no supported way to do this unfortunately.

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

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by PaulMohn, Today, 12:36 PM
                              2 responses
                              16 views
                              0 likes
                              Last Post PaulMohn  
                              Started by Conceptzx, 10-11-2022, 06:38 AM
                              2 responses
                              53 views
                              0 likes
                              Last Post PhillT
                              by PhillT
                               
                              Started by Kaledus, Today, 01:29 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post Kaledus
                              by Kaledus
                               
                              Started by yertle, Yesterday, 08:38 AM
                              8 responses
                              37 views
                              0 likes
                              Last Post ryjoga
                              by ryjoga
                               
                              Started by rdtdale, Today, 01:02 PM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Working...
                              X