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 smartromain, Today, 02:52 AM
          0 responses
          12 views
          0 likes
          Last Post smartromain  
          Started by Marklhc1988, 04-19-2023, 11:11 AM
          12 responses
          575 views
          1 like
          Last Post victor68133  
          Started by nicthe, Yesterday, 02:58 PM
          1 response
          10 views
          0 likes
          Last Post nicthe
          by nicthe
           
          Started by percy3687, 05-17-2024, 12:28 AM
          3 responses
          31 views
          0 likes
          Last Post percy3687  
          Started by SilverSurfer1, Yesterday, 01:33 PM
          0 responses
          14 views
          0 likes
          Last Post SilverSurfer1  
          Working...
          X