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 QuantKey_Bruce, Today, 02:31 PM
          2 responses
          9 views
          0 likes
          Last Post QuantKey_Bruce  
          Started by Cedalgo, Today, 01:41 AM
          1 response
          20 views
          0 likes
          Last Post NinjaTrader_Emily  
          Started by javiertraderpro, 03-27-2023, 11:23 AM
          4 responses
          41 views
          0 likes
          Last Post UnSuccessfulTrader  
          Started by Waxavi, Yesterday, 03:19 PM
          4 responses
          18 views
          0 likes
          Last Post kpoulis
          by kpoulis
           
          Started by markdshark, Today, 12:37 PM
          4 responses
          14 views
          0 likes
          Last Post NinjaTrader_ChrisL  
          Working...
          X