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

Multiple bar conditions:

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

    #16
    Hi Chelsea. This one is a bit of a trip down memory lane. I am trying to convert this into ninja 8 and am having some problems. The truth is I never could get this version 7 one to work and hope to finally get there after 7 years.

    I have attached a chart and some code. So if we take this signal where the green and red arrows appear as an example on the chart. The code for condition 1 in line 7 states that if the price travels below the previous bar low by 20 ticks then a green arrow should print as the condition is hit. Only after that condition is met and price moves up and crosses over the Open of the last bar the red bar should print as the second condition is met.

    Now the problem here is both arrows are being printed once the first first condition is met. I think this is because once the first condition is met i.e. it crosses 20 ticks below the last bar open then second condition is immediately met because price has already been greater than yesterdays open. So I am stumped as far as the second condition. I need the red arrow of the second condition to trigger and print only when condition 1 has been satisfied and only after which price has traveled upwards and crosses yesterdays open. Now if the current bar closes down and does not reach the open of the last bar then the green arrow should stay there on its own as only the first condition was satisfied.

    I am not sure if I am missing something here but any further ideas would be appreciated.

    Thanks
    DJ




    Attached Files
    Last edited by djkiwi; 11-19-2020, 01:39 PM.

    Comment


      #17
      Hello DJ,

      You want one condition to be true first and another condition to be true second?

      Are you using a bool (boolean) that is set to true when the first condition is true, to let the second condition know the first condition was previously true?

      If so, are you printing the value of this bool to the output window along with the time of the bar to see if it is being set to expected value when you are expecting it?
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        Hi Chelsea.

        Yes the first needs to be true then the second. I think I am missing something fundamental. I put in the print statements as you suggested and nothing shows up. When I put them outside of these areas I was getting all arrows.

        I think the issue here is logic. For example condition 1 states price should go below the open of the previous bar by 5 ticks (Line 88). Then after this price should go up and pass through the previous bar. Then condition 3 should be price moving above the previous bar close.

        The problem is the conditions seem to be met immediately rather than as they go. The chart shows some green and cyan arrows but no lime arrow. Condition 1 (Lime arrow) should be printed first but is sometimes ignored as conditions 2 and 3 are met. I am not sure why condition 1 is ignored or green and cyan print as all the flags seem ok. The other arrows on the the far right shows all 3 met but doesn't fill them one after the other. The lime and green arrows are printed at the same time because I think condition 2 has already been satisfied as Close [0] was always above Close [1] the moment condition one was met. What I am trying to do is satisfy condition 1 after which when Close[0] passes above the close of the previous bar condition 2 (green arrow) should be printed.

        Any other ideas for me to test ? Stumped!

        Thanks

        Attached Files

        Comment


          #19
          Hello djkiwi,

          This is Jim responding on behalf of Chelsea who is out of the office at this time.

          If you remove your other conditions for the other arrows and only focus on the lime arrows, are they displaying as you expect? If this is the case, you may be overwriting the drawing object later in your logic if the same drawing tag is used. It is also possible that the logic later in the code modifies the logic that is used draw the lime arrows.

          If the lime arrow is not displaying when you reduce your logic to just that condition set, then the condition controlling it must not be coming true. We would suggest to use prints to see why the strategy logic has not become true when you expected it to be. The Playback Connection can be helpful when debugging so you can fast-forward to a certain point in the data series and look at your prints for a specific part.

          Playback - https://ninjatrader.com/support/help...connection.htm

          We look forward to assisting.
          JimNinjaTrader Customer Service

          Comment


            #20
            Hi Jim.

            That was a good idea. Some strange things going on here. So I am just doing the first condition. I have attached the code. I already have private bool long condition = false in line 34. So when I add in

            long condition ==false in line 99 and
            long condition = true in line 112

            I don't get any arrows. When I remove these I get arrows as normal 20 ticks below the previous low. When I put print statements in I get arrows under every bar so not sure what that signifies. Would you mind having a quick look to see if I am doing it correctly.


            Thanks
            DJ


            Attached Files

            Comment


              #21
              Hello DJ,

              Print the longCondition along with the time of the bar.

              Currently, longCondition starts false, can get set to true once, and then is never set back to false ever again.
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by gravdigaz6, Today, 11:40 PM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by MarianApalaghiei, Today, 10:49 PM
              3 responses
              10 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by XXtrader, Today, 11:30 PM
              0 responses
              4 views
              0 likes
              Last Post XXtrader  
              Started by love2code2trade, Yesterday, 01:45 PM
              4 responses
              28 views
              0 likes
              Last Post love2code2trade  
              Started by funk10101, Today, 09:43 PM
              0 responses
              9 views
              0 likes
              Last Post funk10101  
              Working...
              X