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

Question about how 'rearm' parameter works on Alerts.

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

    Question about how 'rearm' parameter works on Alerts.

    Hi - new to alerts, making progress, but am wondering about my latest situation:

    * Setup some alerts on 15sec/30sec charts, having to do with moving averages.
    * Same code for both. Wanna run same alert code across different time intervals.
    * 60 sec rearm interval, as with short term charts, I don't want the bell ringing all of the time.
    * Works great

    So, time to test longer charts...

    Setup same alert with 1min, 2min, 3min, 4min charts for testing.

    15s/30s alerts fire off very frequently, but have only had the 1min fire off just one time. Nothing with the 2m/3m/4m so far.

    So, I'm wondering if by running the same alert on all of the charts, the 60 sec rearm parm being in effect on 15s/30s charts is suppressing the alerts on 2m/3m/4m charts.

    Does Ninja treat each occurrence of the alert separately or is it one big glob?

    If problem here, is the workaround to make multiple copies of the alert and assign each one uniquely to each chart?

    #2
    Hello AMATX,

    The Alerts use ids. If an id is re-used, that alert will be triggered for both and both can set the re-arm seconds. (This is unique to the instrument)

    With NinjaTrader 7, if in a 3 second chart an alert with an id is triggered with the re-arm seconds set to 30 seconds, and there is a 10 second chart using the ame instrument where an alert with that same id is being triggered with the re-arm seconds set to 1, you will see the 3 second chart alerting every 30 to 33 seconds. The alerts from the 10 second chart will only appear if the 10 second bar closes 30 seconds after the 3 second alert and gets the alert triggered before the 3 second bar closes again. If it is able to alert in that short window an alert will appear for the 10 second bar. This means that the alerts from the 10 second bar will rarely appear.

    The answer here is to use unique alert ids.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I was hoping to use the same chunk of code on a bunch of charts, checking the same moving averages.

      Am I understanding your reply to mean I will have to have separate alerts for each chart, so as to make sure the alert ids are unique? I didn't think there was a way to use the same code but specify a different name for each chart.

      Essentially, same script code, different alerts names, which means a script file for each chart?

      Comment


        #4
        Hi AMATX,

        You can use the same code in the same script.
        You need to use a unique id for the each instance of the script for the Alert in that code.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea - doesn't this mean I need a bunch of separate script files, since the alert name is coded in the alert itself?

          I know I can reuse the same logic and coding, but the only place I see to place the alert name is inside the actual alert.

          So, if I have 1min, 2min, 3min, 4min, 5min charts, I need 5 copies of the script file, each one referencing unique alert ids?

          Comment


            #6
            Hello AMATX,

            Its your decision how you run everything, but no, having different versions of the file is not necessary.

            You only need to make the id for the alert unique.

            You could add the date and time to the id.
            Or add the interval and bar type to the id (this would separate bar type, instrument, and interval, but if you had two charts with the same bar series info they would again interfere).
            You could have a user defined input that the user types something unique into. (but if the user didn't make these unique then the original issue remains)
            You could generate a unique string using GetAtmStrategyUniqueId(). http://ninjatrader.com/support/helpG...gyuniqueid.htm

            There are probably other ways to make a unique id like incrementing a value in a file, or incrementing a value in a static class, but some ways would be inefficient or unsupported.

            For example:
            In #region Variables:
            Code:
            private string alertId;
            In OnStartUp():
            Code:
            alertId = string.Format("ReuseAlertIdsTest{0}", DateTime.Now.ToString());
            In OnBarUpdate() (or wherever the alert is being triggered):
            Code:
            Alert(alertId, Priority.Medium, string.Format("{0} {1}", BarsArray[0].Period.Value, BarsArray[0].Period.Id), string.Empty, 1, Color.White, Color.Black);
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Got it. Thanks.

              I like the time version and the get unique string thing. Anything to get a value that'll not be used again...

              Too new to Ninjascript to know the ins/outs, but I can see how your approaches would work.
              Last edited by AMATX; 11-02-2016, 02:21 PM.

              Comment


                #8
                Well, Chelsea, it all seems to be working ok now. I tried GetAtmStrategyUniqueId() and appear to be getting exactly what I should.

                As mentioned, I'm kinda new to Ninjascript and had focused on just getting the alerts to work. Hadn't gotten into the weeds on alert names, etc. Didn't know I could 'variable-ize' those.

                Gives me some options on having one chunk of code for all of my charts, but by checking various variables to determine which chart is running the code, I can change some things, such as the rearm interval, depending upon whether a short chart(1m) vs. long chart(30m).

                Thanks again.

                Comment


                  #9
                  Hello AMATX,

                  In C# (not just NinjaScript) a variable can be used anywhere in place of an object as long as the variable is the same type.

                  If the parameter or value compared is a string, then a variable that is a string can be substituted. This is true of all variable types in C# (and pretty much all programming languages).
                  Chelsea B.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by TradeForge, 04-19-2024, 02:09 AM
                  2 responses
                  28 views
                  0 likes
                  Last Post TradeForge  
                  Started by aprilfool, 12-03-2022, 03:01 PM
                  3 responses
                  327 views
                  0 likes
                  Last Post NinjaTrader_Adrian  
                  Started by giulyko00, Today, 12:03 PM
                  1 response
                  5 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by f.saeidi, Today, 12:14 PM
                  1 response
                  4 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by AnnBarnes, Today, 12:17 PM
                  1 response
                  2 views
                  0 likes
                  Last Post NinjaTrader_Zachary  
                  Working...
                  X