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 carnitron, 09-20-2022, 10:35 AM
          13 responses
          219 views
          0 likes
          Last Post jeronymite  
          Started by Douglee, Yesterday, 08:00 PM
          0 responses
          49 views
          0 likes
          Last Post Douglee
          by Douglee
           
          Started by DT215, Yesterday, 07:49 PM
          0 responses
          48 views
          0 likes
          Last Post DT215
          by DT215
           
          Started by Jaggy, Yesterday, 07:24 PM
          0 responses
          41 views
          0 likes
          Last Post Jaggy
          by Jaggy
           
          Started by psytopy, Yesterday, 06:20 PM
          0 responses
          49 views
          0 likes
          Last Post psytopy
          by psytopy
           
          Working...
          X