Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NinjaScript coders... is this scenario even possible?

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

    NinjaScript coders... is this scenario even possible?

    Hi all...

    I'm in the process of creating a strategy which takes a position when the RSI line crosses a certain "trigger" line. For example, "20." But... I keep running into a snag... and I can't find a way to fix it (or if a way to fix it even exists).

    In live trading, what happens many times is that the RSI line will cross the threshold (20 in our example here) and then retrace again, and finally move ahead to its intended target destination.

    When I use a "crosses above" or "crosses below" condition, what ends up happening is the strategy sees each and every cross as a valid trigger. In other words, lets say the RSI crosses above 20 and enters a long position... but then, it retraces again back below 20, and then... again "crosses above" 20 (and triggers another "true" response to the "if" condition, which closes the original position, and executes another long position).

    Is there a way to make the strategy execute only once until it hits its target, even if price drops again below 20? Is there a way to tell the strategy to ignore future entry triggers as long as the exit trigger has not been reached? I can't seem to find a command in the ninjascript for handling this type of scenario.


    I would like to tell the strategy: "once you open the trade based on the first trigger condition, keep the trade open until the exit condition is reached, even if price drops back below the initial trigger point and crosses it again." I would like to tell it, after it has opened its position, to ignore any other "entry triggers" which may occur until it reaches its target. This way, it avoids opening and closing multiple trades and triggering multiple unwanted commissions.

    Is there a command in NinjaScript which tells the strategy to "ignore" future "first trigger" conditions until the "exit" trigger condition is reached?

    Thanks.

    #2
    To avoid multiple entries set "EntriesPerDirection = 1" in the Initialize() section of your strategy.

    You should also set your strategy to CalculateOnBarClose = true. That way NinjaTrader will wait for the bar close, before the entry is triggered.

    Comment


      #3
      Thank you Harry, that is very valuable input. I've definitely included the "on bar close" as true in my code.

      So, just to clarify, if I use the "EntriesPerDirection =1;" property, the position will stay open until it reaches its exit condition?

      I was thinking I would need to code an "if, while" condition loop to accomplish this.

      for example:
      Code:
      if (CrossAbove (RSI (20, 3), LongEntryTrigger, 1))
      {[INDENT]EnterLong(DefaultQuantity, "LongRSIEntry")[INDENT]if ((RSI (20, 3).Avg[0] != LongExitTrigger)
      return false;[/INDENT][/INDENT]
      return true;
      }
      
      ExitLong ("etc.. etc...")
      Will the property you mentioned yield basically the same result?

      Thanks again, to you, and any other posters for lending a hand with this. I appreciate it.

      V

      Comment


        #4
        Aurum,

        Correct, the EntriesPerDirection sets the strategies number of entries that can be in the same direction.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by Aurum View Post
          Thank you Harry, that is very valuable input. I've definitely included the "on bar close" as true in my code.

          So, just to clarify, if I use the "EntriesPerDirection =1;" property, the position will stay open until it reaches its exit condition?

          I was thinking I would need to code an "if, while" condition loop to accomplish this.

          for example:
          Code:
          if (CrossAbove (RSI (20, 3), LongEntryTrigger, 1))
          {[INDENT]EnterLong(DefaultQuantity, "LongRSIEntry")[INDENT]if ((RSI (20, 3).Avg[0] != LongExitTrigger)
          return false;[/INDENT][/INDENT]return true;
          }
          
          ExitLong ("etc.. etc...")
          Will the property you mentioned yield basically the same result?

          Thanks again, to you, and any other posters for lending a hand with this. I appreciate it.

          V
          That rather depends on how you have coded your exit conditions. If you want to control when things happen, and when they should be ignored, the best option is to use boolean flags to restrict actions.

          Comment


            #6
            Hello everyone, and thank you for all the excellent answers. I've moved quite far along now in the strategy I am developing, thanks to your comments and directions.

            I have other questions... but I'll ask them in a different thread since they are off topic.

            Thanks again all...

            V

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            648 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            108 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            572 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            574 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X