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

Bool Flag Question

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

    Bool Flag Question

    Hello

    I've developped an indicator that draws a green UpArrow under a candle when certain criteria for a long entry are met. In order to avoid having two (or more) arrows in a row for the same entry when all criteria are met in a multi-candle sequence, I'm using a Bool Flag that specifies that the prior candle must be a bearish (red) one. This works fine.
    What I'm trying to do is to allow a Signal to appear also if the prior candle was a bullish (green) one, but only if the high of the candle that gives the signal (High[0]) is lower than the high of the prior candle (High[1]). I think that my code is correct (see below) but for some reason it doesn't work the way I want it to. Any pointer as to why would be much appreciated.

    Thanks

    if (my conditions here && myBoolFlag)
    {DrawArrowUp etc
    myBoolFlag= false;
    }

    if (Open[1]>Close[1] || Open[1]<Close[1] && High[0]<High[1])
    {
    myBoolFlag= true;
    }

    #2
    Hello,

    Without seeing the rest of the code I would be unable to comment, Try adding in Print() Statements and start outputting variables until you find whaat is not updating as you expect.

    Also, you might try this as I'm unsure if the order operation here is correct:

    This:

    if(Open[1]>Close[1] || Open[1]<Close[1] && High[0]<High[1])

    To This:


    if((Open[1]>Close[1] || Open[1]<Close[1]) && High[0]<High[1])

    Comment


      #3
      Thanks for your reply Brett. The rest of the code is all about the different entry criteria, but the error can't be in there because when I remove the Bool Flag from the code, it works perfectly (it just draws way too many arrows). When I add the Bool Flag again, it obviously removes many arrows (which is good), but I noticed that it sometimes removes a few arrows that shouldn't be removed according to the code snippet that I posted, making me enter a position one candle too late. I replaced my snippet with the one you suggested, but unfortunately it seems to make no difference.

      Thanks
      Last edited by laocoon; 12-06-2010, 08:46 AM.

      Comment


        #4
        Hello,

        In this case, please start adding in Print() statements and printing out variables and tracing your logic to see what is causing this to occur as you do not expect.

        I look forward to assisting you further.

        Comment


          #5
          Hello Brett

          Thanks for your reply. In order to test the basic mechanism of what I want to achieve, I removed all the criteria of my strategy and pretty much just left the bool flag. This is all that's left of my code (longs only):

          if (firstBar && Open[0]<Close[0])
          {
          DrawArrowUp("Long" + CurrentBar, false, 0, Low[0]- 2*(TickSize), Color.Lime);
          firstBar = false;
          }

          if ((Open[1]>=Close[1]) || (High[0]<=High[1]))
          {
          firstBar = true;
          }

          Basically, I want the strategy to draw a green arrow below a candle when certain criteria are met (I removed those criteria to simplify the test). Then, I only want the strategy to draw a green arrow again IF the previous candle was red (Open<Close) or Black (Open=Close). By doing that, I want to avoid a series of successive green candles that would be drawn as long as all criteria are met (I only want the first green candle that gives the entry signal.)

          The only exception to this rule is when the previous candle was green (Close>Open) BUT when its High was <= than the High of the candle before that. In this case I want a green arrow to appear again.

          This is what my code should be achieving, but it doesn't work. It draws successive green arrows in a row when it clearly shouldn't.

          It sounds ridiculously simple but for some reason I don't manage to get it to work.

          Thanks for giving me a hint as to what to do.
          Last edited by laocoon; 12-14-2010, 05:37 AM.

          Comment


            #6
            Hello,

            Are you sure on this logiv side here:

            || (High[0]<=High[1]))


            Your using an OR operator so only one side needs to be true to set the flag back to true.

            Either the first condition is evaluating to true or the second one is this is the only two cases where the bool flag can be set back to true.

            Im not sure where if ther previous High is greater then the current high gets you as this will on a CalculateOnBarClose= False indicator will plot the line as soon as the bar ticks and the current open price is less then the previous high price as on the first tick of a bar the high, close, open, and low is the same price.

            In trading this side of the equation would evauluate to true in a lot of cases to draw the arrow.

            Comment


              #7
              Hello Brett

              Thanks for your reply.
              The expression (High[0]<=High[1]) look correct to me.

              "You're using an OR operator so only one side needs to be true to set the flag back to true."

              =>Absolutely. That's the idea.

              "Either the first condition is evaluating to true or the second one is this is the only two cases where the bool flag can be set back to true."

              =>Correct.

              I'm working with CalculateOnBarClose= True, so the situation you're referring to shouldn't apply in this case.

              Thanks

              Comment


                #8
                Hello,

                Without running your code on my side at this point I would just being making blind stabs. Please post your cfull ode or send it to support at ninjatrader dot com and reference this forum post put ATTN: Brett in the subject line so that I can take a quick run and look into it and add some Prints().

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by rocketman7, Today, 02:12 AM
                1 response
                15 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by briansaul, Today, 05:31 AM
                1 response
                12 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by PaulMohn, Today, 03:49 AM
                1 response
                12 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by frslvr, 04-11-2024, 07:26 AM
                6 responses
                106 views
                1 like
                Last Post NinjaTrader_BrandonH  
                Started by trilliantrader, 04-18-2024, 08:16 AM
                6 responses
                26 views
                0 likes
                Last Post trilliantrader  
                Working...
                X