Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Configure AlertRearmType in script

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

    Configure AlertRearmType in script

    Hello everyone,

    I try to configure the AlertRearmType in my own MarketAnalyzerColumn. Until now I found this solution:

    protected override void OnMarketData(Data.MarketDataEventArgs marketDataUpdate)
    {
    if (RSI1.Default[0] < 50)

    Alert("myAlert", Priority.High, "RSI under 50", NinjaTrader.Core.Globals.InstallDir + @"\sounds\Alert.wav", 60, Brushes.Transparent, Brushes.Black);


    But I want to add something like "AlertRearmType = OnConditionReversed;" Because when the Alert Rearm Type is "on timer" I get the same alert in this case every 60 seconds.

    Has anyone an idea?

    Best Regards
    Andreas



    #2
    Welcome to the forums Andreas189!

    There is not a parameter for setting ReArm type from the Alert method. As the Alert method would not have knowledge of the condition that fires it, you would need to use your own logic to control when the Alert method would be called.

    For example, you could check if a bool "AlertFired" is false before firing the alert, and then set "AlertFired" to true once the alert is fired. You could then check if the opposite condition is true if (RSI1.Default[0] > 50) and then set the bool back to false. This would provide the functionality to fire the alert only once until the condition that triggers the alert has been reversed.

    Please let me know if I can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      That's a good idea. I will try it. Manys thanks for the quick response.

      Comment


        #4
        I tried this:

        bool alert1 = false;
        // Alert 1
        if (RSI1.Default[0] < 50 && (alert1 = false))
        Alert("myalert", Priority.High, "RSI under 50", NinjaTrader.Core.Globals.InstallDir + @"\sounds\Alert.wav", 5, Brushes.Transparent, Brushes.Black);
        alert1 = true;
        if (RSI1.Default[0] > 50 && (alert1 = true))
        alert1 = false;


        Now I get no alerts. Did I any mistake?



        Comment


          #5
          Hello Andreas189,

          Creating your bool within OnMarketData's scope will have a new bool created and initialized as false each time OnMarketData is called.

          The bool should be created in the scope of the class in order to maintain that value between OnMarketData iterations.

          Please let us know if we can be of further assistance.
          JimNinjaTrader Customer Service

          Comment


            #6
            Ah, okay.

            I put it there:

            public class MyAlert : MarketAnalyzerColumn
            {
            private RSI RSI1;
            bool alert1 = false;

            For a better understanding here is the complete script:

            #region Using declarations
            using System;
            using System.Collections.Generic;
            using System.ComponentModel;
            using System.ComponentModel.DataAnnotations;
            using System.Linq;
            using System.Text;
            using System.Threading.Tasks;
            using System.Windows;
            using System.Windows.Input;
            using System.Windows.Media;
            using System.Xml.Serialization;
            using NinjaTrader.Cbi;
            using NinjaTrader.Gui;
            using NinjaTrader.Gui.Chart;
            using NinjaTrader.Gui.SuperDom;
            using NinjaTrader.Gui.Tools;
            using NinjaTrader.Data;
            using NinjaTrader.NinjaScript;
            using NinjaTrader.NinjaScript.Indicators;
            using NinjaTrader.Core.FloatingPoint;

            #endregion

            //This namespace holds MarketAnalyzerColumns in this folder and is required. Do not change it.
            namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
            {
            public class MyAlert : MarketAnalyzerColumn
            {
            private RSI RSI1;
            bool alert1 = false;

            protected override void OnStateChange()
            {
            if (State == State.SetDefaults)
            {
            Description = @"Geben Sie hier die Beschreibung für die neue benutzerdefinierte Marktscanner Spalte.";
            Name = "Mein Alarm";
            Calculate = Calculate.OnPriceChange;

            }
            else if (State == State.DataLoaded)
            {
            RSI1 = RSI(Close, 8, 14);
            }
            }
            protected override void OnMarketData(Data.MarketDataEventArgs marketDataUpdate)
            {
            // Alert 1
            if (RSI1.Default[0] < 50 && (alert1 = false))
            {
            Alert("myalert", Priority.High, "RSI under 50", NinjaTrader.Core.Globals.InstallDir + @"\sounds\Alert.wav", 5, Brushes.Transparent, Brushes.Black);
            alert1 = true;
            }
            if (RSI1.Default[0] > 50 && (alert1 = true))
            alert1 = false;
            }

            }
            }

            But I still don`t get alerts.

            Comment


              #7
              Hello Andreas189,

              In your conditions you are using assignment operator '=' instead of is equal operator '=='

              If you check for equality in your conditions, you should achieve what you are looking for.

              It will also be helpful to use debugging prints to check how your conditions are being evaluated so you can determine:

              1. if the Alert method is being reached (placing a print next to this method)
              2. if the logic is allowing the condition controlling the alert to become true. (placing a print outside of your condition to check the values used to evaluate that condition to see why that condition is evaluating as true or false.)

              Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

              Please let us know if we can be of further assistance.
              JimNinjaTrader Customer Service

              Comment


                #8
                OMG. What a absolut beginner mistake. Instead of thanks I have to say sorry. Shame of me. :-(

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by theoneuetous, Today, 11:22 PM
                0 responses
                1 view
                0 likes
                Last Post theoneuetous  
                Started by hbkopugwdmkb, Today, 11:10 PM
                0 responses
                1 view
                0 likes
                Last Post hbkopugwdmkb  
                Started by fastnet, Today, 10:58 PM
                0 responses
                3 views
                0 likes
                Last Post fastnet
                by fastnet
                 
                Started by tradingbobby, Today, 10:41 PM
                1 response
                6 views
                0 likes
                Last Post s.kinra
                by s.kinra
                 
                Started by bfalls, Today, 10:38 PM
                1 response
                7 views
                0 likes
                Last Post s.kinra
                by s.kinra
                 
                Working...
                X