Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Doji for a strategy question

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

    #16
    I see what you mean.

    I am going to attempt a pseudo-code version of what I posted. I hope this helps but please don't hesitate to let me know if I can take another approach. I believe this pseudo code will be useful if we do need to take another approach as a reference.

    Code:
    [FONT=Courier New]          make a container to store the current bar's minimum[/FONT]
    [FONT=Courier New][FONT=Courier New]          make a container to store the current bar's minimum[/FONT]
    
              Run a sub-program called OnBarUpdate. Everything
              that is created inside this subprogram is destroyed.
              This is why we made places to store stuff earlier.
              Sub-program contents :
                  If this is the first tick of the bar, reset
                  our stored current minimum and maximum
    
                  If the current ask price is lower than the lowest
                  price in this bar so far, the current ask price
                  is now the current bar's minimum price
    
                  If the current bid price is higher than the
                  highest price in this bar so far, the current
                  bid price is now the current bar's maximum
                  price
    
                  Now you can write your own code here, and now
                  you know what the bid, ask, max, and min prices
                  are
    [/FONT]
    Jessica P.NinjaTrader Customer Service

    Comment


      #17
      Originally posted by NinjaTrader_JessicaP View Post
      I see what you mean.

      I am going to attempt a pseudo-code version of what I posted. I hope this helps but please don't hesitate to let me know if I can take another approach. I believe this pseudo code will be useful if we do need to take another approach as a reference.

      Code:
      [FONT=Courier New]          make a container to store the current bar's minimum[/FONT]
      [FONT=Courier New][FONT=Courier New]          make a container to store the current bar's minimum[/FONT]
      
                Run a sub-program called OnBarUpdate. Everything
                that is created inside this subprogram is destroyed.
                This is why we made places to store stuff earlier.
                Sub-program contents :
                    If this is the first tick of the bar, reset
                    our stored current minimum and maximum
      
                    If the current ask price is lower than the lowest
                    price in this bar so far, the current ask price
                    is now the current bar's minimum price
      
                    If the current bid price is higher than the
                    highest price in this bar so far, the current
                    bid price is now the current bar's maximum
                    price
      
                    Now you can write your own code here, and now
                    you know what the bid, ask, max, and min prices
                    are
      [/FONT]
      Thank you,Jessica,

      but whta is my entry logic after all that for this one?:

      if (High[0] < High[1] && Low[0] > Low[1])
      && (High[0] > High[1] && Low[0] < Low[1])

      Comment


        #18
        Hello Outsource,

        So your entry logic in pseudo code is likely not what you would like it to be. That looks like this :

        Code:
        [FONT=Courier New]if ...
        [/FONT][FONT=Courier New]...the most recent high is less than the second most recent high...[/FONT]
        [FONT=Courier New]...the most recent low is greater than the second most recent low...
        [/FONT][FONT=Courier New]...the most recent high is greater than the second most recent high...
        [/FONT][FONT=Courier New]...the most recent low is less than the second most recent low...
        [/FONT]
        Because it is impossible for the high one bar ago to be both greater than and lower than the high two bars ago, and the same is true for the low, this code block can be replaced by, simply (in real code and not pseudo code)

        Code:
        [FONT=Courier New]if (false)[/FONT]
        A lot of programmers, in fact, use <> to mean "not equal to" for this reason.

        You probably meant to split this into two code blocks, e.g.

        Code:
        [FONT=Courier New]if ( (High[0] < High[1]) && (Low[0] > Low[1]) )
        {
            // do stuff here
        }[/FONT]
        [FONT=Courier New]if ( (High[0] > High[1]) && (Low[0] < Low[1]) )
        {
            // do other stuff here
        }[/FONT]
        Otherwise, if you simply wanted to do things when the High and Low prices are not equal, that would look like this :

        Code:
        [FONT=Courier New]if ( (High[0] != High[1]) && (Low[0] != Low[1]) )
        {
            // do stuff here
        }[/FONT]
        If neither of these is the case, if you could let me know what your intentions are, I can look deeper into this.
        Jessica P.NinjaTrader Customer Service

        Comment


          #19
          Originally posted by NinjaTrader_JessicaP View Post
          Hello Outsource,

          So your entry logic in pseudo code is likely not what you would like it to be. That looks like this :

          Code:
          [FONT=Courier New]if ...
          [/FONT][FONT=Courier New]...the most recent high is less than the second most recent high...[/FONT]
          [FONT=Courier New]...the most recent low is greater than the second most recent low...
          [/FONT][FONT=Courier New]...the most recent high is greater than the second most recent high...
          [/FONT][FONT=Courier New]...the most recent low is less than the second most recent low...
          [/FONT]
          Because it is impossible for the high one bar ago to be both greater than and lower than the high two bars ago, and the same is true for the low, this code block can be replaced by, simply (in real code and not pseudo code)

          Code:
          [FONT=Courier New]if (false)[/FONT]
          A lot of programmers, in fact, use <> to mean "not equal to" for this reason.

          You probably meant to split this into two code blocks, e.g.

          Code:
          [FONT=Courier New]if ( (High[0] < High[1]) && (Low[0] > Low[1]) )
          {
              // do stuff here
          }[/FONT]
          [FONT=Courier New]if ( (High[0] > High[1]) && (Low[0] < Low[1]) )
          {
              // do other stuff here
          }[/FONT]
          Otherwise, if you simply wanted to do things when the High and Low prices are not equal, that would look like this :

          Code:
          [FONT=Courier New]if ( (High[0] != High[1]) && (Low[0] != Low[1]) )
          {
              // do stuff here
          }[/FONT]
          If neither of these is the case, if you could let me know what your intentions are, I can look deeper into this.
          Jessica,i don`t know how programmatically,but can you imagine that the bar can do many things as it developes intrabar,can you imagine all the people?.....The code that i posted just illustrates how an inside bar becomes an outside bar - intrabar.the code that does it for me exposes the patterns via int series.So they are ID`ed as,lets say:

          the inside bar == 1

          the oustside bar == 2

          so itry to get the logic like

          if this.pattern[0] == 1
          && this.pattern[0] == 2

          {entry}

          but it doesn`t work so far,but you are amazing in your assistance!

          Comment


            #20
            Hello Outsource,

            I appreciate your patience, but in your simple example, you have "this.pattern" taking on multiple values in a single tick, which it can not do.

            Are you asking how to tell if something has taken on the first pattern, and then if it has, if it has taken on the second pattern, within the same bar?

            If this is the case, you will need to refer to the 3rd example in the first post I sent to you. If I can clarify that post, or provide any other assistance, please let me know.
            Jessica P.NinjaTrader Customer Service

            Comment


              #21
              Originally posted by NinjaTrader_JessicaP View Post

              Are you asking how to tell if something has taken on the first pattern, and then if it has, if it has taken on the second pattern, within the same bar?

              If this is the case, you will need to refer to the 3rd example in the first post I sent to you. If I can clarify that post, or provide any other assistance, please let me know.
              Yes,because this one always shows up first(when and if it does):

              if (High[0] < High[1]) && (Low[0] > Low[1])

              after a while this one shows up during the same bar:

              if (High[0] > High[1]) && (Low[0] < Low[1])

              Our quest so far is how to tell the strategy to b able to recognize both and open a position.The strategy calls an indicator where those two gus are ID`ed.

              Comment


                #22
                Hello outsource,

                I would like at this time to return to a piece of code I posted earlier, and reproduce it in pseudo-code, so that it is easier to understand what this does.

                Code:
                [FONT=Courier New]private bool tradedYet = false;
                protected override void OnBarUpdate()
                {
                
                    // ...
                
                    if(FirstTickOfBar)
                    {
                        tradedyet = false;
                    }
                
                    if(! tradedYet)
                    {        [/FONT][FONT=Courier New] if([/FONT][FONT=Courier New]Position.MarketPosition != MarketPosition.Long && Low[0] < Open[0] && Close[0] > Open[0] )
                [/FONT][FONT=Courier New]         {
                            [/FONT][FONT=Courier New]EnterLong();[/FONT][FONT=Courier New]
                            tradedYet = true;[/FONT][FONT=Courier New]
                        [/FONT][FONT=Courier New]}
                        [/FONT][FONT=Courier New]else if([/FONT][FONT=Courier New]Position.MarketPosition != MarketPosition.Short && High[0] > Open[0] && Close[0] < Open[0] )
                        [/FONT][FONT=Courier New]{
                            [/FONT][FONT=Courier New]EnterShort();[/FONT][FONT=Courier New][FONT=Courier New]
                            tradedYet = true;[/FONT]        [/FONT][FONT=Courier New]}
                    }
                
                    // ...
                
                } [/FONT]
                Here is the same thing in pseudo-code

                Code:
                [FONT=Courier New]keep track of our state between ticks
                run a sub program called OnBarUpdate
                    if this is the first tick in the bar
                        reset our state to "not yet traded"
                    if we are in a "not yet traded state"
                        enter long or short side of the market depending
                        set our state to "we have performed a trade"
                [/FONT]
                So this accomplishes something very close to what you were asking just now. Let's take what you just asked, and re-write it in pseudo code.

                I will refer to this,

                Code:
                [FONT=Courier New]( (High[0] < High[1]) && (Low[0] > Low[1]) )[/FONT]
                as your "thin" condition, since you start off with a wide range and end up with a short range, and

                Code:
                [FONT=Courier New]( (High[0] > High[1]) && (Low[0] < Low[1]) )[/FONT]
                as your "thick" condition, since you start off with a thin range and end up with a wide range. Our pseudo code for what you just asked for now looks like,

                Code:
                [FONT=Courier New]keep track of our state between ticks
                run a sub program called OnBarUpdate
                    if this is the first tick in the bar
                        reset our state to "[B]thick condition not yet met[/B]"
                    if we are in a "[B]thick condition not yet met[/B]" state
                        set our state to "[B]thick condition has been met[/B]"
                    [B]otherwise
                        if our "thin condition" has been met
                            do something
                [/B][/FONT]
                That looks like, in regular code,

                Code:
                [FONT=Courier New]private bool [B]thickMet[/B] = false;
                protected override void OnBarUpdate()
                {
                
                    // ...
                
                    if(FirstTickOfBar)
                    {
                        [B]thickMet[/B] = false;
                    }
                
                    if(! [B]thickMet[/B])
                    {        [/FONT][FONT=Courier New] if [/FONT][B][FONT=Courier New]( (High[0] > High[1]) && (Low[0] < Low[1]) )[/FONT][/B][FONT=Courier New]
                [/FONT][FONT=Courier New]         {[/FONT][FONT=Courier New]
                            [B]thickMet[/B] = true;[/FONT][FONT=Courier New]
                        [/FONT][FONT=Courier New]}[/FONT][FONT=Courier New]
                    }
                    else
                    {[/FONT][FONT=Courier New][FONT=Courier New] if [/FONT][B][FONT=Courier New]( (High[0] < High[1]) && (Low[0] > Low[1]) )[/FONT][/B][FONT=Courier New]
                [/FONT][FONT=Courier New]         {[/FONT][FONT=Courier New]
                            [B]// do stuff[/B][/FONT][FONT=Courier New]
                        [/FONT][FONT=Courier New]}
                [/FONT]    }
                } [/FONT]
                This is the sequence of events this specifies :

                1. On our first tick, we start testing to see if the thick condition was met
                2. Around the 3rd tick of the bar, the thick condition is met.
                  1. We now start looking for the thin condition

                3. Around the 6th tick of the bar, the thin condition is met
                  1. The code where I have "// do stuff" is executed


                If I did not understand the goal correctly, please copy the last pseudo-code sample in this post and modify it in your reply. That will make it very easy to get you the right assistance.
                Jessica P.NinjaTrader Customer Service

                Comment


                  #23
                  Hi,Jessica,i think you understood correctly,but it still doesn`t work.Here is my version:

                  if(! thickMet)
                  { if (High[0] > High[1]) && (Low[0] < Low[1])
                  { thickMet = true;}
                  }
                  else
                  {
                  if (High[0] < High[1]) && (Low[0] > Low[1])
                  {xR.Set(0, true);}
                  }

                  then,im trying to call the sequence via strategy

                  if(this.pa.XR[0] == true)

                  {enter}

                  no luck

                  Comment


                    #24
                    Hello outsource,

                    I had to take some guesses at the code outside the sample you provided, but I am providing a sample which incorporates what you gave me, which does work. Please review and modify this code sample to suit your needs, and please let me know if you have any questions.
                    Attached Files
                    Jessica P.NinjaTrader Customer Service

                    Comment


                      #25
                      Originally posted by NinjaTrader_JessicaP View Post
                      Hello outsource,

                      I had to take some guesses at the code outside the sample you provided, but I am providing a sample which incorporates what you gave me, which does work. Please review and modify this code sample to suit your needs, and please let me know if you have any questions.
                      Thank you,Jessica,i`ll try it asap and get back to you!

                      Comment


                        #26
                        Jessica,i cant only see now how i call the value via strategy?Or is it the strategy that you provided?For me it would be easier if it was an indicator.Can i just move all the parts to the new indicator?If so,what is the value to call?

                        Thank you

                        Comment


                          #27
                          Hello outsource,

                          Bear in mind that you can not place trades from indicators. If you need some help getting started with strategies, you can refer to this section of the help guide



                          That said, I have just tested, and the code sample I provided will in fact compile into an Indicator. I am providing a code sample in which I have pasted it into an indicator.

                          Please let us know if there are any other ways we can help.
                          Attached Files
                          Jessica P.NinjaTrader Customer Service

                          Comment


                            #28
                            Originally posted by NinjaTrader_JessicaP View Post
                            Hello outsource,

                            Bear in mind that you can not place trades from indicators. If you need some help getting started with strategies, you can refer to this section of the help guide



                            That said, I have just tested, and the code sample I provided will in fact compile into an Indicator. I am providing a code sample in which I have pasted it into an indicator.

                            Please let us know if there are any other ways we can help.

                            Thanks,Jessica!Seems to be working perfectly great!Thank you for your assistance and have a great Weekend!

                            Comment


                              #29
                              Hello,Support,

                              Let`s get to the topic please,shall we?

                              The question about the following sequence which i need to try a little tweak on:

                              Code:
                                  if(FirstTickOfBar)
                                  {
                                      thickMet = false;
                                  }
                              
                                  if(! thickMet)
                                  {         if ( (High[0] > High[1]) && (Low[0] < Low[1]) )
                                       {
                                          thickMet = true;
                                      }
                                  }
                                  else
                                  { if ( (High[0] < High[1]) && (Low[0] > Low[1]) )
                                       {
                                          // do stuff
                                      }
                                  }
                              }
                              
                              Now,following the example above,is the tripple alternation possible?For example:

                              Code:
                               if(FirstTickOfBar)
                                  {
                                      thickMet = false;
                                  }
                              
                                  if(! thickMet)
                                  {         if ( (High[0] > High[1]) && (Low[0] < Low[1]) )
                                       {
                                          thickMet = true;
                                      }
                              
                                       else    if ( High[0] = High[1] )
                                       {
                                          thickMet = true;
                                       }
                                  }
                                  else
                                  { if ( (High[0] < High[1]) && (Low[0] > Low[1]) )
                                       {
                                          // do stuff
                                      }
                                  }
                              }
                              Will it be working properly that way?

                              Thank you

                              Comment


                                #30
                                Hello outsource,

                                In your modified logic, your script is first going to check if High[0] > High[1] AND if Low[0] < Low[1]. If both of these conditions are true, thickMet is set to true.

                                Now if both of these conditions are NOT true, or if just one is NOT true, your script is going to evaluate your else if statement. If High[0] equals High[1], then thickMet is set to true.

                                Please note that in a conditional statement, you need to check for equality with two equal signs (==).

                                Code:
                                else if (High[0] == High[1])
                                Zachary G.NinjaTrader Customer Service

                                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
                                574 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