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

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 knowmad, Today, 03:52 AM
          0 responses
          14 views
          0 likes
          Last Post knowmad
          by knowmad
           
          Started by tradingnasdaqprueba, Today, 03:42 AM
          0 responses
          10 views
          0 likes
          Last Post tradingnasdaqprueba  
          Started by Haiasi, 04-25-2024, 06:53 PM
          4 responses
          63 views
          0 likes
          Last Post effraenk  
          Started by ccbiasi, 11-23-2017, 06:06 AM
          5 responses
          2,205 views
          0 likes
          Last Post leodavis  
          Started by kujista, Yesterday, 12:39 AM
          2 responses
          14 views
          0 likes
          Last Post kujista
          by kujista
           
          Working...
          X