Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

multi timeframes, instruments

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

    #16
    Hi sosMsos,

    I made a quick video of how you could make the code more straightforward with a boolean,
    World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.


    Please take a look at this and try it out.
    DexterNinjaTrader Customer Service

    Comment


      #17
      NT does not recognize the expression shouldGoLong in:
      if (shouldGoLong == true)
      somehow dosnt work.
      i also dont understand why we need the boolean.

      My latest take on this was ( both condition sets work if the other one is disabled, but no trades when they are both enabled):

      {
      // Condition set 1
      if (EMA(BarsArray[1], 21)[0] > EMA(BarsArray[1], 55)[0]
      && EMA(BarsArray[1], 55)[0] > EMA(BarsArray[1], 200)[0]
      && EMA(BarsArray[1], 55)[0] > EMA(BarsArray[1], 55)[1]
      && EMA(BarsArray[1], 200)[0] > EMA(BarsArray[1], 200)[1])

      // if ((BarsInProgress == 0)
      if ((CountIf(delegate {return (CrossAbove(RSI(9, 0), 30, 1));}, 5) >0)
      && (CountIf(delegate {return (CrossAbove(RSI(4, 0), 70, 1));}, 5) >0))

      {
      EnterLong(0,DefaultQuantity, "");
      }
      Last edited by sosMsos; 04-28-2011, 04:18 PM.

      Comment


        #18
        Hello sosMsos,

        Please try adding the following to the variables section of your indicator:

        private bool shouldGoLong;

        The code you posted will check the daily bars every single bar close of your primary series, which isn't really needed. When you put it in a BarsInProgress == 1 check, it will only run once a day since they are daily bars.

        This is why using a boolean to check if the buy signal is met is more efficient than checking data that hasn't changed every OnBarUpdate().

        Also, you are using CrossAbove() and CrossBelow in CountIfs going back 5 times. You can alternatively use a lookback of 5 in the CrossAbove() and CrossBelow(), for example:

        CrossAbove(RSI(4, 0), 70, 5)

        I'd recommend simplifying your entry logic when working with two data series until it works as expected, then add finer/more entry conditions after its working.
        DexterNinjaTrader Customer Service

        Comment


          #19
          whats the code for, if more than 5 bars after last exit...? Do something...

          "if (BarsSinceExit() > 5" seems not to work

          Comment


            #20
            Hello sosMsos,

            Yes, BarsSinceExit() is correct. Since you are working with multiple timeframes/instruments you may have to use BarsSinceExit() with the BarsArray to check specified:

            if ( BarsSinceExit(BarsArray[1], "", 0) > 5) would check the primary series.

            For more information on using BarsSinceExit() please see the following helpguide article:
            DexterNinjaTrader Customer Service

            Comment


              #21
              Originally posted by NinjaTrader_Dexter View Post
              if ( BarsSinceExit(BarsArray[1], "", 0) > 5) would check the primary series.
              It would have to be BarsArray[0] to be the primary series.

              And the syntax would be

              if ( BarsSinceExit(0, "", 0) > 5)

              to check check the primary series.

              Comment


                #22
                Hello KJB,

                You are correct, I misspoke. BarsArray[1] would check the first additionally added series, and BarsSinceExit() needs an integer, not the actual data series. Thank you for catching this.
                DexterNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                672 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                379 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                111 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                577 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                582 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X