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 2 lines on cross over

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

    Coloring 2 lines on cross over

    Hello,
    Can someone give me a code example of how to change the color of 2 moving averages when they cross?
    Thanks

    #2
    Hello CaptainAmericaXX,

    You may view the following thread that goes over changing an indicator(s) color.


    Let us know if we can be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      JC,
      Thanks for the reply, however I need to change the colors dynamically, on a crossover. For instance, when the top line crosses the bottom I'd like color both lines red, then when the bottom line crosses the top turn both lines green. Any ideas?

      Comment


        #4
        Okay, here is what I have so far. It's working to change the MA color, but it only lasts for one bar. I'd like it to last until the next cross over. I know I can figure this out eventually, but if someone can ease my pain and give me a quick answer,I'd be grateful.
        protected override void Initialize()
        {
        Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Slow"));
        Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "Fast"));
        Overlay = true;
        }


        protected override void OnBarUpdate()
        {

        if(CrossAbove(HMA(slowperiod), HMA(fastperiod), 1))
        {
        PlotColors[0][0] = Color.Green;
        PlotColors[1][0] = Color.Green;
        }
        if(CrossBelow(HMA(slowperiod), HMA(fastperiod), 1))
        {
        PlotColors[0][0] = Color.Red;
        PlotColors[1][0] = Color.Red;
        }
        Slow.Set(HMA(slowperiod)[0]);
        Fast.Set(HMA(fastperiod)[0]);

        Comment


          #5
          All right I figured it out. Now I need to get it to overlay on the price. For some reason the indicator in in a new panel. Here's the code.
          protected override void Initialize()
          {
          Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Slow"));
          Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "Fast"));
          Overlay = true;
          }


          protected override void OnBarUpdate()
          {

          if(HMA(slowperiod)[0] > HMA(fastperiod)[0])
          {
          PlotColors[0][0] = Color.Green;
          PlotColors[1][0] = Color.Green;
          }
          else
          {
          PlotColors[0][0] = Color.Red;
          PlotColors[1][0] = Color.Red;
          }

          Slow.Set(HMA(slowperiod)[0]);
          Fast.Set(HMA(fastperiod)[0]);
          }

          Comment


            #6
            Well I'm answering my own questions. Maybe this post will be good for someone as clueless as me. Anyway, originally I had Overlay = false; I changed it to true, but only refreshed the indicator with F5 on the chart instead of removing it and reinstalling it when I changed the code to Overlay = true. All is good now.

            Comment


              #7
              Hello CaptainAmericaXX,

              Glad that you were able to get it all figured out, and thanks for posting the resolutions that you found as well.
              JCNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by judysamnt7, 03-13-2023, 09:11 AM
              4 responses
              59 views
              0 likes
              Last Post DynamicTest  
              Started by ScottWalsh, Today, 06:52 PM
              4 responses
              36 views
              0 likes
              Last Post ScottWalsh  
              Started by olisav57, Today, 07:39 PM
              0 responses
              7 views
              0 likes
              Last Post olisav57  
              Started by trilliantrader, Today, 03:01 PM
              2 responses
              21 views
              0 likes
              Last Post helpwanted  
              Started by cre8able, Today, 07:24 PM
              0 responses
              10 views
              0 likes
              Last Post cre8able  
              Working...
              X