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.
    Browse examples for many languages, with explanations and code side by side for easy understanding.


    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.


    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:

        Price alert indicator for NinjaTrader 8. The chart Alerts window functionality replaces the need for this NinjaTrader 7 indicator, but has been created at user request. See more about chart alerts: https://ninjatrader.com/support/helpGuides/nt8/alerts.htm Exported with 8.0.21.0. (Update March 11th, 2020 – Added re-arm ability, can be added to other panels, trigger price updates to line position […]


        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:



        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", NinjaTrader.Core.Globals.InstallDir+@"\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 algospoke, 04-17-2024, 06:40 PM
            6 responses
            48 views
            0 likes
            Last Post algospoke  
            Started by arvidvanstaey, Today, 02:19 PM
            4 responses
            11 views
            0 likes
            Last Post arvidvanstaey  
            Started by samish18, 04-17-2024, 08:57 AM
            16 responses
            61 views
            0 likes
            Last Post samish18  
            Started by jordanq2, Today, 03:10 PM
            2 responses
            9 views
            0 likes
            Last Post jordanq2  
            Started by traderqz, Today, 12:06 AM
            10 responses
            19 views
            0 likes
            Last Post traderqz  
            Working...
            X