• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Alert conditions - static bars ago settings?

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

    Alert conditions - static bars ago settings?

    Hello,

    Is there any way that I can set the bars ago settings within alert conditions to a static point, so that the start of my look back period for the alert condition stays the same. e.g I can set it to 5 bars ago now and then when I am 10 bars into the future the alert will effectively be looking back 15 bars ago as my start point. I understand the conditions are dynamic by default so it will look back 5 bars ago, no matter how far into the future you are. I tried using the Excel code of putting "$" in front of the "bars ago" number in the conditions but that didn;t work.

    Thanks

    #2
    Hello b16_aln,

    Thank you for your post.

    While you couldn't do this using the Alerts window, you could certainly code a custom indicator containing an alert that would do this.

    We do have resources to help you begin creating NinjaScript Strategies/Indicators. All links below are publicly available.

    The best way to begin learning NinjaScript is to use the Strategy Builder. With the Strategy Builder you can setup conditions and variables and then see the generated code in the NinjaScript Editor by clicking the View Code button.

    I'm also providing a link to a pre-recorded set of videos 'Strategy Builder 301' and 'NinjaScript Editor 401' for you to view at your own convenience.

    Strategy Builder 301
    NinjaScript Editor 401

    If you are new to C#, to get a basic foundation for the concepts and syntax used in NinjaScript I would recommend this section of articles in our NT7 help guide first:
    Basic Programming Concepts

    For general C# education I have personally found Dot Net Perls to be a great reference site with easy to understand examples.
    https://www.dotnetperls.com/

    We also have great resources in relation to Strategy Development on our Support Forum. There is a very active developer community in our support forum that supplements the responses provided by NinjaTrader support staff providing all users with an exceptional support experience.
    Take me to your support forum!

    There are a number of indicators which come pre-configured in NinjaTrader that you can use as a starting point. These are found under New -> NinjaScript Editor -> Indicators. You will see locked indicators where you can see the details of the code, but you will not be able to edit (you can though always create copies you can later edit via right click > Save as)

    We also have some Reference samples online as well as ‘Tips and Tricks’ for both indicators and strategies:
    Click here to see our NinjaScript Reference Samples
    Click here to see our NinjaScript Tips

    These samples can be downloaded, installed and modified from NinjaTrader and hopefully serve as a good base for your custom works.

    Also, below I am also linking you to the Educational Resources section of the Help Guide to help you get started with NinjaScript.
    http://ninjatrader.com/support/helpG..._resources.htm

    Further, the following link is to our help guide with an alphabetical reference list to all supported methods, properties, and objects that are used in NinjaScript.
    Alphabetical Reference

    And our Educational Resources in the NinjaTrader 8 help guide.
    Educational Resources

    You can also contact one of our professional NinjaScript Consultants or Educators who would be eager to create or modify this script at your request or assist you with your script. Please let me know if you would like a list of professional NinjaScript Consultants or Educators who would be happy to create or modify any script at your request or assist you in learning NinjaScript.

    Please let me know if I may be of further assistance.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Could you give me a hand with what the code would look like? I'm not a coder. Thanks

      Comment


        #4
        Hello b16_aln,

        Thank you for your reply.

        I don't have an example of exactly this, but you could check out the Price Alert indicator publicly available on our User App Share for an example of including an alert in an indicator:

        https://ninjatraderecosystem.com/use...d/price-alert/

        You'd also need to make sure you're incrementing the number of bars to look back for your conditions each time OnBarUpdate() is triggered. I really suggest reviewing the educational links in my previous post, as well as some of the open source indicators included with NinjaTrader that you can find in the NinjaScript Editor. Also, I suggest taking a look at our help guide section on Alerts in NinjaScript:

        https://ninjatrader.com/support/help...nd_sharing.htm

        Please let us know if we may be of further assistance to you.

        The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Thanks, so for the start of my range, how would I write the code for current bar so that it remains static without having to input a time get bar code? And then for my end bar I want to be alwasy be the current bar so that it keeps updating as the new chart points plot.

          Comment


            #6
            Hello b16_aln,

            Thank you for your reply.

            You could add something like the following code:

            Code:
                    private SMA SMA1;
                    private bool IsAlertTriggered;
            
                    protected override void OnStateChange()
                    {
                        if (State == State.SetDefaults)
                        {
                            Description                                    = @"Enter the description for your new custom Indicator here.";
                            Name                                        = "BasicAlertLookback";
                            Calculate                                    = Calculate.OnBarClose;
                            IsOverlay                                    = true;
                             ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                            //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
                            //See Help Guide for additional information.
                            IsSuspendedWhileInactive                    = true;
                            LookbackBar                    = 5;
            
                            AddPlot(Brushes.Goldenrod, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameSMA);
                        }
                        else if (State == State.Configure)
                        {
                            SMA1 = SMA(10);
                            IsAlertTriggered = false;
                        }
                    }
            
                    protected override void OnBarUpdate()
                    {
                        if(CurrentBar < BarsRequiredToPlot)
                            return;
            
                        Value[0] = SMA1[0];
            
                        for(int i=0; i < LookbackBar; i++)
                        {
                            if(Close[0] > Value[i])
                            {
                                IsAlertTriggered = true; //set bool to true if our condition exists
                            }
                        }
            
                        if(IsAlertTriggered)
                        {
                            // play alert if our condition was true
                            Alert("myAlert", Priority.High, "Reached threshold", [email protected]"\sounds\Alert1.wav", 10, Brushes.Black, Brushes.Yellow); 
                        }
                        IsAlertTriggered = false; //reset alert bool
                        LookbackBar++; //increment bars to look back by 1
                    }
            
                    #region Properties
                    [NinjaScriptProperty]
                    [Range(1, int.MaxValue)]
                    [Display(Name="LookbackBar", Description="Starting bar for lookback", Order=1, GroupName="Parameters")]
                    public int LookbackBar
                    { get; set; }
                    #endregion

            Please let us know if we may be of further assistance to you.
            Kate W.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Newtrader101, Today, 03:54 PM
            1 response
            15 views
            0 likes
            Last Post NinjaTrader_ShawnB  
            Started by williamzz, Today, 03:28 PM
            0 responses
            7 views
            0 likes
            Last Post williamzz  
            Started by Robert87, Today, 11:07 AM
            0 responses
            13 views
            0 likes
            Last Post Robert87  
            Started by phta123, Today, 10:24 AM
            0 responses
            17 views
            0 likes
            Last Post phta123
            by phta123
             
            Started by sidviciousX, Today, 06:47 AM
            0 responses
            16 views
            0 likes
            Last Post sidviciousX  
            Working...
            X