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

Issue with my indicator not updating/refreshing properly.

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

    Issue with my indicator not updating/refreshing properly.

    I have an indicator that I wrote where the candles change colors when an MA is crossed. However, when the criteria is no longer met, it doesn't change back to the original color preset by the chart settings. I have to refresh the chart to get the candles update. Is there a piece of code I can add to my indicator so that it auto refreshes when the criteria is no longer met? Example. Price is below the 9 sma. It's crosses up above it and turns green. However, before the candle closes, it drops back below the 9 sma, it closes below the 9 sma, but stays green. It doesn't go back to the color it was originally. How do I fix it so that it changes on the fly?

    #2
    Hello jamestrader21x,

    Thank you for your post.

    I note that you had posted a similar thread in the NT7 forum as well - just to confirm, is this script for NinjaTrader 7, NinjaTrader 8 or both?

    Is the indicator updating OnBarClose, OnPriceChange, or OnEachTick?

    Would you be able to provide a snippet of your current logic for changing the color?

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      ninja trader 8

      f (State == State.SetDefaults)

      {

      Description = @"A visual representation of CCI in colored bars.";

      Name = "BACABarsEV";

      Calculate = Calculate.OnPriceChange;

      IsOverlay = true;

      DisplayInDataBox = true;

      DrawOnPricePanel = true;

      DrawHorizontalGridLines = true;

      DrawVerticalGridLines = true;

      PaintPriceMarkers = true;

      ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;

      //Disable this property if your indicator requires custom values that cumulate with each new market data event.

      //See Help Guide for additional information.

      IsSuspendedWhileInactive = true;

      SMA_Period = 9;

      AddPlot(new Stroke(Brushes.Lime, 2), PlotStyle.Bar, "Up_Color");

      AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.Bar, "Dn_Color");

      }

      else if (State == State.Configure)

      {

      }

      }

      @

      protected override void OnBarUpdate()

      {

      if (CurrentBar < 1)

      return;



      if(Close[1] <= SMA(SMA_Period)[1] && Close[0] > SMA(SMA_Period)[0])

      {

      BarBrush = Brushes.Lime;

      }



      else if(Close[1] >= SMA(SMA_Period)[1] && Close[0] < SMA(SMA_Period)[0])

      {

      BarBrush = Brushes.Red;

      }

      }


      Comment


        #4
        I had it set to on price change....I tried adding else{ return;} but it didn't work.

        Comment


          #5
          Hello jamestrader21x,

          Thank you for your reply.

          Your logic is currently set up so that if the conditions are true, the color of the bar changes, but I'm not seeing any logic for changing back when the conditions are false - this doesn't happen automatically. You'd want to revise your logic so that when the condition is reversed you repaint the bar its original color.

          Please let us know if we may be of further assistance to you.
          Kate W.NinjaTrader Customer Service

          Comment


            #6
            Is there a way to repaint the bar without coding the Close > Open BarBrush = Brushes.White;, Close < Open BarBrush = Brushes.Black, etc? Like if(x < y) {BarBrush = Brushes.default;}
            I looked through color list and didn't find anything as far as default color.

            Comment


              #7
              I added a bunch of else if statements. It looks like it's working. I appreciate the help.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by CortexZenUSA, Today, 12:53 AM
              0 responses
              1 view
              0 likes
              Last Post CortexZenUSA  
              Started by CortexZenUSA, Today, 12:46 AM
              0 responses
              1 view
              0 likes
              Last Post CortexZenUSA  
              Started by usazencortex, Today, 12:43 AM
              0 responses
              5 views
              0 likes
              Last Post usazencortex  
              Started by sidlercom80, 10-28-2023, 08:49 AM
              168 responses
              2,265 views
              0 likes
              Last Post sidlercom80  
              Started by Barry Milan, Yesterday, 10:35 PM
              3 responses
              11 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Working...
              X