Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Signal Trouble

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

    Signal Trouble

    Hi. Can you tell me how to get this to only play the sound when the conditions are met for both the ES 1 min. and ES 3 min. simultaneously. Right now it plays when either the ES 1 min meets the conditions or the 3 min does individualy or both. I hope that makes sense and you can help me.
    Thank You!

    // Add an ES 12-08 3 minute Bars object to the strategy
    Add("ES 12-08", PeriodType.Minute, 1);


    // Add an ES 12-08 3 minute Bars object to the strategy
    Add("ES 12-08", PeriodType.Minute, 3);


    CalculateOnBarClose =
    false;
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    // Condition set 1
    if (EMA(14)[0] > SMA(20)[0]
    && MACD(
    12, 26, 9)[0] > MACD(12, 26, 9).Avg[0])
    {
    PlaySound(
    @"C:\Program Files\NinjaTrader 6.5\sounds\beep.wav");
    }

    #2
    Hello,

    Try something like this:

    // Add an ES 12-08 3 minute Bars object to the strategy
    Add("ES 12-08", PeriodType.Minute, 1
    );


    // Add an ES 12-08 3 minute Bars object to the strategy
    Add("ES 12-08", PeriodType.Minute, 3
    );


    CalculateOnBarClose =
    false
    ;
    }
    ///
    <summary>
    ///
    Called on each bar update event (incoming tick)
    ///
    </summary>
    protectedoverridevoid
    OnBarUpdate()
    {


    if(BarsInProgress == 0)
    return;
    if(BarsInProgress == 1)
    return;
    // Condition set 1
    if (EMA(BarsArray[1], 14)[0] > SMA(BarsArray[1], 20)[0
    ]
    && MACD(BarsArray[1],
    12, 26, 9)[0] > MACD(BarsArray[1], 12, 26, 9).Avg[0]


    && EMA(BarsArray[2], 14)[0] > SMA(BarsArray[2], 20)[0]
    && MACD(BarsArray[2],
    12, 26, 9)[0] > MACD(BarsArray[2], 12, 26, 9).Avg[0])
    )

    {
    PlaySound(
    @"C:\Program Files\NinjaTrader 6.5\sounds\beep.wav");
    }


    This link will help with BarsArray[]:
    http://www.ninjatrader-support.com/HelpGuideV6/BarSeries.html


    DenNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Ben View Post
      Hello,

      Try something like this:

      // Add an ES 12-08 3 minute Bars object to the strategy
      Add("ES 12-08", PeriodType.Minute, 1
      );


      // Add an ES 12-08 3 minute Bars object to the strategy
      Add("ES 12-08", PeriodType.Minute, 3
      );


      CalculateOnBarClose =
      false
      ;
      }
      ///
      <summary>
      ///
      Called on each bar update event (incoming tick)
      ///
      </summary>
      protectedoverridevoid
      OnBarUpdate()
      {


      if(BarsInProgress == 0)
      return;
      if(BarsInProgress == 1)
      return;
      // Condition set 1
      if (EMA(BarsArray[1], 14)[0] > SMA(BarsArray[1], 20)[0
      ]
      && MACD(BarsArray[1],
      12, 26, 9)[0] > MACD(BarsArray[1], 12, 26, 9).Avg[0]


      && EMA(BarsArray[2], 14)[0] > SMA(BarsArray[2], 20)[0]
      && MACD(BarsArray[2],
      12, 26, 9)[0] > MACD(BarsArray[2], 12, 26, 9).Avg[0])
      )

      {
      PlaySound(
      @"C:\Program Files\NinjaTrader 6.5\sounds\beep.wav");
      }


      This link will help with BarsArray[]:
      http://www.ninjatrader-support.com/HelpGuideV6/BarSeries.html


      Looks like I am about to learn something new. Thanks for your help. I think this will work great!

      Comment


        #4
        Adding Conditions and Open and Close

        The Condition 1 of the formula you gave me worked great but when I tried to add a Condition 2, as indicated below, only Condition 1 worked. Is there something I need to add when adding a Condition 2 or is it better just to make a whole new complete strategy? Also I wanted to add
        && Open[
        0] < Close[0] for each insturment on both conditions but it said that it was wrong. Is there a special way to write the code for those with BarsArray?

        Thanks for your help.

        // Add an ES 12-08 3 minute Bars object to the strategy
        Add("ES 12-08", PeriodType.Minute, 1);
        // Add an ES 12-08 3 minute Bars object to the strategyAdd("ES 12-08", PeriodType.Minute, 3);


        CalculateOnBarClose =
        false;
        }
        ///<summary>/// Called on each bar update event (incoming tick)///</summary>protectedoverridevoid OnBarUpdate()
        {


        if(BarsInProgress == 0)
        return;
        if(BarsInProgress == 1)
        return;
        // Condition set 1if (EMA(BarsArray[1], 14)[0] > SMA(BarsArray[1], 20)[0]
        && MACD(BarsArray[1],
        12, 26, 9)[0] > MACD(BarsArray[1], 12, 26, 9).Avg[0]

        && EMA(BarsArray[2], 14)[0] > SMA(BarsArray[2], 20)[0]
        && MACD(BarsArray[2],
        12, 26, 9)[0] > MACD(BarsArray[2], 12, 26, 9).Avg[0]))

        {
        PlaySound(
        @"C:\Program Files\NinjaTrader 6.5\sounds\beep.wav");
        }

        // Condition set 2
        if (EMA(BarsArray[1], 14)[0] < SMA(BarsArray[1], 20)[0]
        && MACD(BarsArray[1],
        12, 26, 9)[0] < MACD(BarsArray[1], 12, 26, 9).Avg[0]

        && EMA(BarsArray[2], 14)[0] < SMA(BarsArray[2], 20)[0]
        && MACD(BarsArray[2],
        12, 26, 9)[0] < MACD(BarsArray[2], 12, 26, 9).Avg[0]))

        {
        PlaySound(
        @"C:\Program Files\NinjaTrader 6.5\sounds\beep.wav");
        }

        Comment


          #5
          Hello,


          Your code should work fine. Are you sure the condition was met? If so, try using Print() before the PlaySound in the new condition. This link will help:


          To get Open[0] < Close[0] try using something like this:

          Open[1][0] < Close[1][0]

          and

          Open[2][0] < Close[2][0]

          This link will help:
          http://www.ninjatrader-support.com/H...ameInstruments

          DenNinjaTrader Customer Service

          Comment


            #6
            You have been a huge help, THANK YOU!

            Robert

            Comment


              #7
              I am going to try this. I read the info on the link and I think that
              Open[1] [0] or Close[1][0]
              on multi instruments has to be writen in the plural form
              Opens and Closes but not for the Open[0] or Close[0]. It wouldn't let me compile without an error until I wrote it plural. I am going to test everything tomorrow to see if it works.
              Thanks again.


              Originally posted by NinjaTrader_Ben View Post
              Hello,


              Your code should work fine. Are you sure the condition was met? If so, try using Print() before the PlaySound in the new condition. This link will help:


              To get Open[0] < Close[0] try using something like this:

              Open[1][0] < Close[1][0]

              and

              Open[2][0] < Close[2][0]

              This link will help:
              http://www.ninjatrader-support.com/H...ameInstruments

              Comment


                #8
                cre8it8,

                That is correct. Typo on our end. You want to use Closes and Opens with the "s".
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by yertle, Today, 08:38 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post yertle
                  by yertle
                   
                  Started by Mestor, 03-10-2023, 01:50 AM
                  15 responses
                  378 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by samish18, Yesterday, 08:57 AM
                  10 responses
                  27 views
                  0 likes
                  Last Post samish18  
                  Started by matty89, 03-02-2020, 08:31 AM
                  34 responses
                  3,039 views
                  1 like
                  Last Post NinjaTrader_BrandonH  
                  Started by kujista, Today, 05:44 AM
                  3 responses
                  14 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Working...
                  X