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 love2code2trade, Yesterday, 01:45 PM
              4 responses
              28 views
              0 likes
              Last Post love2code2trade  
              Started by funk10101, Today, 09:43 PM
              0 responses
              7 views
              0 likes
              Last Post funk10101  
              Started by pkefal, 04-11-2024, 07:39 AM
              11 responses
              37 views
              0 likes
              Last Post jeronymite  
              Started by bill2023, Yesterday, 08:51 AM
              8 responses
              45 views
              0 likes
              Last Post bill2023  
              Started by yertle, Today, 08:38 AM
              6 responses
              26 views
              0 likes
              Last Post ryjoga
              by ryjoga
               
              Working...
              X