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

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:

      The best futures trading community on the planet: futures trading, market news, trading charts, trading platforms, trading strategies


      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 geddyisodin, Today, 05:20 AM
      3 responses
      20 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by lorem, Today, 09:18 AM
      1 response
      4 views
      0 likes
      Last Post lorem
      by lorem
       
      Started by bmartz, Today, 09:30 AM
      0 responses
      3 views
      0 likes
      Last Post bmartz
      by bmartz
       
      Started by GussJ, 03-04-2020, 03:11 PM
      14 responses
      3,245 views
      0 likes
      Last Post GussJ
      by GussJ
       
      Started by ArkansasClint, Today, 09:28 AM
      0 responses
      0 views
      0 likes
      Last Post ArkansasClint  
      Working...
      X