• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 Beauregard, Today, 04:36 AM
              0 responses
              2 views
              0 likes
              Last Post Beauregard  
              Started by fx.practic, Today, 04:34 AM
              0 responses
              1 view
              0 likes
              Last Post fx.practic  
              Started by thomaspartyof10, Today, 02:33 AM
              0 responses
              7 views
              0 likes
              Last Post thomaspartyof10  
              Started by ArmKnuckle, Today, 01:59 AM
              0 responses
              12 views
              0 likes
              Last Post ArmKnuckle  
              Started by seppyr, Today, 01:53 AM
              0 responses
              10 views
              0 likes
              Last Post seppyr
              by seppyr
               
              Working...
              X