Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Doji for a strategy question

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

    #31
    Originally posted by NinjaTrader_ZacharyG View Post
    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])
    Hi Zachary,

    thanks for your reply.

    what i need is that both conditions to be true,and on the third(if true) i want to enter.I need them to appear consequently.So,whould this one give me what i need?

    Code:
    if(! thickMet)
        {         if ( (High[0] > High[1]) && (Low[0] < Low[1]) )
             {
                [B]thickMet = true;[/B]
            }
    
             else    if ( High[0] == High[1] )
             {
                [B]thickMet = true;[/B]
             }
        }
        else
        { if ( (High[0] < High[1]) && (Low[0] > Low[1]) )
             {
                // [B]do stuff[/B]
            }
        }

    Comment


      #32
      hey there,

      still not as familiar with C# as I have to be, but from phyton and Java days, I have to assume you should use a while{} operator. Put the two conditions 1 && 2 you want, and then draw IF (third condition == true) { execute}

      Sorry I'm not providing exact code needed with syntax, but it's super late, and I would have to compile it myself to test for potential errors

      Comment


        #33
        Hello outsource,

        Can you please clarify if this is what you are looking for?

        Code:
        // checks if both condition1 and condition2 are true
        // if both conditions are true, check if condition3 is true
        if (condition1 && condition2)
        {
             // if condition3 is true, enter
             if (condition3)
                  // enter
        }
        Zachary G.NinjaTrader Customer Service

        Comment


          #34
          Originally posted by NinjaTrader_ZacharyG View Post
          Hello outsource,

          Can you please clarify if this is what you are looking for?

          Code:
          // checks if both condition1 and condition2 are true
          // if both conditions are true, check if condition3 is true
          if (condition1 && condition2)
          {
               // if condition3 is true, enter
               if (condition3)
                    // enter
          }
          Hi Zachary,

          Yes,if condition1 true and condition2 true(consequently),then if condition3 true - enter.

          Comment


            #35
            Hello outsource,

            I have provided sample syntax on how to accomplish this in my previous post.

            You will just need to replace condition1, condition2, and condition3 with your conditions.

            Originally posted by NinjaTrader_ZacharyG View Post
            Hello outsource,

            Can you please clarify if this is what you are looking for?

            Code:
            // checks if both condition1 and condition2 are true
            // if both conditions are true, check if condition3 is true
            if (condition1 && condition2)
            {
                 // if condition3 is true, enter
                 if (condition3)
                      // enter
            }
            Zachary G.NinjaTrader Customer Service

            Comment


              #36
              Originally posted by NinjaTrader_ZacharyG View Post
              Hello outsource,

              I have provided sample syntax on how to accomplish this in my previous post.

              You will just need to replace condition1, condition2, and condition3 with your conditions.
              So i don`t need to compare and don`t need to use thickMet function?

              Comment


                #37
                Hello outsource,

                I am not clear of what you are requesting.

                Originally posted by outsource View Post
                Hi Zachary,

                Yes,if condition1 true and condition2 true(consequently),then if condition3 true - enter.
                Code:
                // if condition1 AND condition2 are true, check if condition3 is true
                if (condition1 && condition2)
                {
                     // if condition3 is true, call entry logic
                     if (condition3)
                          // enter
                }
                I do not know what your thickMet boolean is used for and I am not quite clear by what you mean by "so I don't need to compare."

                Please clarify what you are asking for.
                Zachary G.NinjaTrader Customer Service

                Comment


                  #38
                  Originally posted by NinjaTrader_ZacharyG View Post
                  Hello outsource,

                  I am not clear of what you are requesting.



                  Code:
                  // if condition1 AND condition2 are true, check if condition3 is true
                  if (condition1 && condition2)
                  {
                       // if condition3 is true, call entry logic
                       if (condition3)
                            // enter
                  }
                  I do not know what your thickMet boolean is used for and I am not quite clear by what you mean by "so I don't need to compare."

                  Please clarify what you are asking for.
                  It`s explained here:



                  All i want now is to add some extra second condition.Originaly it was two conditions:

                  if first true,and then the second true - enter.

                  Now it`s:

                  if first true and the second true(all intrabar) and next, on third enter,if true.That`s it.

                  Comment


                    #39
                    Jessica provided the example:

                    Code:
                    private bool thickMet = false;
                    protected override void OnBarUpdate()
                    {
                    
                        // ...
                    
                        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
                            }
                        }
                    }
                    Which works as expected.But now i wonder if i can add the second condition before the execution.For example:

                    Code:
                    private bool thickMet = false;
                    protected override void OnBarUpdate()
                    {
                    
                        // ...
                    
                        if(FirstTickOfBar)
                        {
                            thickMet = false;
                        }
                    
                        if(! thickMet)
                        {         if ( (High[0] > High[1]) && (Low[0] < Low[1]) )
                             {
                                thickMet = true;
                            }
                        }
                    [B] if(! thickMet)
                        {         if (second condition)
                             {
                                thickMet = true;
                            }
                        }[/B]
                        else
                        { if ( (High[0] < High[1]) && (Low[0] > Low[1]) )
                             {
                                // do stuff
                            }
                        }
                    }
                    Would this one work properly???

                    Comment


                      #40
                      Hello outsource,

                      On each call of OnBarUpdate(), your edited code is going to:
                      1. Check if OnBarUpdate() was called on the first tick of a bar. If true, change thickMet to false
                      2. Check if thickMet is false. If it's false, check if the current high is more than the previous high AND if the current low is less than the previous low. If this condition is true, set the thickMet to true
                      3. Check again if thickMet is false. If it's false, check if the second condition is true. If the second condition is true, change thickMet to true.
                      4. If thickMet is TRUE when evaluating the second if (!thickMet) condition in bold (which is checking to see if thickMet is FALSE), the second condition will not be evaluated. The else code block will run instead and check if the current high is less than the previous high AND if the current low is more than the previous low. If this is true, run the // do stuff logic.


                      The else block of your code will not evaluate if the second if (!thickMet) condition in bold is true.

                      If this is not what you are wanting in your code, please provide a psuedocode sample of the behavior you are wishing to see.

                      I would highly suggest taking a look at this publicly available link for further information about if, else, and else if statements: http://www.techotopia.com/index.php/...th_if_and_else
                      Zachary G.NinjaTrader Customer Service

                      Comment


                        #41
                        Hi Zachary,

                        would that be more correct?

                        Code:
                        private bool thickMet = false;
                        protected override void OnBarUpdate()
                        {
                        
                            // ...
                        
                            if(FirstTickOfBar)
                            {
                                thickMet = false;
                            }
                        
                            if(! thickMet)
                            {         if ( (High[0] > High[1]) && (Low[0] < Low[1]) )
                                 {
                                    thickMet = true;
                                }
                            }
                            [B]else[/B]
                            {         if (second condition)
                                 {
                                    thickMet = true;
                                }
                            }
                            else
                            { if ( (High[0] < High[1]) && (Low[0] > Low[1]) )
                                 {
                                    // do stuff
                                }
                            }
                        }

                        Comment


                          #42
                          Hello outsource,

                          Have you attempted to compile the syntax you have written?

                          If-else-else is not proper syntax.

                          You will need to do if-ELSE IF-else

                          As an example:
                          Code:
                          if (condition1)
                          {
                               // do something
                          }
                          else if (condition2)
                          {
                               // do something
                          }
                          else
                          {
                               // do something
                          }
                          Code:
                          if (!thickMet)
                          {
                               if((High[0] > High[1]) && (Low[0] < Low[1]))
                                    thickMet = true;
                          }
                          else if (second condition)
                               thickMet = true;
                          else
                          {
                               if ((High[0] < High[1]) && (Low[0] > Low[1]))
                                    // do stuff
                          }
                          I would not be able to tell you if this would be "more correct" or not. You will need to see how this code will be logically evaluated and then determine if this is what you desire.

                          In summary, your logic does the following:
                          1. If being evaluated on the first tick of bar, set thickMet to false
                          2. Check if thickMet is false. If thickMet is false, check if High[0] > High[1] AND Low[0] < Low[1]. If this condition is true, change thickMet to true. The rest of the code (second condition and last condition) will not evaluate regardless of the result of the High[0] > High[1] AND Low[0] < Low[1] check.
                          3. If the condition, if (!thickMet), is false, evaluate the second condition. If the second condition is true, set thickMet to true. The rest of the code (the last condition) will not evaluate if second condition is true.
                          4. If second condition AND if (!thickMet) are both false, the last condition will evaluate. If this is true, run the // do stuff code


                          If this is not what you are wanting in your code, please provide a psuedocode sample of the behavior you are wishing to see.

                          I would highly suggest reading this article from DotNetPerls for further information about if, else if, and else: http://www.dotnetperls.com/if
                          Zachary G.NinjaTrader Customer Service

                          Comment


                            #43
                            Originally posted by NinjaTrader_ZacharyG View Post
                            Hello outsource,

                            Have you attempted to compile the syntax you have written?

                            If-else-else is not proper syntax.

                            You will need to do if-ELSE IF-else

                            As an example:
                            Code:
                            if (condition1)
                            {
                                 // do something
                            }
                            else if (condition2)
                            {
                                 // do something
                            }
                            else
                            {
                                 // do something
                            }
                            Code:
                            if (!thickMet)
                            {
                                 if((High[0] > High[1]) && (Low[0] < Low[1]))
                                      thickMet = true;
                            }
                            else if (second condition)
                                 thickMet = true;
                            else
                            {
                                 if ((High[0] < High[1]) && (Low[0] > Low[1]))
                                      // do stuff
                            }
                            I would not be able to tell you if this would be "more correct" or not. You will need to see how this code will be logically evaluated and then determine if this is what you desire.

                            In summary, your logic does the following:
                            1. If being evaluated on the first tick of bar, set thickMet to false
                            2. Check if thickMet is false. If thickMet is false, check if High[0] > High[1] AND Low[0] < Low[1]. If this condition is true, change thickMet to true. The rest of the code (second condition and last condition) will not evaluate regardless of the result of the High[0] > High[1] AND Low[0] < Low[1] check.
                            3. If the condition, if (!thickMet), is false, evaluate the second condition. If the second condition is true, set thickMet to true. The rest of the code (the last condition) will not evaluate if second condition is true.
                            4. If second condition AND if (!thickMet) are both false, the last condition will evaluate. If this is true, run the // do stuff code


                            If this is not what you are wanting in your code, please provide a psuedocode sample of the behavior you are wishing to see.

                            I would highly suggest reading this article from DotNetPerls for further information about if, else if, and else: http://www.dotnetperls.com/if
                            Yes,it compiles,but it`s hard to tell visually if it`s working..

                            Comment


                              #44
                              In summary, your logic does the following:
                              1. If being evaluated on the first tick of bar, set thickMet to false
                              2. Check if thickMet is false. If thickMet is false, check if High[0] > High[1] AND Low[0] < Low[1]. If this condition is true, change thickMet to true. The rest of the code (second condition and last condition) will not evaluate regardless of the result of the High[0] > High[1] AND Low[0] < Low[1] check.
                              3. If the condition, if (!thickMet), is false, evaluate the second condition. If the second condition is true, set thickMet to true. The rest of the code (the last condition) will not evaluate if second condition is true.
                              4. If second condition AND if (!thickMet) are both false, the last condition will evaluate. If this is true, run the // do stuff code


                              Zachary,all in all,

                              I wan`t the code to evaluate all three conditions to be true.So,if the first condition is true,then evaluate the second one,if the second one is true,evaluate the third one,if the third one is also true - do stuff.

                              Comment


                                #45
                                Hello outsource,

                                Thank you for the clarification.

                                You'll want to look into making a nested if statement.

                                Here is an example:
                                Code:
                                if (condition1)
                                {
                                     if (condition2)
                                     {
                                          if (condition3)
                                          {
                                               // do something
                                          }
                                    }
                                }
                                In the example above, if condition1 is true, evaluate condition2. If condition2 is true, evaluate condition3. If condition3 is true, do something.
                                Last edited by NinjaTrader_Jesse; 09-17-2016, 07:41 PM. Reason: corrected curly brace
                                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