Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw region between 2 indicator lines

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

    Draw region between 2 indicator lines

    Hi. I would appreciate some guidance to get the following accomplished:

    I have an indicator that colors the region between the EMA and LinReg but it does it based on whether the LinReg is faster than the EMA. See attached Image 1.

    What I'd like to change is that the region between the two lines is colored depending on whether the LinReg is falling or rising as depicted in the attached photoshopped Image 2.

    Can the existing code be modified to accomplish that (I can post that code if needed) or would it be better to start from scratch?

    Where do I start keeping in mind that my coding capabilities are minimal.

    sandman
    Attached Files

    #2
    Hi Sandman,

    Thank you for posting.

    Yes, the existing code can be modified. For the rising and falling you can use the function check Rising and Falling with in the if statement that draws the region.

    Example -
    Code:
    if(Rising(LinReg(20)))
    {
         DrawRegion(...);
    }
    http://www.ninjatrader.com/support/h...tml?rising.htm

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      You can find the indicator here:



      It is a free download for elite members.

      Below is the code section used to do the coloring. It is more complex than usual in order to allow to shift the indicator plot forwards and backwards.

      Code:
      if (Trigger[0]>TriggerAverage[0])
                  {
                      PlotColors[0][-Displacement] = upColor;
                      PlotColors[1][-Displacement] = upColor;
                      if(opacity != 0)
                      {    
                          if(FirstTickOfBar)
                              priorIndex = index;
                          count = CurrentBar - priorIndex + 1 - Displacement;
                          if(upTrend[1])
                          {
                              if(index == CurrentBar)
                                  RemoveDrawObject("triggerBands" + CurrentBar);
                              if(count <= CurrentBar)
                                  DrawRegion("triggerBands" + priorIndex, count, -Displacement, Trigger, TriggerAverage, Color.Transparent, upColor, opacity);
                              index = priorIndex;
                          }
                          else
                          {
                              if (count <= CurrentBar && index == priorIndex)
                                  DrawRegion("triggerBands" + priorIndex, count, 1 - Displacement, Trigger, TriggerAverage, Color.Transparent, downColor, opacity);
                              DrawRegion("triggerBands" + CurrentBar, 1 - Displacement, -Displacement, Trigger, TriggerAverage, Color.Transparent, upColor, opacity);
                              index = CurrentBar;
                          }
                      }
                      upTrend.Set(true);
                  }
                  else if (Trigger[0]<TriggerAverage[0])
                  {
                      PlotColors[0][-Displacement] = downColor;
                      PlotColors[1][-Displacement] = downColor;
                      if(opacity != 0)
                      {    
                          if(FirstTickOfBar)
                              priorIndex = index;
                          count = CurrentBar - priorIndex + 1 - Displacement;
                          if(!upTrend[1])
                          {
                              if(index == CurrentBar)
                                  RemoveDrawObject("triggerBands" + CurrentBar);
                              if(count <= CurrentBar)
                                  DrawRegion("triggerBands" + priorIndex, CurrentBar - priorIndex + 1 - Displacement, -Displacement, Trigger, TriggerAverage, Color.Transparent, downColor, opacity);
                              index = priorIndex;
                          }
                          else
                          {
                              if (count <= CurrentBar && index == priorIndex)
                                  DrawRegion("triggerBands" + priorIndex, CurrentBar - priorIndex + 1 - Displacement, 1 - Displacement, Trigger, TriggerAverage, Color.Transparent, upColor, opacity);
                              DrawRegion("triggerBands" + CurrentBar, 1 - Displacement, -Displacement, Trigger, TriggerAverage, Color.Transparent, downColor, opacity);
                              index = CurrentBar;
                          }
                      }
                      upTrend.Set(false);
                  }            
                  else
                  {
                      PlotColors[0][-Displacement] = PlotColors[2][-Displacement];
                      PlotColors[1][-Displacement] = PlotColors[2][-Displacement];
                      if(opacity != 0)
                      {    
                          if(FirstTickOfBar)
                              priorIndex = index;
                          count = CurrentBar - priorIndex + 1 - Displacement;
                          if(index == CurrentBar)
                              RemoveDrawObject("triggerBands" + CurrentBar);
                          if(count <= CurrentBar)
                              DrawRegion("triggerBands" + priorIndex, count, -Displacement, Trigger, TriggerAverage, Color.Transparent, PlotColors[0][-Displacement], opacity);
                          index = priorIndex;
                      }
                      upTrend.Set(upTrend[1]);
                  }

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      607 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      353 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      560 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      561 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X