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 babouin77, Yesterday, 06:04 PM
          1 response
          17 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Daddy_Trader21, Yesterday, 05:04 PM
          3 responses
          25 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by ernest93, Today, 01:08 PM
          0 responses
          7 views
          0 likes
          Last Post ernest93  
          Started by Unsuitable, Yesterday, 02:54 PM
          1 response
          23 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by elnoppo, Yesterday, 10:24 AM
          1 response
          16 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X