Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Coloring background based on MA Crossover

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

    Coloring background based on MA Crossover

    Hi,

    I created the following indicator to color the background when a EMA crosses over or below a SMA. However i would like the background to stay painted until the opposite crossover happens rather than just for one bar.

    Is it possible to have a condition instead of a fix number to define the length of the coloring?

    CrossAbove(EMA(FastEMA), SMA(SlowSMA), 1)

    See indicator attached


    thanks
    Attached Files

    #2
    reno,

    You would probably want to change this :

    if(
    CrossAbove(EMA(FastEMA), SMA(SlowSMA), 1)

    )
    {
    BackColorAll = Color.PaleGreen;



    }

    else

    if(
    CrossBelow(EMA(FastEMA), SMA(SlowSMA), 1)
    )
    {
    BackColorAll = Color.LightCoral;



    }
    To this :

    Code:
    
    			if(
    				EMA(FastEMA)[0] > SMA(SlowSMA)[0]
    				
    				)
    			{
    				BackColorAll = Color.PaleGreen;
    							
    				
    				
    			}
    			
    			else
    				
    			if(
    				EMA(FastEMA)[0] < SMA(SlowSMA)[0]
    				)
    			{
    				BackColorAll = Color.LightCoral;
    							
    				
    				
    			}
    If you would like to have a set amount of bars that would be colored, you could use this :

    if(
    CrossAbove(EMA(FastEMA), SMA(SlowSMA), WIDTH)

    )
    {
    BackColorAll = Color.PaleGreen;



    }

    else

    if(
    CrossBelow(EMA(FastEMA), SMA(SlowSMA), WIDTH)
    )
    {
    BackColorAll = Color.LightCoral;



    }
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      I guess i would,

      Thanks Adam, i cant believe i didn't think of that.

      Comment


        #4
        And can i make it only color the background on panel #2 rather than the whole chart?

        When i select Panel #2 it still paints the whole chart.

        thanks,

        Comment


          #5
          reno,

          You would want to change "BackColorAll" to "BackColor".

          Adam P.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          579 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          334 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          554 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          551 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X