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

If something wrong with Draw.Region?

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

    If something wrong with Draw.Region?

    I am trying to get the region to only fill when the CCI value exceeds my defined value, yet it colors the area below as well regardless how I try to stop it from doing so. I've included a snippet for what I believe should trigger it to shade red if its over my overbought level, and lime if its under my oversold level. Can you please help me sort out why this would not work as intended?

    Code:
    if (CCIPlot[0] > obLevelE)
    {
        Draw.Region(this, "CCIup", CurrentBar, 0, CCIPlot, obLevelE, Brushes.Red, opacity4, Displacement);
    }
    if (CCIPlot[0] < osLevelE)
    {
        Draw.Region(this, "CCIdn", CurrentBar, 0, CCIPlot, osLevelE, Brushes.Lime, opacity4, Displacement);
    }    ​
    Last edited by Conceptzx; 01-24-2024, 05:34 AM.

    #2
    current output...
    Attached Files

    Comment


      #3
      Hello Conceptzx,

      Thank you for your post.

      In both Draw.Region() methods, you have the startBarsAgo set to "CurrentBar" barsAgo and the endBarsAgo set to 0 barsAgo. This means the region will be drawn for every bar on the chart up to that bar where the condition was triggered. Each time the condition is triggered again, the existing Region object is updated to draw across all bars on the chart again. You mentioned you want it to, "only fill when the CCI value exceeds my defined value" - do you mean you only want it to fill for the bars on which the CCI is above/below the value? Please clarify what you are looking to achieve so I may better understand and assist you.

      I look forward to your reply.
      Emily C.NinjaTrader Customer Service

      Comment


        #4
        In the attached image where CCI exceeds my defined value, I only want it to fill red between the plot and the line while above the line, not from below the line to the plot.
        Attached Files
        Last edited by Conceptzx; 01-24-2024, 09:06 AM.

        Comment


          #5
          Originally posted by Conceptzx View Post
          In the attached image where CCI exceeds my defined value, I only want it to fill red between the plot and the line while above the line, not from below the line to the plot.
          In that case, you would need to save the bar number on which the CCI crosses above the value and then draw the region up until it crosses below the value. You will then need a new tag for each new region that is drawn, as it will be more than just one region above and one region below. You need to create a new region object for each time the CCI crosses above/below the value.

          A similar scenario has been discussed in the following thread:
          Hello, I'm trying to draw a region whose color will depend on whether an indicator line is higher or lower than another indicator line. It just keeps giving me the same color, though. Could you please tell me what is incorrect with this syntax? I've simplified the issue with the following sample. I would be most grateful


          As mentioned in that thread, there is an example indicator that uses different colored regions for different conditions. This indicator is publicly available on our NinjaTrader Ecosystem website:
          Here is a basic guideline of how to import NinjaScript add-ons in NinjaTrader 8:

          Note — To import NinjaScripts you will need the original .zip file.

          To Import:
          1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
          2. From the Control Center window select the menu Tools > Import > NinjaScript Add-on...
          3. Select the downloaded .zip file
          4. NinjaTrader will then confirm if the import has been successful.

          Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'

          Once installed, you may add the indicator to a chart by:
          • Right-click your chart > Indicators... > Select the Indicator from the 'Available' list on the left > Add > OK

          Here is a short video demonstration of the import process:
          Please let me know if I can be of further assistance.

          The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
          Emily C.NinjaTrader Customer Service

          Comment


            #6
            The CCI logic is built into this indicator, its not calling on the original CCI to calculate the plot.

            I'm still confused here, are you suggesting something like this?
            Code:
                        if (CCIPlot[0] < obLevelE && CCIPlot[0] > osLevelE)
                        {
                            Draw.Region(this, "CCIneu", CurrentBar, 0, CCIPlot, obLevelE, Brushes.Transparent, 100, Displacement);
                            Draw.Region(this, "CCIned", CurrentBar, 0, CCIPlot, osLevelE, Brushes.Transparent, 100, Displacement);
                        }    
                        else if (CCIPlot[0] > obLevelE)
                        {
                            Draw.Region(this, "CCIup", CurrentBar, 0, CCIPlot, obLevelE, Brushes.Red, opacity4, Displacement);
                        }    
                        else if (CCIPlot[0] < osLevelE)
                        {
                            Draw.Region(this, "CCIdn", CurrentBar, 0, CCIPlot, osLevelE, Brushes.Lime, opacity4, Displacement);
                        }​

            Comment


              #7
              Originally posted by Conceptzx View Post
              The CCI logic is built into this indicator, its not calling on the original CCI to calculate the plot.

              I'm still confused here, are you suggesting something like this?
              Code:
              if (CCIPlot[0] < obLevelE && CCIPlot[0] > osLevelE)
              {
              Draw.Region(this, "CCIneu", CurrentBar, 0, CCIPlot, obLevelE, Brushes.Transparent, 100, Displacement);
              Draw.Region(this, "CCIned", CurrentBar, 0, CCIPlot, osLevelE, Brushes.Transparent, 100, Displacement);
              }
              else if (CCIPlot[0] > obLevelE)
              {
              Draw.Region(this, "CCIup", CurrentBar, 0, CCIPlot, obLevelE, Brushes.Red, opacity4, Displacement);
              }
              else if (CCIPlot[0] < osLevelE)
              {
              Draw.Region(this, "CCIdn", CurrentBar, 0, CCIPlot, osLevelE, Brushes.Lime, opacity4, Displacement);
              }​
              This is not what I am suggesting; you are drawing one Region with the tag "CCIup" and another region with the tag "CCIdn" and both regions start on the first bar of the chart and go all the way up to the bar where the condition was triggered. That means the two objects will both be drawn and shade the region between the two provided values for the entirety of the chart. You will need to draw multiple separate regions that have different tags and start/end only when the CCI crosses above/below and then crosses back over to the other side in order to generate the desired result. The indicator I referenced adds info to the tag to generate new Region objects when conditions are met. For example:
              Draw.Region(this, "reg1" + sb1, CurrentBar - sb1 + 1, 0, Upper, Lower, Brushes.Transparent, wideColor, opacity, Displacement);

              Additionally, the regions do not start at the beginning of the chart and end on the current bar. You will need to indicate which bar you would like the regions to start on, which is when the crossover occurs.

              Please let us know if we may be of further assistance.
              Emily C.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Jimmyk, 01-26-2018, 05:19 AM
              6 responses
              835 views
              0 likes
              Last Post emuns
              by emuns
               
              Started by jxs_xrj, 01-12-2020, 09:49 AM
              6 responses
              3,291 views
              1 like
              Last Post jgualdronc  
              Started by Touch-Ups, Today, 10:36 AM
              0 responses
              11 views
              0 likes
              Last Post Touch-Ups  
              Started by geddyisodin, 04-25-2024, 05:20 AM
              11 responses
              62 views
              0 likes
              Last Post halgo_boulder  
              Started by Option Whisperer, Today, 09:55 AM
              0 responses
              9 views
              0 likes
              Last Post Option Whisperer  
              Working...
              X