Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How do I branch out of a block of instructions?

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

    How do I branch out of a block of instructions?

    Hi,

    I'm referring specifically to the code in red. I would like to instruct the code to do something else when the Buy Setup Count is equal to 9 and at the same time continue to do what it is still doing. Not having much joy with that. Can somebody please help?

    Thanks.

    Kay Wai
    Code:
    [FONT=Courier New][COLOR=#000000]if (CurrentBar < SetupBars*2) return;[/COLOR][/FONT]
    [FONT=Courier New][COLOR=#000000]            [/COLOR][/FONT]
    [COLOR=#000000][FONT=Courier New]// Initiating Buy Setup[/FONT][/COLOR]
    [COLOR=#000000][FONT=Courier New]if (Close[1]>Close[5] && Close[0]<Close[4])[/FONT][/COLOR]
    [COLOR=#000000][FONT=Courier New]    {[/FONT][/COLOR]
    [COLOR=#000000][FONT=Courier New]       priceflipdown = true;[/FONT][/COLOR]
    [COLOR=#000000][FONT=Courier New]    }[/FONT][/COLOR]
    [COLOR=#000000][FONT=Courier New]// Initiating Sell Setup[/FONT][/COLOR]
    [COLOR=#000000][FONT=Courier New]if (Close[1]<Close[5] && Close[0]<Close[4])[/FONT][/COLOR]
    [COLOR=#000000][FONT=Courier New]    {[/FONT][/COLOR]
    [COLOR=#000000][FONT=Courier New]      priceflipup = true;[/FONT][/COLOR]
    [COLOR=#000000][FONT=Courier New]    }[/FONT][/COLOR]
    [COLOR=#000000][FONT=Courier New]// Starting Buy Setup Count[/FONT][/COLOR]
    [COLOR=#000000][FONT=Courier New]if ((priceflipdown == true) && (Close[0]<Close[4]))[/FONT][/COLOR]
    [COLOR=#000000][FONT=Courier New]     {[/FONT][/COLOR]
    [COLOR=#000000][FONT=Courier New]        BuySetupCount++;[/FONT][/COLOR]
    [COLOR=#000000][FONT=Courier New]        this.TDBuySetupDrawText(BuySetupCount.ToString());[/FONT][/COLOR]
    [COLOR=#000000][FONT=Courier New]     }[/FONT][/COLOR]
    [COLOR=#000000][FONT=Courier New]// Buy Setup Cancellation[/FONT][/COLOR]
    [COLOR=#000000][FONT=Courier New]else if ((priceflipup == true) && (BuySetupCount < 9))[/FONT][/COLOR]
    [COLOR=#000000][FONT=Courier New]     {[/FONT][/COLOR]
    [COLOR=#000000][FONT=Courier New]        this.RemoveBuySetup();[/FONT][/COLOR]
    [COLOR=#000000][FONT=Courier New]     }[/FONT][/COLOR]
    [FONT=Courier New][COLOR=red][B]// Buy Setup Completion[/B][/COLOR][/FONT]
    [FONT=Courier New][COLOR=red][B]else if ((priceflipup == true) && (BuySetupCount >= 9))[/B][/COLOR][/FONT]
    [FONT=Courier New][B][COLOR=red]     {[/COLOR][/B][/FONT]
    [B][COLOR=red][FONT=Courier New]        [/FONT][FONT=Courier New]BuySetupCount = 0;[/FONT][/COLOR][/B]
    [FONT=Courier New][B][COLOR=red]        priceflipdown = false;[/COLOR][/B][/FONT]
    [FONT=Courier New][B][COLOR=red]     }[/COLOR][/B][/FONT]

    #2
    Hi Kai, I'm not sure I follow you completely but to monitor for a condition inside a condition, you would add for example set of if { } 's inside it, as they would only be monitoring while the if 'above' it would be evaluating to 'true' thus triggering the logic contained.

    Comment


      #3
      Hi Bertrand,

      This indicator, in a way, is a counter. If the condition is true, it adds a count and the counts are consecutive. That is the first "IF".

      The second "IF" deal with the conditions when it is false and the count is less than 9. All the counts are removed if the final count before the condition is false is less than 9. The removal is sent to a block of code.

      The third "IF" deals with conditions when the counts are greater than or equal to 9. As long as the condition is true, it will continue to add a count ad infinitum. What I would also like to add to this third "IF" is when the count is equal to 9, I would like the code to initiate a new count with different conditions WHILE continuing with its existing count.

      Hope you can help. Thanks. Bertrand.

      Kay Wai

      Comment


        #4
        You would need to add another 'else if' part then to check with your flip is true and the count == 9, then set for example a bool true which starts another counter in your code.

        Comment


          #5
          Hi Bertrand,

          Do you mean like this?

          Regards

          Kay Wai


          Code:
          [B][FONT=Courier New][COLOR=#ff0000]// Calling Countdown[/COLOR][/FONT][/B]
          [FONT=Courier New][COLOR=red][B]else if ((priceflipup == true) && (BuySetupCount == 9))[/B][/COLOR][/FONT]
          [FONT=Courier New][B][COLOR=red]     {[/COLOR][/B][/FONT]
          [B][COLOR=red][FONT=Courier New]      if Close[0] <= Low[2][/FONT][/COLOR][/B]
          [B][FONT=Courier New][COLOR=#ff0000]        {[/COLOR][/FONT][/B]
          [B][FONT=Courier New][COLOR=#ff0000]            this.CountdownCount();[/COLOR][/FONT][/B]
          [B][FONT=Courier New][COLOR=#ff0000]        }[/COLOR][/FONT][/B]
          [FONT=Courier New][B][COLOR=red]     }[/COLOR][/B][/FONT]

          Comment


            #6
            Yes correct, as this will only start your new countdown if both rules are 'hitting'.

            Comment


              #7
              didn't get the desired result.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              580 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              335 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              102 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              554 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              552 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X