Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Code Examples

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

    Code Examples

    I am relatively new to NT and I am trying to write a simple indicator to show examples of

    Highlight a bar;
    Place a marker on the chart; and
    Play a sound

    When Certian conditions occur. I do not get an error, but I do not get any markers, painted bar or sound.

    Where did I go wrong?


    ---------------------
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    ///<summary>
    /// This indicator will paint a bar, make a sound, place a marker
    ///</summary>
    [Description("This indicator will paint a bar")]
    publicclass PaintBar : Indicator
    {
    #region Variables
    // Wizard generated variables
    privateint myInput0 = 1; // Default setting for MyInput0
    // User defined variables (add any user defined variables below)
    #endregion
    ///<summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    ///</summary>
    protectedoverridevoid Initialize()
    {
    Add(
    new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
    CalculateOnBarClose =
    true;
    Overlay =
    true;
    PriceTypeSupported =
    false;

    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    if (Close[0] > Close[1])
    BarColor = Color.Pink;
    DrawTriangleUp(
    "MyTriangleUp", 0, Low[0] - 2 * TickSize, Color.Red);
    PlaySound(
    @"C:\Program Files\NinjaTrader 6.5\sounds\Alert1.wav");
    Last edited by velocity; 06-27-2008, 04:29 PM.

    #2
    Hi velocity,

    I'm not sure about everything wrong, but I can see two errors.
    Firstly you should put the block into parentheses or otherwise only the first line will count as part of the condition.
    Secondly, you will not get unique triangles drawn as you have not uniquely identified them per bar, so your latest triangle will always overwrite the previous.

    You could also try Alert() instead of PlaySound() as that plays a sound and shows an alert in the Alerts window, that way you know if its your sound system or the code.


    So something like :

    if (Close[0] > Close[1])
    {
    BarColor = Color.Pink;
    DrawTriangleUp(
    "MyTriangleUp"+CurrentBar, 0, Low[0] - 2 * TickSize, Color.Red);
    Alert("myAlert", NinjaTrader.Cbi.Priority.High, "Reached threshold", "Alert1.wav", 10, Color.Black, Color.Yellow);

    }

    Comment


      #3
      Thanks for taking a look. I got every example to work except I don't get an alert window. Any thoughts?

      See attached for what examples look like.

      thanks.



      protectedoverridevoid OnBarUpdate()
      {
      // Use this method for calculating your indicator values. Assign a value to each
      if (CurrentBar < 1)
      return;

      if (Close[0] > Close[1])
      BarColor = Color.Pink;
      if (Close[0] > Close[1])
      DrawArrowUp(
      "MyArrowUp"+CurrentBar, 0, Low[0]- (TickSize*2) , Color.Black);
      if (Close[0] > Close[1])
      PlaySound(
      @"C:\Program Files\NinjaTrader 6.5\sounds\Alert1.wav");
      if (Close[0] > Close[1])
      Alert(
      "myAlert", NinjaTrader.Cbi.Priority.High, "Reached threshold", "Alert2.wav", 10, Color.Black, Color.Yellow);
      if (Close[0] > Close[1])
      DrawText(
      "MyText"+CurrentBar, "Low "+ Low[0], 0, Low[0] - (TickSize*4), Color.Blue);
      }
      Attached Files

      Comment


        #4
        Open a alerts window, File->New->Alerts

        Comment


          #5
          Strange, wonder it Alert window only works in real time or replay. because I did open a window and while the indicators popped up on the chart as I scrolled thru, the nothing appeared in the Alert Window.

          Comment


            #6
            Yes, correct, Alert() only works in real time or replay...

            Comment


              #7
              thanks for the help

              Comment

              Latest Posts

              Collapse

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