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

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.
    JimNinjaTrader Customer Service

    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.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by llanqui, Today, 11:10 AM
        0 responses
        3 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by llanqui, Today, 10:29 AM
        0 responses
        5 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by llanqui, Today, 08:32 AM
        1 response
        11 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by lollers, Yesterday, 03:26 AM
        1 response
        53 views
        0 likes
        Last Post lollers
        by lollers
         
        Started by Salahinho99, 05-05-2024, 04:13 AM
        7 responses
        63 views
        0 likes
        Last Post Salahinho99  
        Working...
        X