Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trying to mod an EMA slope color indicator

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

    Trying to mod an EMA slope color indicator

    Hello, can somebody please help me with this, I have an indicator EMA Slope Color which paints the EMA a different color depending on if the candles are above or below it. I'm trying to modify it so that it paints an EMA 21, if a hidden EMA 9 crosses above or below it. Here is a link to the app and here is my ninjascript which isn't working properly. Any help would be appreciated. Thanks!



    protected override void OnBarUpdate()

    {

    Value[0] = (CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Value[1]);




    if (CrossAbove(EMA(9), EMA(21),1))

    {



    PlotBrushes[0][0] = UpColor;

    }

    if (CrossBelow(EMA(9), EMA(21), 1))

    {



    PlotBrushes[0][0] = DnColor;

    }
    Just an example on colorplots. A standard EMA indicator with the possibility to colorcode the slope. Selectable colors for up/down
    Last edited by augustfay; 07-30-2020, 12:01 PM.

    #2
    Hello augustfay,

    Thanks for your post.

    Please be sure to describe what is not working and that you are expecting so we can share our advise.

    Are you intending to have the color change when the there is a cross? Currently, you are just setting the color for the bar where the cross is detected.

    I may suggest using a bool that is set to true when there is a cross above, and then set to false when there is a cross below.

    If the bool is true, use PlotBrushes[0][0] = UpColor;

    If the bool is false, use PlotBrushes[0][0] = DnColor;

    We look forward to assisting.

    Comment


      #3
      Hi Jim, apologies for my lack of clarification. I am trying to get this so that the coloring doesn't only occur on the bar where the cross is detected, but remains on the EMA until the next cross is detected. The part of the EMA that is above will be one color and the part that is below will be the other. The same way the indicator is now except the coloring wouldn't be based on the bars being above or below, but instead on if the EMA is crossed. Is a bool still the best way to go about this? Thank you.

      Comment


        #4
        Hello augustfay,

        You would want to use a variable to identify when a cross has occurred and set the color based off that variable. A bool would work well here.

        We look forward to assisting.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        599 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        344 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        558 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        557 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X