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

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 love2code2trade, Yesterday, 01:45 PM
          4 responses
          28 views
          0 likes
          Last Post love2code2trade  
          Started by funk10101, Today, 09:43 PM
          0 responses
          7 views
          0 likes
          Last Post funk10101  
          Started by pkefal, 04-11-2024, 07:39 AM
          11 responses
          37 views
          0 likes
          Last Post jeronymite  
          Started by bill2023, Yesterday, 08:51 AM
          8 responses
          44 views
          0 likes
          Last Post bill2023  
          Started by yertle, Today, 08:38 AM
          6 responses
          26 views
          0 likes
          Last Post ryjoga
          by ryjoga
           
          Working...
          X