Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trying to create a special type of "since" condition. Any thoughts?

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

    Trying to create a special type of "since" condition. Any thoughts?

    Hi all...

    I've decided to try and add greater functionality to my little strategy as I've recently noticed an opportunity I'd like to capitalize on.

    Here's what I'd like NinjaScript to capture (instead of "n" bars back, I'd like to capture a specific series events in a specific order):

    1. Within the last "n" bars, the indicator crossed below 5.
    2. Then, the indicator crossed back above 5.
    3. The indicator then climbed to 30.
    4. The indicator then crossed back below 20 (but never went past 15).
    5. Now, the indicator is on the way back up again. (essentially a "failure swing," where the indicator has made a higher low).

    Thanks to all the great assistance I've been receiving here on the forum, I've learned how to tell the strategy to look back a certain number of bars.

    I also now know (thanks to your wonderful "nudges") how to tell the strategy to check "within" a certain number of bars for an event.

    What I'm wondering, is how to tell the strategy about a "sequence" of events which happened in a particular order. (without necessarily having to specify the number of bars within which the event happened).

    So, (within the wizard of course), I'm trying to tell the strategy that "recently" a series of events occurred this specific order... the first was a cross below 5, the second was a cross above 5, the third was a cross above 30, the fourth was a cross below 20, etc..

    I've been trying a string of "crossabove" and "crossbelow" commands, but this has been cumbersome and inefficient, and I suspect there is a more elegant, and efficient way to accomplish exactly my goal.

    It would be wonderful to have someone again point me in the right direction for the correct NinjaScript method to use to accomplish this.

    Any thoughts?

    -V

    #2
    Hello Aurum,

    Thanks for your post.

    One way, within the wizard, to accomplish your goal of sequential events is through the use of Boolean flag that you set based on when each condition occurs and then an evaluation of all the conditions to then perform whatever action is needed. There are no user flags within the wizard however you can use the User Variables in that manner.

    So for example in the condition and actions builder, you could have several sets as follows:

    Condition: if the indicator crosses below 5, Action: Set Variable0 = 1

    Condition: if Variable0 ==1 and indicator crosses above 5, Action: Set Variable 1 = 1

    Condition: if Variable1 == 1 and indicator crosses above 30, Action: Set Variable2 = 1

    Condition: if Variable2 == 1 and indicator crosses below 20, action: Set Variable3 = 1

    etc, etc.

    At some point you would have a final condition to then perform your action (buy/Sell?) and as part of the action you would also have the actions to reset all your variables to 0 to begin again.

    Note that you will also need to consider when the sequence is no longer valid and you will need to reset the appropriate variables.

    Please let me know if I can be of further assistance.

    Comment


      #3
      Hello Paul!

      Thank you, thank you!

      This is great information. I've given it a try and it is perfect for what I need.

      NinjaTraderSupport >= cool.

      -V

      Comment


        #4
        Hi Paul!

        I'm working with your suggestions about setting variables in order to store and use sequential events, and I have a question.

        In the example you give, these are all events which are happening one after the other, which definitely applies to my situation. the only difference is, in my scenario, they are all happening "while" another indicator is hovering above a certain number. One of the conditions must remain true while all the other conditions are happening sequentially.

        How would I accomplish the listing you've described, only "while" another condition is true during all of the above?

        For example

        "while indicatorB is above 90..." and then all the other conditions you've outlined.

        I've tried assigning the "above 90" condition to the first variable, but this doesn't work.

        For example, if I state:

        Condition: if indicatorA is above 90, Action: Set Variable0 = 1

        Condition: if Variable0 ==1 and indicatorB crosses below 80, Action: Set Variable 1 = 1

        Condition: if Variable1 == 1 and indicatorB crosses below 50, Action: Set Variable2 = 1

        Condition: if Variable2 == 1 and indicator crosses below above 50, action: Set Variable3 = 1

        For some reason, this is not working for me. Any suggestions as to what I may be doing wrong here?

        Thank you in advance for your assistance.

        -V

        Comment


          #5
          Hi Aurum,

          Thanks for your post and question.

          There are a couple of ways to do this with what you have. The easiest would be to add the condition to your first set so that it does not start the sequence unless condition: if the indicator crosses below 5 && indicatorB is above 90..., Action: Set Variable0 = 1

          Alternatively you could add the condition: && indicatorB is above 90... to all sets so that if you are in the middle of the sequence it will stop if condition && indicatorB is above 90..., is not true.

          Please note that in the conditions builder, within a set, any conditions that you list will be treat as "And" (which is "&&" in C# code). So you can have many conditions that all must be true in order to execute the action(s) in the same set.

          Please let me know if I can be of further assistance.

          Comment


            #6
            Hi Paul !!

            Great! Thanks for the assistance.

            I think the second scenario you outlined would be best for my application.

            So, would the setup look something like this:

            If:

            IndicatorA CrossAbove 5 && IndicatorB > n
            Variable0 == 1

            if:

            IndicatorA CrossAbove 10 && IndicatorB > n && Variable0 = 1
            Variable1 == 1

            if:

            IndicatorA CrossBelow 5 && IndicatorB > n && Variable1 = 1
            Variable2 == 1

            Etc... etc.

            Does that look correct to you?

            -V

            Comment


              #7
              Hello Aurum,

              Thanks for the post.

              Yes, that is correct, what you have written shows the overriding condition being required for each of your sequential steps.

              Please let me know if I can be of further assistance.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              649 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              370 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              109 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              573 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              576 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X