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

Modify RSI plots

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

    Modify RSI plots

    Please, can anyone modify the attached RSI so that the zones indicated on the image can be filled in red or green and can also be used for setting conditions with the Strategy Builder of NT8.
    Thank you

    Attached Files

    #2
    Hello guidoisot,

    Thank you for your post.

    You could achieve this by utilizing Draw.Region() to draw in the panel.

    I noticed a number of the Lines added did not show up until I gave them separate names, so something like this (note the code in bold):


    Code:
            [B]private Series<double>        upperGreen1;
            private Series<double>        lowerGreen1;[/B]
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                    = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionRSI;
                    Name                        = "aaRSIZones";
                    IsSuspendedWhileInactive    = true;
                    BarsRequiredToPlot            = 20;
                    Period                        = 14;
                    Smooth                        = 3;
    [B]DrawOnPricePanel             = false;  //this makes sure our drawing object isn't drawn on the same panel as the data series[/B]
    
                    AddPlot(Brushes.DodgerBlue,        NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameRSI);
                    AddPlot(Brushes.Goldenrod,        NinjaTrader.Custom.Resource.NinjaScriptIndicatorAvg);
    
    [B]                AddLine(Brushes.Red,    20,    "LowerRed20");
                    AddLine(Brushes.Red,    30,    "LowerRed30");
                    AddLine(Brushes.Green,    40,    "UpperGreen40");
                    AddLine(Brushes.Green,    50,    "UpperGreen50");
                    AddLine(Brushes.Red,    55,"LowerRed55");
                    AddLine(Brushes.Red,    65,    "LowerRed65");
                    AddLine(Brushes.Green,    80,    "UpperGreen80");
                    AddLine(Brushes.Green,    90, "UpperGreen90");[/B]
                }
                else if (State == State.Configure)
                {
                     // removed for simplicity
                }
                else if (State == State.DataLoaded)
                {
                    //other variables removed
    
    [B]                upperGreen1        = new Series<double>(this, MaximumBarsLookBack.Infinite); 
                    lowerGreen1        = new Series<double>(this, MaximumBarsLookBack.Infinite);[/B]
                }
            }
    
            protected override void OnBarUpdate()
            {
                //removed for simplicity
    
    [B]            upperGreen1[0] = 50;
                lowerGreen1[0] = 40;
    
                Draw.Region(this, "tag1", CurrentBar, 0, lowerGreen1, upperGreen1, null, Brushes.Green, 100);[/B]
    
               //rest of logic removed for space reasons
            }
    Basically what this does is to fill in the green region between 40 and 50. We take our line values and create a new Series<double> for each to hold the values so the y-coordinates are set for each bar. Then in OnBarUpdate, we make sure we have the Series<double> values assigned for the current bar and draw our region. Make sure you've set DrawOnPricePanel as false or it won't show up correctly. This should give you a jumping off point to color the remaining areas.

    Here's a link to our help guide regarding Draw.Region:



    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Kate View Post

      the Lines added did not show up until I gave them separate names,

      ...

      Make sure you've set DrawOnPricePanel as false or it won't show up correctly.
      .
      Hello Kate
      thank you for your reply.
      Yes I did not know/thought that the plots needed their names.

      I tentatively ... set the false value for the DrawOnPricePanel in the State.SetDefaults and it appeared as doing ok.

      My end goal here is being able to set conditions on the SB when there are rsi reversals in either one of the two zones around the 50 level.


      Thank you so much for your help.

      gt

      Click image for larger version  Name:	NQ 09-19 (1 Minute) _ NQ 09-19 (120 Minute) 2019_06_21 (09_19_40).png Views:	1 Size:	181.8 KB ID:	1061481
      Last edited by guidoisot; 06-21-2019, 01:27 AM.

      Comment


        #4
        Hello Guidoisot,

        Thank you for your reply.

        You have two options here:

        You could either hard code the values into the strategy since they're always the same, or you could expose the Series<double> values so they would be usable in the Strategy Builder. The latter is preferable since then if you want to use it in multiple strategies you don't have to hard code the values again each time.

        For example, I could add this to the #region Properties section of the indicator to expose the upperGreen1 line value:

        Code:
                [Browsable(false)]
                [XmlIgnore]
                public Series<double> UpperGreen1 // note this is uppercase "U" when our series in the indicator itself starts with a lowercase "u"
                {
                    get { return upperGreen1; }    // Allows our public upperGreen1 Series<double> to access and expose our internal upperGreen1 Series<double>
                }
        There's an example in our help guide here that goes over exposing values that are not plots of an indicator so they are usable in the Strategy Builder:

        https://ninjatrader.com/support/help...alues_that.htm

        Please let us know if we may be of further assistance to you.
        Last edited by NinjaTrader_Kate; 06-21-2019, 02:35 PM. Reason: missed some commenting in code
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by rtwave, 04-12-2024, 09:30 AM
        4 responses
        31 views
        0 likes
        Last Post rtwave
        by rtwave
         
        Started by yertle, Yesterday, 08:38 AM
        7 responses
        29 views
        0 likes
        Last Post yertle
        by yertle
         
        Started by bmartz, 03-12-2024, 06:12 AM
        2 responses
        22 views
        0 likes
        Last Post bmartz
        by bmartz
         
        Started by funk10101, Today, 12:02 AM
        0 responses
        6 views
        0 likes
        Last Post funk10101  
        Started by gravdigaz6, Yesterday, 11:40 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X