Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

A boolean!

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

    A boolean!

    Hello!
    I have an issue with the Boolean.
    I have the following code:
    HTML Code:
    if((High[0] >= EMA(7)[0]) || (High[1] >= EMA(7)[0])) (Line1)
    { if(Close[0] < EMA(7)[0]) (Line2)
    DrawArrow()}}
    If we have one condition of the Line1 filled, one arrow will be drawn. If both conditions of Line1 are filled, two arrows will be drawn.
    Here I want to have ONLY THE FIRST arrow drawn when both conditions of the Line1 are filled and not two arrows.
    Later on, still in the downtrend, we have similar situation and two arrows are drawn. Here again, I want ONLY the first arrow.
    I have tried to control these conditions with a boolean, but I am failing to fix it. I have the following code:

    HTML Code:
    private bool flagUp = false;
    if((High[0] >= EMA(7)[0]) || (High[1] >= EMA(7)[0]) && !flagUp) (Line1)
    { if(Close[0] < EMA(7)[0]) (Line2)
    DrawArrow();
    flagUp = true;}
    else flagUp =false;}
    I would really appreciate any help.

    Thanks in advance!

    Last edited by Stanfillirenfro; 04-18-2022, 05:20 AM.

    #2
    First, reset the bool.:

    if(IsFirstTickOfBar)
    flagUp = false;

    Then do the test like this if all conditions need to be met:

    if(flagUp == false && High[0] >= EMA(7)[0] && High[1] >= EMA(7)[0] && Close[0] < EMA(7)[0])
    {
    DrawArrow();
    flagUp = true;
    }
    eDanny
    NinjaTrader Ecosystem Vendor - Integrity Traders

    Comment


      #3
      Many thanks eDanny for your reply.

      The idea of reseting the bool is nice.
      But the test as you have suggested is not really what I wanted because in the case with "&&", all conditions have to be met. I just want one condition to be met, but since I do not know if it is at first occurence or later, that makes me difficult to solve the problem.

      Any idea?

      Thanks for your help!

      Comment


        #4
        I see the issue. You need to only reset the flag each bar, not after each test. You reset your bool to false the next tick after it is set to true and you drew the arrow. Then it will draw again, set to true again, next tick set to false, etc.

        Try this:

        if(IsFirstTickOfBar)
        flagUp = false;

        if(!flagUp && (High[0] >= EMA(7)[0] || High[1] >= EMA(7)[0]))
        {
        if(Close[0] < EMA(7)[0])
        {
        DrawArrow();
        flagUp = true;
        }
        }
        eDanny
        NinjaTrader Ecosystem Vendor - Integrity Traders

        Comment


          #5
          Sorry Danny for the delay in my response.

          Thanks a lot. It is working.
          Many thanks!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          579 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          334 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 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
          551 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X