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

Color and Loop Question for Indicator

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

    Color and Loop Question for Indicator

    I am making a CCI histogram that does the following:

    While the CCI is ranging between 200 and -200, it prints yellow.

    However...

    If the CCI crosses the 200 level, it prints blue until it crosses back down below the 100 level at which time it will print yellow again.

    If the CCI crosses the -200 level, it prints orange until it crosses back up over the 100 level, at which time it prints yellow again.

    Hopefully this makes sense - can some one give me a hint on how to do this? I tried using a while loop, but always seem to freeze up ninjatrader whenever I try that....

    Thanks for the suggestions.
    Last edited by jmflukeiii; 04-10-2012, 02:40 PM. Reason: PLEASE DELETE, ANSWERED MY OWN QUESTION

    #2
    Hello,

    If I'm following correctly, you should be able to accomplish this with a simple If-Else If ladder and using the CrossAbove/Below method and using a value of bars to look back.

    Below is an example where we are looking for a CrossAbove 200 within the last 10 bars, or a CrossBelow -200 within the last 10 bars

    Code:
                if(CCI(14)[0] < 100 && CCI(14)[0] > -100)
                    BackColor = Color.Yellow;
                
                else if (CrossAbove(CCI(14), 200, 10))
                    BackColor = Color.Blue;
                
                else if (CrossBelow(CCI(14), -200, 10))
                    BackColor = Color.Orange;
                
                else BackColor = Color.Yellow;
    Of course, you will need to adjust the look back from CrossAbove/Below to meet your requirements, but this should help get you started.

    If this doesn't help, can you give me an example of the methods you were attempting and I may be able to help determine why this was locking up.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Well I thought I solved it, but I'm not sure that code would work -

      What I want it to do is once it crosses above the 200 level, for it keep printing blue until it crosses below the 100 level at which point is prints yellow. Now should it cross below the 100 level, and then move back up, it is printing yellow until it once again crosses above the 200 level where it will print blue until it crosses below the 100 level again. So the condition for printing blue over 100 is that it has fallen from the 200 level . It cannot cross up the 100 level and print blue, it must reach 200 first.

      So the condition can't really be based on a lookback period, but rather is conditioned upon achieving the 200 level and however long it takes to fall back below the 100 level.

      Comment


        #4
        Hello,

        So I can have a better idea, can you provide us with the code you attempted to use?
        MatthewNinjaTrader Product Management

        Comment


          #5
          if (CurrentBar < input1) return;
          {
          if (CrossAbove(CCI(input1),200,100))
          {
          if (CCI(input1)[0]>100)
          {
          BarUpBlue.Set(CCI(input1)[0]);
          }
          else
          {
          BarUpYellow.Set(CCI(input1)[0]);
          }
          }
          else if (CrossBelow(CCI(input1),-200,100))
          {
          if (CCI(input1)[0]<-100)
          {
          BarDownOrange.Set(CCI(input1)[0]);
          }
          else
          {
          BarUpYellow.Set(CCI(input1)[0]);
          }
          }
          else
          {
          BarUpYellow.Set(CCI(input1)[0]);
          }

          Comment


            #6
            Basically I need to figure out how to set the intLookback for the CrossAbove/Below = to 0 once the CCI drops below 100. I don't know if there's a way to do that in that command, but maybe there's a way to make a loop to artificially create something like that?

            Comment


              #7
              Hello,

              You should try using conditional bool or int statements to determine if it has recently crossed above or below.

              Here is some pseudo code to help you get started

              Code:
              bool above200 == false;
              
              (CrossAbove(CCI(input1),200,100))
               {  
                  above200 == true;
              
                  if (above200 == true && CCI(input1)[0]>100)
                                          BarUpBlue.Set(CCI(input1)[0]);
              }
              MatthewNinjaTrader Product Management

              Comment


                #8
                Thanks Matthew -

                I appreciate your help but tried something that I think will just give the same results. The problem is the CrossAbove integer lookback period - at 50 or 100 or whatever, it will be true for the next 50 or 100, etc. bars after the cross. So therefore, it will make the next statement true as long as the CCI is above 100. However - the effect I want is that the 'If CrossAbove' statement to become false once the CCI has fallen back below the 100 level, therefore requiring another cross above the 200 before the condition is true again. (This would make the bars print yellow once crossing back up over the 100 until it reaches 200 again).

                I'll keep fiddling with ideas and maybe post it here if I ever figure it out. Is there someway of making that statement false. Here's my code and sample - the white box shows that price crossed above the 200 it turned blue - then it fell below the 100 and turned yellow -all good. But then it crossed back above the 100 and turned blue again - this part should be yellow unless the cci crosses the 200 again.
                Code:
                bool above200=false;
                            bool below200=false;
                            if (CrossAbove(CCI(period),200,50))
                            {
                                above200=true;
                                if (above200==true && CCI(period)[0]>100)
                                {
                                       Up.Set(CCI(period)[0]);
                                }
                                else 
                                {
                                    Yellow.Set(CCI(period)[0]);
                                    above200=false;
                                }
                            }
                            if (CrossBelow(CCI(period),-200,50))
                            {
                                below200=true;
                                if (below200=true && CCI(period)[0]<-100)
                                {
                                    Down.Set(CCI(period)[0]);
                                }
                                else 
                                {
                                       Yellow.Set(CCI(period)[0]);
                                    below200=false;
                                }
                            }
                            else
                            {
                                Yellow.Set(CCI(period)[0]);
                            }
                Attached Files
                Last edited by jmflukeiii; 04-11-2012, 07:06 PM.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by junkone, Today, 11:37 AM
                2 responses
                12 views
                0 likes
                Last Post junkone
                by junkone
                 
                Started by frankthearm, Yesterday, 09:08 AM
                12 responses
                43 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by quantismo, 04-17-2024, 05:13 PM
                5 responses
                35 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by proptrade13, Today, 11:06 AM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by love2code2trade, 04-17-2024, 01:45 PM
                4 responses
                35 views
                0 likes
                Last Post love2code2trade  
                Working...
                X