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 Hwop38, 05-04-2026, 07:02 PM
      0 responses
      169 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      324 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      250 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      351 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      180 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Working...
      X