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

Entering trade when conditions don't happen simultaneasly

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

    Entering trade when conditions don't happen simultaneasly

    Hi,
    To improve a strategy, I would like the condition to enter a trade to be triggered only after a second crossing happens. Meaning, for instance we have a sthocastics crossing, but the strategy would only trigger when a crossing between 2 emas happen. Would the looking back N bars work? Can it be done within the builder instead of using code?

    #2
    Hello Sifred,

    You have a couple choices.

    You can use a bool (or set of bools). When the conditions are true but the bool is false, set the bool to true. You know the condition was true once. When the conditions are true again and the trigger bool is also true, then you know its the second time, and you can trigger the action, and reset the bool back to false.

    Or you can use an integer as a counter. Each time the condition is true increment the integer. When the integer is 2, trigger the action and set the integer back to 0.

    Or you can use a Series<bool>. On every bar set the bool series to the result of the condition to save the true or false of that condition on each bar. Then you can use bars ago values or loops if you would like.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi, thanks for your reply.
      When I click on the link, I get a "page not found message".. it happens with a lot of links in responses on this forum. I use this forum a lot for answers, but most times the links posted direct me to empty pages, "page not found" messages.
      So, it's not possible to do with conditions on the strategy builder? Since I'm not familiar with programming, bools and integers, can you show me the right direction?

      Comment


        #4
        Hello Sifred,

        I have tested the link and it is working as expected.

        You are clicking the link and you are not copying and pasting the shorted text correct?

        Trying right-clicking the link and select 'Open link in new tab'.

        Bools can be used in the Strategy Builder.


        Below is a link to a forum post with helpful information about getting started with NinjaScript. Be sure to watch the Strategy Builder 301 training video.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Click image for larger version  Name:	Captura de Ecrã (23).png Views:	0 Size:	1.33 MB ID:	1131085
          Same result. It happened in many links I found on the forum, when browsing before. The 2 links you gave me last work perfectly, but the previsous still didn't. But I saw the video before

          Ok, fair enough, I knew about the bools from the video 301, but still don't know how it can make the action be triggered after the second condition.
          For example, a set of conditions than can happen simultaneously do happen (macd > 0, stochastics crossover, EMA >0, etc..), but the action of buying long should only be triggered when a second crossing happens, which can be a number of bars later. How is the bool affecting this?
          Sorry for my newbiness and thanks
          Last edited by Sifred; 12-07-2020, 09:31 AM.

          Comment


            #6
            Hello Sifred,

            I see that this in another language. It may be that the help guide links are not working in the language you have this set to, which from my understanding were not publicly available or completed.

            The /pt/ designation is Portuguese is this correct?

            May I inquire how you obtained the link to the Portuguese help guide?

            Is this loading automatically when you open the link without opening in English?


            First, add two bool variables, one for the trigger being set, one for the action having been triggered and waiting to reset. The bools will be false by default. I'll refer to these as the TriggerSet and ActionTriggered bools, however you can name your bools whatever you would like.
            Let me know if you get stuck adding a bool variable.

            In the conditions add a condition set to reset everything after the action has triggered.
            Include a condition on the left User input -> TriggerSet, Equals in the center, Misc -> True on the right.
            Include a condition on the left User input -> ActionTriggered, Equals in the center, Misc -> True on the right.

            In the Actions set the bools to false:
            Include an action Misc -> set TriggerSet -> unchecked (false)
            Include an action Misc -> set ActionTriggered -> unchecked (false)

            In the conditions add a condition set with the conditions you want (that you want to trigger twice).
            Add to this condition set another condition that compares User input -> TriggerSet on the left, equals in the center, and Misc -> True on the right.
            Add to this condition set another condition that compares User input -> ActionTriggered on the left, equals in the center, and Misc -> False on the right.
            For the action, trigger the action you want (such as placing an order).
            This set is for when the trigger is set from the first condition and the action is not yet triggered but the condition is true a second time. This condition set comes before the next set because they are evaluated in order, and you don't want the same bar to trigger both conditions at the same time.

            Add another condition set with the conditions you want (that you want to trigger twice).
            Add to this condition set another condition that compares User input -> TriggerSet on the left, equals in the center, and Misc -> False on the right.
            For the action, Misc -> set TriggerSet -> checked (true)
            This set is for setting a trigger when the first condition is true after a reset before the next condition triggers the action.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_ChelseaB View Post
              The /pt/ designation is Portuguese is this correct?

              May I inquire how you obtained the link to the Portuguese help guide?

              Is this loading automatically when you open the link without opening in English?
              Correct. It loads automatically as soon as I either click on the link or right click to open on a new tab. Like I said before, I'm rarely, if ever, successfull when clicking on these links to help guides or other posts.


              Regarding the strategy, I tried a different way, can you confirm it works differently than yours? Couldn't get my head around yours yet!

              Bool set to false by default

              Set 1:
              If: Conditions I want as first trigger;
              Action: set bool to true.

              Set 2:
              If all:
              Bool=true
              second condition I want to see triggering the buy action
              Action:
              EnterLong;
              Bool=False; to reset the bool

              Set 3:
              Exit the trade on conditions.

              Comment


                #8
                Hello Sifred,

                Attached is an example of using bools to trigger an action after a first condition is true and setting a bool, then having a second condition be true on a later bar and then triggering the action.
                Attached Files
                Last edited by NinjaTrader_ChelseaB; 12-13-2020, 05:34 PM.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  I really appreciate your effort but I'm even more lost now. In your example, What is exactly the second condition? I understood that if one of your triggers is false, you set it to true. the first set is there to reset everything.
                  The conditions I used on my previous post worked somehow. I'm just not sure it does exactly what I want it to.
                  Also, what if you want the second condition to happen within a certain number of bars? Like, it must happen within 5 bars or not at all?

                  Comment


                    #10
                    Hello Sifred,

                    The first condition to trigger (set 3), is the first time the condition is true, the second condition to trigger (set 2), is when the action actually takes place. This means the condition has to be true twice for the action to trigger. The last condition set to trigger (set 1) resets everything after the action has occurred so the triggers can go off in sequence again.

                    Below is a link to an example that saves the CurrentBar number of the first action to a Series (so an offset can be used), continuously saves the value of CurrentBar to another series. and then uses the offset to subtract one series from another to get a number of bars used as a bar counter.
                    with regard to the attached image: Line A is an indicator Line B is the m period MAX of line A Line C is an average of this indicator A Line D is another average of this indicator A is it possible, possibly using the strategy builder, but without adding a temporary variable, to set on the condition: line C crosses below line D
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by PhillT, Today, 02:16 PM
                    2 responses
                    6 views
                    0 likes
                    Last Post PhillT
                    by PhillT
                     
                    Started by Kaledus, Today, 01:29 PM
                    3 responses
                    10 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by frankthearm, Yesterday, 09:08 AM
                    14 responses
                    47 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by gentlebenthebear, Today, 01:30 AM
                    2 responses
                    14 views
                    0 likes
                    Last Post gentlebenthebear  
                    Started by PaulMohn, Today, 12:36 PM
                    2 responses
                    17 views
                    0 likes
                    Last Post PaulMohn  
                    Working...
                    X