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

Pull Back Logic Possible?

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

    Pull Back Logic Possible?

    Hello,

    I need a specific type of logic to be created to define a "pullback".

    Is the logic provided below possible with implementing in the scripter?

    Create logic which will look for a sequence where a stock is above the mid bb at all times

    And then check if the last 2 bars highs are less than the 3rd bar which is the proposed high.

    As long as the 3rd bar has never been broken higher and the price is still above the midd bb, then the 3rd bar stays set as the current high for the pullback

    The trigger to enter in a position is when the price breaks above the SET HIGH

    This cancels if the price breaches the mid bb.

    And then restarts once it has been cancelled or triggered to enter in a position.
    Is this type of logic possible?


    Is it possible to set one specific candle value while new bars continue to develop?

    #2
    Hello dorony,

    Thank you for your post.

    This logic is possible to develop in NinjaScript.

    I am not sure I understand your last question though. What candle value would you be setting?

    I look forward to your response.

    Comment


      #3
      Thank you...

      And then check if the last 2 bars highs are less than the 3rd bar which is the proposed high.

      As long as the 3rd bar has never been broken higher and the price is still above the midd bb, then the 3rd bar stays set as the current high for the pullback
      So as long as the 3rd bar has never been broken. How do I set the 3rd candle to stay relevant as long as its holding the mid bb.

      Comment


        #4
        Hello dorony,

        Thank you for your response.

        Can you provide a screenshot that might provide further insight into this matter?

        I look forward to your response.

        Comment


          #5
          I attached a chart of IMGN on the 1min with a pull back.

          As you can see the CandleBar[3] is greater than the candles ahead of it.

          So this means the 3rd candle is greater than the 2nd 1st and current candle high.

          It is also above the Middle Bollinger band.

          At this point. I want it to signify a pull back and continue to do so until the price breaks below the mid bb or breaks above the candle high within the sequence I mentioned which is the 3rd candle.

          My question is as the chart continues to develop new candle bars, how do I get it to continue to use the value of the 3rd bar even though that won't be the case when new candles are developed.

          I hope this makes sense.
          Attached Files

          Comment


            #6
            Hello dorony,

            Thank you for your response.

            So another way to put it would be to have the the value of the "size" of the 3rd bar back to update consistently?

            I look forward to your response.

            Comment


              #7
              I want it to lock in its high value of the 3rd candle even when it technically becomes the 4th and 5th candle as time goes on.

              Let me know if you want a more thorough explanation. I will try to explain it clearer.

              Comment


                #8
                I created the logic or the code that I believe should be written to evaluate whether a pull back back has developed (in my own pull back definition)

                I don't know how to create a value that remains constant once its been triggered.

                Maybe this will make it easier to understand my logic and what I am looking for.

                If ((Low[4] > Mid BB[4]) – To make sure price has never broken below the mid bb from the beginning process.

                && If (High[4] < High[3]) -- This is to make sure that the candle is higher than the previous one.

                && (Low[3] > Mid BB[3] – Continues to make sure that the price has not broken below the mid bb.

                && (High[3] > High[2]) – If it continues to pass through the statements as true, then High[3] will become a constant value to be used. (even when it becomes High[4]…[5]…[6] and so on. (Or I am thinking I can keep High[3] as constant by calling back the candle by its Time stamp. ie. High[3] is 12:00pm est)

                && (Low[2] > Mid BB[2]) – Continues to make sure that the price has not broken below the mid bb.

                && (High[3] > High[1])

                && (Low[1] > Mid BB[1]) – Continues to make sure that the price has not broken below the mid bb.

                && (Low[0] > Mid BB[0]) – Continues to make sure that the price has not broken below the mid bb.

                Then High[3] is marked as the high of the “pull back” – This should become a constant variable as long as the mid bb is never breached and then looks for entry within the code below.

                && (High[0] > “Pull Back”)

                So this is my definition of a pull back. The pull back will continue to exist as long as it doesn’t break below the mid bb and will trigger if it breaks the MARKED and FIXED “pull back” candle high level. This is where maybe I need to mark High[3] as a time stamp as stated above.

                Then it would be If (1minute candle at 12pm est HIGH is > Low[2], Low[1]...)

                So an entry can occur as it continues to develop candles as long as it never breaks the mid bb and will continue to wait for the price to break the “pull back” candle high.

                If it breaks below the mid bb, then the “pull back” candle becomes invalid and cancels, and resets to look for another pull back development.
                Attached Files
                Last edited by dorony; 02-13-2018, 06:05 PM.

                Comment


                  #9
                  Hello dorony,

                  Thank you for your response and additional details.

                  You would assign the "size" value and/or bar number of the bar to a variable or set of variables (such as double for a value or int for a bar number) when your condition for that bar is true. That way the variable is only updated on when the condition is true.

                  Please let me know if you have any questions.

                  Comment


                    #10
                    Could you provide an example please...

                    Not sure how to even begin that.

                    Comment


                      #11
                      Hello dorony,

                      Thank you for your response.

                      Please refer to the basic example of this below:
                      Code:
                      		private double holdValue = 0;
                      		private int holdBarNumber = 0;
                      		protected override void OnBarUpdate()
                      		{
                      			if (Close[0] > Open[0]) // pseudo condition, replace with your condition
                      			{
                      				holdValue = Close[0]; //store the close when the condition was true
                      				holdBarNumber = CurrentBar; // store the current bar number when the condition was true
                      			}
                      			
                      			if (holdValue != 0 && holdBarNumber != 0) // check if we have values for the variables
                      			{
                      				Print("Close price at last condition was " + holdValue);
                      				Print("Bar timestamp of last condition was " + Time[CurrentBar - holdBarNumber]); // subtract the bar number from the current bar number to get the proper BarsAgo int
                      			}
                      		}
                      Please let me know if I may be of further assistance.
                      Last edited by NinjaTrader_PatrickH; 02-15-2018, 11:38 AM.

                      Comment


                        #12
                        I kinda get what the code is getting at but after inputting condition and testing it, it doesn't do what I expect it to do as per the image I sent you.

                        remember that as long as the condition is met, and the low prices of each candle are greater than the middle bollinger band then it can continue to find an entry when the current candle high is greater than the holdvalue.

                        Here is what I have so far for the code. Let me know if you see anything wrong with this.

                        protected override void OnBarUpdate()
                        {
                        if (CurrentBars[0] < 5)
                        return;


                        if ((High[3] > High[2])
                        && (Low[2] > midbbBull.Middle[2])
                        && (High[3] > High[1])
                        && (Low[1] > midbbBull.Middle[1]))
                        {
                        holdValue = High[3];
                        holdBarNumber = CurrentBar;
                        }

                        if (holdValue != 0 && holdBarNumber != 0)
                        {
                        Print("Close price at last condition was "+ holdValue);
                        Print ("Bar timestamp of last condition was "+ Time[CurrentBar - holdBarNumber]);
                        }

                        if ((Low[0] > midbbBull.Middle[0])
                        && (High[0] > holdValue))
                        {
                        EnterLong();
                        }


                        Also I dont' need the current bar to be held. I need the High[2] but when I try to input that it gives me an error that it must be a double.
                        Last edited by dorony; 02-15-2018, 10:42 AM.

                        Comment


                          #13
                          Hello dorony,

                          Thank you for your response.

                          For the error message you need to define the variable as a double and not an int.

                          My example was just that, a simplified example. Based on your response I would recommend taking a look at the basic programming concepts at the following link to get yourself familiarized with the concepts used: https://ninjatrader.com/support/help...g_concepts.htm

                          Now, that link is for NinjaTrader 7 but the same concepts apply in NinjaTrader 8. For a bit more detail in NinjaTrader 8 please visit the following link: https://ninjatrader.com/support/help..._practices.htm

                          Please let me know if you have any questions.

                          Comment


                            #14
                            Thanks I read it and understand it.

                            Still very foggy in terms of what needs to be done. But to try and follow through with your help,

                            doesn't that mean I don't need "holdBarNumber = CurrentBar; // store the current bar number when the condition was true"

                            Since holdValue is really only what I need in order to use the high price of a certain candle within the condition?

                            If not then what is the purpose of holdbarvalue?

                            Comment


                              #15
                              Hello dorony,

                              Thank you for your response.

                              That was simply an example of storing the CurrentBar but it is not necessary for your intended behavior.

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

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by thanajo, 05-04-2021, 02:11 AM
                              4 responses
                              470 views
                              0 likes
                              Last Post tradingnasdaqprueba  
                              Started by aa731, Today, 02:54 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post aa731
                              by aa731
                               
                              Started by Christopher_R, Today, 12:29 AM
                              0 responses
                              10 views
                              0 likes
                              Last Post Christopher_R  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              166 responses
                              2,237 views
                              0 likes
                              Last Post sidlercom80  
                              Started by thread, Yesterday, 11:58 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post thread
                              by thread
                               
                              Working...
                              X