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

About OHLC and OHL indicator alerts

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

    About OHLC and OHL indicator alerts

    I think there are OHLC and OHL in the default indicator of NinjaScript, and I have made them to sound an alert when the previous day's high is updated on the same day, but when the update is automatic (attachment 1), some symbols are not alerted and not output.
    However, when I run it manually, it seems to output correctly as shown in attachment (2).
    What could be the cause?​
    Attached Files

    #2
    Hi, thanks for posting. Please first use Print() in your script to see the values the strategy is seeing. This is the best way to debug a condition:

    Print(PriorDayOHLC().PriorLow[0]);
    Print(PriorDayOHLC().PriorHigh[0]);

    This will show you why your alert is not triggering when expected.

    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply.

      I have described and executed the print, is that correct?

      I also verified again why the alerts are not sounded and output to the alert log, and it seems that stocks that renewed the previous day's high price for two consecutive days (the day before and the day of) are alerted and output to the alert log only when enabled in the Alert Properties setting.
      Therefore, it seems that issues that did not renew the previous day's high price on the previous day are alerted and output when the previous day's high price is renewed on the day of the renewal.
      So I would like to ask, how can I make the alert sound and be output to the alert log when the previous day's high price renews the previous day's bar high price, and then renews the previous day's high price the next day as well?​
      Attached Files
      Last edited by ラリー; 10-04-2022, 11:12 PM.

      Comment


        #4
        Hi, thanks for your reply. The first thing about using Prints, to make them useful, use them inside of your condition block so that you know when the condition becomes true e.g.

        if(<some condition>)
        {
        Print("Condition True");
        }

        The second issue is your condition described in the first post:

        "previous day's high is updated on the same day"

        If you are using PriorDayOHLC, this value does not change as it is taking the finalized OHLC prices from the previous day. If you want to keep track of the current day high, you can write something similar to this:

        Code:
        private double HighestHigh;
        protected override void OnBarUpdate()
        {
        if(Bars.IsFirstBarOfSession)
        {
        HighestHigh = 0;
        }
        
        if(High[0] > HighestHigh)
        {
        HighestHigh = High[0];
        Draw.Dot(this, "HighestHigh", false, 0, High[0]+TickSize*4, Brushes.Cyan);
        }
        
        }
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Thank you for your reply.

          The first thing about using Prints, to make them useful, use them inside of your condition block so that you know when the condition becomes true e.g.

          if(<some condition>)
          {
          Print("Condition True");
          }​
          I described the print on lines 142 to 145 but multiple errors were output.
          What is wrong with my description?​

          The second issue is your condition described in the first post:

          "previous day's high is updated on the same day"

          If you are using PriorDayOHLC, this value does not change as it is taking the finalized OHLC prices from the previous day. If you want to keep track of the current day high, you can write something similar to this:​

          That is exactly what I wanted to ask you, so thank you for understanding.

          I have described the code you provided as in the screenshot, is that correct?​
          Attached Files

          Comment


            #6
            Hi, thanks for the follow up. I will be limited in the time spent verifying custom code, this is so we can help all client requests in a timely matter. I attached my full test script if you would like to try it.

            Kind regards,
            -ChrisL
            Attached Files
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Thank you for your reply.

              Thank you for providing this information.
              I have tried that and would like to do the same in the attached case, is it possible?
              In other words, I would like to do the same thing for other than the highest price.​
              Attached Files

              Comment


                #8
                Hi, the drawing tools need a unique Tag parameter to stay on the chart, since we are using an non-uniquie string "HighestHigh" the draw object gets moved every time we call Draw.Dot. To change this, make the Tag unique by appending the CurrentBar value to the tag e.g.

                "HighestHigh" + CurrentBar
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you for your reply.

                  I added "HighestHigh" + CurrentBar as attached (#1) and executed it and it seems that the highest highs are marked, but I would like to have an alert when the previous day's high (Oct 5) is updated to the current day's high (Oct 6), for example.
                  The same is true in the past.

                  Also, this script is colored for all the bars that have broken the previous day's high, and I would like the chart or market analyzer to sound an alert for those bars.

                  Attached Files

                  Comment


                    #10
                    Hi, thanks for the follow up. What does it mean for the previous day's high to be updated to the current day's high? Does this mean you want to check if the current days high reaches the previous days high?

                    Kind regards,
                    -ChrisL
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      Thank you for your reply.

                      What does it mean for the previous day's high to be updated to the current day's high? Does this mean you want to check if the current days high reaches the previous days high?
                      Yes, it is.
                      We want to be alerted when the day's high reaches the previous day's high.​

                      Comment


                        #12
                        Hi, thanks for confirming. You can do this using C# code to compare values on every bar update. We recommend being at least intermediate level using, reading, and writing C# code for the best experience using NinjaScript. The publicly available dotnetperls is a good starting place for written tutorials. https://www.dotnetperls.com/

                        You can use the CurrentDayOHL and PriorDayOHL indicators to compare each High price on every bar:



                        Kind regards,
                        -ChrisL
                        Chris L.NinjaTrader Customer Service

                        Comment


                          #13
                          Thank you for your reply.

                          I can already sound alerts with the default Current dayOHLC and Current dayOHL in NinjaScript, but the problem is that
                          If I enable the alerts before the Japanese market starts, the alerts go off when the conditions are met, but I want them to go off again when the conditions are met after the market starts.​

                          Comment


                            #14
                            Hi, thanks for the follow up. The frequency at which your conditions are checked is determined by the Calculate property of the script, so if you check your IF statement within OnBarUpdate, the frequency at which it will be checked depends on this setting:



                            In a Chart based alert (no script), you must check your Rearm type in the alert settings. Make sure its not set to Never.

                            Kind regards,
                            -ChrisL
                            Chris L.NinjaTrader Customer Service

                            Comment


                              #15
                              Thank you for your reply.

                              I checked the alert settings, OHLC and OHL settings and it does not seem to be Never.

                              I activated and verified it again today before the market opened for trading.
                              If it is before the market starts trading, all symbols that meet the conditions will sound an alert, but then after the market starts, there are symbols that do not sound an alert even though the conditions are met.
                              The common denominator of those symbols that did not sound seemed to be when the market gapped up (when the opening price of the day achieved the previous day's high) after the close.
                              However, if you manually reload NinjaScript, the alert will sound even for the symbols that do not sound.
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by alifarahani, Today, 09:40 AM
                              4 responses
                              19 views
                              0 likes
                              Last Post alifarahani  
                              Started by gentlebenthebear, Today, 01:30 AM
                              3 responses
                              15 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by PhillT, Today, 02:16 PM
                              2 responses
                              7 views
                              0 likes
                              Last Post PhillT
                              by PhillT
                               
                              Started by Kaledus, Today, 01:29 PM
                              3 responses
                              11 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by frankthearm, Yesterday, 09:08 AM
                              14 responses
                              47 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Working...
                              X