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

Gradient Shading Between two EMA's

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

    Gradient Shading Between two EMA's

    I have an indicator that plots two EMA's. I want to be able to gradient shade the area between the EMA's going from dark green to dark red, depending on the spread between the EMA's. Any one have any ideas if this can be done and how to do it?

    #2
    Hello Kaiviti57,

    Draw.Region() can shade a region between plots. Is this what you are looking for.?


    This is not a gradient but a solid color. Any gradient would require custom rendering with sharpdx.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea B.,
      I am also trying to plot region between 2 moving averages but unable to achieve it. I got it working for MA envelope or band but for CrossAbove & CrossBelow I am unable to plot the region, however I tested the Cross & was able to draw chart marker @ CrossAbove & CrossBelow. Any help to plot region @ cross over is appreciated, thanks.

      Comment


        #4
        OK, I am making progress but still not there yet. I have managed to create a coloured zone between my 2 EMA's. It took a while but I finally solved it by declaring the references to other indicators ( and the summation of two values) as "Values". When I tried to use the formula for the EMA and the calculation, it kept giving me errors. This is the formula I used:

        Values[0][0] = (EMA(Slow).Value[0]);
        Values[1][0] = (MACD(Fast, Slow, Smooth).Avg[0] + (EMA(Slow).Value[0]));

        if (zero>trend)
        Draw.Region(this,"effUp", CurrentBar, 0 ,Values[0],Values[1], null, Brushes.Red, 20);
        else if (zero<trend)
        Draw.Region(this,"effDown", CurrentBar, 0 ,Values[0],Values[1], null, Brushes.Green, 20);

        Comment


          #5
          Hello Kaiviti57,
          I couldn't understand your moving averages, it seems you're plotting EMA & (MACD + EMA).
          I am simply plotting 2 MA's (slow & fast) & looking the cross over to plot region, unable to do so as of now. Something I might be missing. Draw region line is ok but is not working for me, however I can plot the region if I have channel / band / envelope but on cross its not working for me.

          Update:: I got it working. Tried to change color of plot @ cross over found its coloring only for cross bar, so I changed my condition from CroosAbove / CrossBelow to Fast > Slow & Fast < Slow, it worked. Then I applied the same logic for region & it worked.
          Thanks
          Last edited by s.kinra; 09-08-2020, 08:39 AM.

          Comment


            #6
            Hello Kaiviti57,

            Below is a link to an example that uses Draw.Region().
            https://ninjatraderecosystem.com/use...acrossbuilder/

            You have mentioned that you have received error messsages.
            What are the error messages?


            The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi Chelsea,
              Apologies for the time delay in my replies. I am in a very different time zone to you and I am spending a lot of time trying to solve the issues before I reply. Basically, forget about the errors because I have moved past that. I will have a look at the example provided to see if I can get my indictor to do what I want it to do. Currently, it is shading the region between the EMA's but it is not shading the previous bars according to my rules. I will follow up after I have studied the example.

              Comment


                #8
                Hello Kaiviti57,
                The only change you need to do is modify the tag in draw.region, currently your tag is "effUp" modify it to: "effUp" + CurrentBar & your region will be plotted for previous bars as well. Basically the tag you're using is static & it will plot only 1 region, if you make it dynamic the it can plot all regions with unique tags.
                Hope it helps.

                Comment


                  #9
                  Wow, the code in the example is a bit too complex for what I am doing. I did manage to learn a few things from it though and I have incorporated into my indicator. I still have a problem though.

                  I have a plot that shows 2 EMA's. The idea is to color the band between these EMA's green, yellow or red. The color will depend on whether the RSI period and smoothing lines are above a user-defined range, within the range or below the range. The code is attached. I appear to have a problem with the if statements. The plot is coloring all yellowish - neither green, red, nor yellow. I have tried several different combinations of setting out if, else, else if, and some others. Nothing seems to works as far as I can logically see. Any help in sorting this out would be appreciated.
                  Attached Files

                  Comment


                    #10
                    Hello Kaiviti57,
                    I haven't yet gone thru your code but it seems you're facing issues with if statements, a simple fix :: use 3 if statements for 3 colors -> if, else if, else. You are possible using 2 consecutive if so the problem. I'll see your code later today.
                    Hope it helps.

                    Comment


                      #11
                      Thanks, I have tried various forms of if statements. I have tried them on their own with a return at the end of the if true part; tried them so that if one condition is true, it will go to the next if condition and then used a return again if it is false; tried them so that if it is false it uses an else if. I think I have tried every combination.

                      Comment


                        #12
                        Hello Kaiviti57,
                        I think you need to rethink your logic. You are using bool true / false for trend so it will plot only one region irrespective of your brushes because when 1 is true other automatically becomes false & the complete region will be plotted as per current trend only. For if conditions you are evaluating true / false & no evaluation is happening for CurrentBar so the region color is not changing as the condition is evaluating for full loaded data & can't differentiate the plot even though you've defined brushes.
                        Also reconsider the trend definition, when rising is rsi > avg, why not neutral is rsi == avg ?
                        Hope it helps.
                        Last edited by s.kinra; 09-09-2020, 04:54 AM. Reason: missed the trend

                        Comment


                          #13
                          OK, I took your advice and got rid of all the boolean stuff. It is getting better but it's still not right. I have spent all day with this. In fact, I have been working on this for several days. I am getting better but man, is it frustrating when I don't know why something is not working.

                          Can you please load my indicator on a chart as well as the RSI(23,23). I am using vastly different RSI values for a reason. Please see if you can figure out what I am doing wrong. Once loaded, you will see that when the RSI is above the avg(signal) line (for the current candle, and several candles back) the colors are correct. The problem now appears to be that the older candles have not painted the right color. They are all one color and this is wrong. I want the MDI to show red when the RSI is below the avg line (and lower than the neutral band). Then it should paint yellow when the RSI and the avg lines are close together and within the range of the neutral band. Finally, it would paint green when the RSI is above the avg (line and beyond the neutral band). These colors should remain for all the candles visible - and even further back.
                          Attached Files

                          Comment


                            #14
                            Hello Kaiviti57,
                            OK, so basically you want the region when rsi > avg for up trend, when rsi < avg for dn trend, when rsi == avg for no trend, pls confirm.
                            I feel declare rsi & avg as series instead of double, so you can compare rsi[0] > avg[0] , rsi[0] < avg[0] ,else & then regions will plot correctly.
                            You're calculating rising, falling & band, all 3 are actually same so ignore them for now & do the above changes.
                            Hope it helps.

                            Comment


                              #15
                              A little more confirmation on the regions. The uptrend is when rsi>(avg+Band). The downtrend is when avg>(rsi+Band). No trend or neutral is when Math.Abs(rsi-avg)==Band.

                              Currently, the region is being colored according to the formula but, it is coloring the whole region and not just the region related to the bar. It is also mixing the colors a bit because there are different conditions met.

                              I need the region to end up with multiple shaded areas within the region. This indicator does not reply upon the region being shaded one color, on one side of a crossover, and another color on the other side of the crossover. Instead, it relies on another indicator determining the color for shading. I only want to get the area shaded that directly related to the bar vertically above or below it. That is why I have three conditions: If the trend is rising, shade the area of the band (either above or below the candle) green: if the trend is falling, shade it red: if it is within the band, shade it yellow.

                              Please see the screenshot attached.
                              Attached Files
                              Last edited by Kaiviti57; 09-09-2020, 11:32 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by thumper57, Yesterday, 04:30 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by dcriador, Yesterday, 12:06 PM
                              1 response
                              16 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by dcriador, Yesterday, 12:04 PM
                              1 response
                              18 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by cutzpr, Yesterday, 08:54 AM
                              1 response
                              14 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by gcztraders, Yesterday, 03:58 AM
                              1 response
                              17 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Working...
                              X