Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Read Alerts Generated by other Indicators

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

    Read Alerts Generated by other Indicators

    Hello.
    Is there a way to read when writing a strategy aletrs generated in aletrswindow by other indicators?
    I've tried:
    foreach (KeyValuePair<string, IEnumerable<AlertEventArgs>> baseAlert in NinjaTrader.NinjaScript.Alert.AlertHistory)
    {
    foreach (AlertEventArgs alertEventArgs in baseAlert.Value)
    {
    Print("id: " + alertEventArgs.Id + " instrument: " + alertEventArgs.Instrument.FullName);
    }
    }

    But wont work.

    Thank you.
    Regards

    #2
    Hello motxu,

    Welcome to the NinjaTrader support forum.

    I wanted to ask, are the alerts happening in the same workspace? I do see this working on my end after testing the code you provided an indicator to generate alerts and a strategy to read it.

    Indicator causes an Alert:
    Code:
    Alert("Test" +  CurrentBar, Priority.High, "test Message", "",0,Brushes.Red, Brushes.Gold);
    Strategy Prints that from OnBarUpdate:

    Code:
    protected override void OnBarUpdate()
    {
        foreach (KeyValuePair<string, IEnumerable<AlertEventArgs>> baseAlert in NinjaTrader.NinjaScript.Alert.AlertHistory)
        { 
            foreach (AlertEventArgs alertEventArgs in baseAlert.Value)
            {
    	        Print("id: " + alertEventArgs.Id + " instrument: " + alertEventArgs.Instrument.FullName);
            }
        }
    }
    I can see the alert is updated.
    Code:
    id: Test20214699839150754002 instrument: ES 12-17
    It looks like there is a timestamp or some random increment appended to the ID which makes its print look this way.

    Could you provide more detail on your test using this code? Are you seeing no output or something unexpected?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hmmm

      Hello Jesse, thank you for your answer.
      Alerts generated in same workspace.
      This is the code:

      Code:
      #region Using declarations
      using System;
      using System.ComponentModel;
      using System.Diagnostics;
      using System.Drawing;
      using System.Drawing.Drawing2D;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Data;
      using NinjaTrader.Gui.Chart;
      using System.Windows.Forms;
      
      #endregion
      
      // This namespace holds all indicators and is required. Do not change it.
      namespace NinjaTrader.Indicator
      {
          /// <summary>
          /// Enter the description of your new custom indicator here
          /// </summary>
          [Description("Enter the description of your new custom indicator here")]
          public class NumTicks : Indicator
          {
              #region Variables
      
              #endregion
      
              /// <summary>
              /// This method is used to configure the indicator and is called once before any bar data is loaded.
              /// </summary>
              protected override void Initialize()
              {
              }
      
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
      protected override void OnBarUpdate()
      {
          foreach (KeyValuePair<string, IEnumerable<AlertEventArgs>> baseAlert in NinjaTrader.NinjaScript.Alert.AlertHistory)
          { 
              foreach (AlertEventArgs alertEventArgs in baseAlert.Value)
              {
      	        Print("id: " + alertEventArgs.Id + " instrument: " + alertEventArgs.Instrument.FullName);
              }
          }
      }
      
              #region Properties
              [Browsable(false)]	// this line prevents the data series from being displayed in the indicator properties dialog, do not remove
              [XmlIgnore()]		// this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
              public DataSeries Plot0
              {
                  get { return Values[0]; }
              }
              
              #endregion
          }
      }
      I get three errors on line 40:
      Indicator\NumTicks.cs El tipo o el nombre del espacio de nombres 'NinjaScript' no existe en el espacio de nombres 'NinjaTrader' (¿falta una referencia de ensamblado?) CS0234 - click for info 40 89

      Indicator\NumTicks.cs No se puede encontrar el tipo o el nombre de espacio de nombres 'IEnumerable' (¿falta una directiva using o una referencia de ensamblado?) CS0246 - click for info 40 35

      Indicator\NumTicks.cs No se puede encontrar el tipo o el nombre de espacio de nombres 'KeyValuePair' (¿falta una directiva using o una referencia de ensamblado?) CS0246 - click for info 40 14

      Comment


        #4
        Hello,

        Thank you for the additional details.

        I had not initially caught that this was posted in the NT7 subforum when I had replied as the syntax indicated to me this was for NT8. The code you have pasted was originally for NT8 which does work in NT8 but will not in NT7. There is no way I am aware of to capture the alerts in NT7, you would instead need to expose a signal from the indicator and then have the strategy call the indicator from code.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Ok.
          Thank you Jesse

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by algospoke, Yesterday, 06:40 PM
          2 responses
          19 views
          0 likes
          Last Post algospoke  
          Started by ghoul, Today, 06:02 PM
          3 responses
          14 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          44 views
          0 likes
          Last Post jeronymite  
          Started by Barry Milan, Yesterday, 10:35 PM
          7 responses
          20 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by AttiM, 02-14-2024, 05:20 PM
          10 responses
          180 views
          0 likes
          Last Post jeronymite  
          Working...
          X