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

Place a dot above/below and Island Reversal?

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

    Place a dot above/below and Island Reversal?

    I am trying to create an indicator which will place a dot above or below and island reversal. I have it working with the code below but I have a problem. The logic correctly places the dot above the high bar if I get a lower close on that bar, but if the logic to detect the bar is not "true" then the statement I have from the example will plot a "0" value for the result. This works fine if I want to mark a reversal up or down with an indicator running in another panel. But I'd like to see the dot above or below the actual price bar. Is there an alternative I can use in the current location occupied by "0" that means don't plot anything at all? I tried using null but that wouldn't compile. Any suggestions are gratefully accepted. Here's the code:

    Code:
            protected override void OnBarUpdate()
            {
                // Use this method for calculating your indicator values. Assign a value to each
                // plot below by replacing 'Close[0]' with your own formula.
    			
    			if (CurrentBar < bO_Period + 1)
    				return;
    			
    				Value.Set(High[0]  > MAX(High, bO_Period)[1] && Close[0] < Close[1] ? High[0] + offset: 0);
    
    				Value.Set(Low[0]  > MIN(Low, bO_Period)[1] && Close[0] > Close[1] ? Low[0] - offset: 0 );
            }

    #2
    daven,

    Just don't call Value.Set() and it won't set any value. Instead of using bitwise comparisons to determine the value to set. Use if-statements to just not set the value at all when there is nothing to set.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Place a dot continued....

      Josh,
      I am a little slower than you assume. I lifted the code to create the dot above the high price from the KeyReversalUp indicator in the library. What I thought I was looking for was some alternative to the "0" in the last position in the value statement, which I think means if the conditions for a key reversal are true, then plot a dot above the high, and if they are not plot a "0". I don't want to plot a "0", I want to plot nothing at all. Is there some kind of value represntation I can put in the place of "0" to avoid plotting a value at all. As I said I tried "null" but that didn't compile. If there is another way to do this could you point me to a code example of what you mean. I have no clue how to do what you propose as an alternative to the way I did it in the example?
      Thanks for your help.
      DaveN

      Comment


        #4
        Code:
        Value.Set(High[0]  > MAX(High, bO_Period)[1] && Close[0] < Close[1] ? High[0] + offset: 0);
        means...

        if High > MAX(...) and Close < previous Close
        then value = High + offset
        otherwise value = 0

        So instead of using this expression just use if-statements directly and leave out the else-if part.

        Code:
        if (High[0] > MAX(High, bO_Period)[1] && Close[0] < Close[1])
             Value.Set(High[0] + offset);
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Almost there

          Josh,
          Thanks for your help. I got it running and it works with one exception, though I have defined the high dots as being an aqua color and the low dots as being a firebrick, they are all aqua. I suspect it is because the plots are only taking on a single value, defined by the logic in front of the value statement. How do I tie the value statement to the original plot statement so the dot is properly colored? For reference I'm including most of the code so you can see what I've done. I tried making the value statement as value0 and value1, but that change wouldn't compile. Here's the code and thanks again for the guidance.
          daven

          Code:
                  protected override void Initialize()
                  	{
                      Add(new Plot(Color.FromKnownColor(KnownColor.Aqua), PlotStyle.Dot, "Island_High"));
                      Add(new Plot(Color.FromKnownColor(KnownColor.Firebrick), PlotStyle.Dot, "Island_Low"));
                      CalculateOnBarClose	= true;
                      Overlay				= false;
                      PriceTypeSupported	= false;
                  	}
          
                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
                  	{	
                      // Use this method for calculating your indicator values. Assign a value to each
                      // plot below by replacing 'Close[0]' with your own formula.
          			
          			if (CurrentBar < bO_Period + 1)
          				return;
          			
          				if (High[0] > MAX(High, bO_Period)[1] && Close[0] < High[1] )
          					
          					Value.Set(High[1] + offset );
          								
          				if (Low[0] < MIN(Low, bO_Period)[1] && Close[0] > High[1] )
          			
          					Value.Set(Low[1] - offset );
                 		}

          Comment


            #6
            daven,

            You need to have two separate plots and then you need to call .Set on their respective plots. Please take a look at the MACD indicator for instance and pay special attention to the Properties region of the code. That is where they create the multiple plots. Then go back to OnBarUpdate() and see how they use .Set.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Does anyone have an indicator for the island reversals? It would be much appreciated.

              Thank you,
              Chuck

              Comment


                #8
                Chuck,

                I suggest you check the file sharing section to see if you are able to find anything you that would fit your needs. Otherwise if you want this professionally made for you you could also try one of the 3rd party NinjaScript Consultants here: http://www.ninjatrader.com/webnew/pa...injaScript.htm
                Josh P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by mgco4you, Today, 09:46 PM
                1 response
                2 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by wzgy0920, Today, 09:53 PM
                0 responses
                3 views
                0 likes
                Last Post wzgy0920  
                Started by Rapine Heihei, Today, 08:19 PM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by Rapine Heihei, Today, 08:25 PM
                0 responses
                6 views
                0 likes
                Last Post Rapine Heihei  
                Started by f.saeidi, Today, 08:01 PM
                1 response
                9 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Working...
                X