Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calling Alert() in a custom drawing tool, during OnRender()

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

    Calling Alert() in a custom drawing tool, during OnRender()

    As the title suggests, I have a custom drawing tool that I want to call Alert() in OnRender().

    It's not allowing me to call it as outlined here:


    Instead, it gives me a compiler error:

    PHP Code:
    Error    CS1955    Non-invocable member 'Alert' cannot be used like a method.    NinjaTrader.Custom    <myfile>.cs 
    Perhaps I need to call Alert() from a different context? (such as chartControl, GetAttachedToChartBars(), something else?)

    I CAN create an Alert object, then set all the values individually:

    PHP Code:
    Alert tempAlert = new Alert();
    tempAlert.Id "myId";
    tempAlert.Priority Priority.Medium;
    etc... 
    If I have to go this route, how to I trigger the alert object I just created? By this time in my code, the condition has been met and I need to simply fire off the alert immediately.

    Further, I can call PlaySound() or SendMail() without the compiler complaining, but they don't seem to actually do anything runtime.

    Any help is greatly appreciated!
    Last edited by neoikon; 10-29-2015, 08:36 AM.

    #2
    Hello,

    Thank you for reporting this. I'm not seeing the same on my end -- Alert() is working as a method from within OnBarUpdate(), as expected. Can you please send me a sample script which would reproduce this issue, so that I can investigate further?
    Dave I.NinjaTrader Product Management

    Comment


      #3
      My issue is with the OnRender() method, not OnBarUpdate()

      Comment


        #4
        Hello neoikon,

        You can do this by creating an object reference. For example:
        Code:
        	public class TestDrawingTool : DrawingTool
        	{
        		private IndicatorBase i = new IndicatorBase();
        And then in OnRender():
        Code:
        		public override void OnRender(ChartControl chartControl, ChartScale chartScale)
        		{
        			i.Alert("myAlert", Priority.High, "Reached threshold", [email]NinjaTrader.Core.Globals.InstallDir+@"\sounds\Alert1.wav[/email]", 10, Brushes.Black, Brushes.Yellow);

        Comment


          #5
          Great! This got it to compile. However, it still doesn't actually do anything at runtime.

          I tested these without luck:

          i.Alert(), i.PlaySound(), i.SendMail()

          I'm thinking it's just an empty object and not actually in the context of the chart, since I tried to print out various other values within indicatorBase and they were empty.

          Perhaps I don't want to create a new one, but access the existing one? If so, how do I access the "IndicatorBase" from within the context of a "custom drawing tool"?
          Last edited by neoikon; 10-30-2015, 07:42 AM.

          Comment


            #6
            Can you please clarify exactly how you would like to use the alert within your drawing tool? There may be a better way to accomplish what you are looking for, rather than triggering the alert in the drawing tool itself. For example, if you are looking to detect when the market price crosses within your drawing tool (or anything similar), perhaps a supplementary indicator would be a better option for processing the alert.
            Dave I.NinjaTrader Product Management

            Comment


              #7
              I need the user to be able to draw a line (or multiple lines) (not drawn by an indicator), then output an alert based on price in relation to that line.

              Looking at it in another direction, if I draw a normal line in NT, I can right-click and attach an alert to it. Is there a way to do something similar through NinjaScript?

              Thank you!
              Last edited by neoikon; 11-04-2015, 12:48 PM.

              Comment


                #8
                You should be able to accomplish that by calling the Alert() method when your script detects Close[0] crossing above or below the price at which the line sits. To obtain the price of the line's anchor points, you can obtain a reference to the Line object within the DrawObjects collection, and the Line object will contain a StartAnchor and LastAnchor property, each of which will expose a Price property essentially giving you the y-axis coordinates of both anchor points, like so:

                Code:
                foreach (DrawingTool dt in DrawObjects)
                            {
                                if (dt.GetType().ToString() == "NinjaTrader.NinjaScript.DrawingTools.Line")
                                {
                                   NinjaTrader.NinjaScript.DrawingTools.Line ln = dt as NinjaTrader.NinjaScript.DrawingTools.Line; // dt.Anchors[0].
                
                                      triggerPrice = ln.EndAnchor.Price;
                                }
                            }
                Note that it is important to safely cast the Line object to the correct type to avoid ambiguity between NinjaTrader.NinjaScript.DrawingTools.Line and NinjaTrader.Gui.Line.
                Dave I.NinjaTrader Product Management

                Comment


                  #9
                  Originally posted by NinjaTrader_Dave View Post
                  You should be able to accomplish that by calling the Alert() method when your script detects Close[0] crossing above or below the price at which the line sits. To obtain the price of the line's anchor points, you can obtain a reference to the Line object within the DrawObjects collection, and the Line object will contain a StartAnchor and LastAnchor property, each of which will expose a Price property essentially giving you the y-axis coordinates of both anchor points, like so:

                  Code:
                  foreach (DrawingTool dt in DrawObjects)
                              {
                                  if (dt.GetType().ToString() == "NinjaTrader.NinjaScript.DrawingTools.Line")
                                  {
                                     NinjaTrader.NinjaScript.DrawingTools.Line ln = dt as NinjaTrader.NinjaScript.DrawingTools.Line; // dt.Anchors[0].
                  
                                        triggerPrice = ln.EndAnchor.Price;
                                  }
                              }

                  Dave, Isn't this going to face the same object null reference error we were discussing from another thread, if the user compiles any script and then refreshes any chart that has this code in an indicator applied to it?


                  -=Edge=-
                  NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

                  Comment


                    #10
                    Originally posted by -=Edge=- View Post
                    Dave, Isn't this going to face the same object null reference error we were discussing from another thread, if the user compiles any script and then refreshes any chart that has this code in an indicator applied to it?


                    Yes, this is always a possibility when compiling at runtime when these objects from the custom assembly already exist.
                    MatthewNinjaTrader Product Management

                    Comment


                      #11
                      Originally posted by NinjaTrader_Dave View Post
                      You should be able to accomplish that by calling the Alert() method when your script detects Close[0] crossing above or below the price at which the line sits.
                      Thank you for the information, though it's disappointing. I have my drawing tool completely built and working, except that Alert() does nothing.

                      Unfortunately, it feels more like a hack to have an indicator perform the alert (or any action) of a drawing tool. It seems like this is becoming my norm, when creating drawing tools.

                      Any chance the Alert() functionality will be changed/exposed in the future?

                      Comment


                        #12
                        I've got some clarification on this, which should make your day. The Alert() method is actually a convenience method accessible in only a few NinjaScript Types. However, there is another method which can be called from a Drawing Tool directly: AlertCallBack(). It functions the same way, but with a more robust constructor, and it should do the job that you are looking to do.

                        You can find more information about AlertCallBack() and other lower-level methods which can be used in place of higher-level convenience methods in any NinjaScript Type:

                        Dave I.NinjaTrader Product Management

                        Comment


                          #13
                          Thanks! I think this will give me what I need (as well as the other functions mentioned in that article, for the future)

                          As an aside, I did figure out this hack, where I can trigger the alert in the context of one of the existing indicators:

                          PHP Code:
                          if (chartControl.Indicators.Count 0)
                            
                          chartControl.Indicators[0].Alert(...); 
                          If there are no indicators on the chart, it also requires adding a dummy indicator, calling the alert, then removing the dummy indicator. (Obviously, sloppy and poor performance!) However, I couldn't get that bit to work right.

                          Thanks again!
                          Last edited by neoikon; 11-05-2015, 11:08 AM.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Pattontje, Yesterday, 02:10 PM
                          2 responses
                          15 views
                          0 likes
                          Last Post Pattontje  
                          Started by flybuzz, 04-21-2024, 04:07 PM
                          17 responses
                          229 views
                          0 likes
                          Last Post TradingLoss  
                          Started by agclub, 04-21-2024, 08:57 PM
                          3 responses
                          17 views
                          0 likes
                          Last Post TradingLoss  
                          Started by TradingLoss, 04-21-2024, 04:32 PM
                          4 responses
                          44 views
                          2 likes
                          Last Post TradingLoss  
                          Started by cre8able, 04-17-2024, 04:16 PM
                          6 responses
                          57 views
                          0 likes
                          Last Post cre8able  
                          Working...
                          X