Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator to repaint with RemoveDrawObject();

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

    Indicator to repaint with RemoveDrawObject();

    Hi,

    i am just starting to learn ninjascript and I would like to create a simple indicator that repaints before the candle closes, if the conditions are not met.
    I place a dot with Draw.Dot() function, and if the conditions are no longer met, I want to remove that dot with RemoveDrawObject() function.
    The problem is that this way my indicator doesn't even load and NT8 freezes.
    Can somebody help me figure out what I am doing wrong?

    Thank you
    Code:
    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class TestIndicator : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "TestIndicator";
    Calculate = Calculate.OnEachTick;
    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;
    }
    else if (State == State.Configure)
    {
    }
    }
    
    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;
    
    if (CurrentBars[0] < 4)
    return;
    
    if ( (Close[1] > Open[1])
    )
    {
    Draw.Dot(this,"HV DtUp_1"+CurrentBar, false, 1, (Low[1] + (-2 * TickSize)) , Brushes.Blue);
    }
    else
    {
    RemoveDrawObject("HV DtUp_1"+CurrentBar);
    }
    
    
    
    
    
    if ((Close[1] < Open[1])
    )
    {
    Draw.Dot(this,"HV DtDn_1"+CurrentBar, false, 1, (High[1] + (2 * TickSize)) , Brushes.Red);
    }
    else
    {
    RemoveDrawObject("HV DtDn_1"+CurrentBar);
    }
    
    }
    }
    }
    Last edited by gyilaoliver; 05-16-2024, 07:03 AM.

    #2
    Hello gyilaoliver,

    Welcome to the NinjaTrader forums!

    I see this set to run with Calculate.OnEachTick. Is TickReplay enabled?

    Drawing and removing drawing objects on each tick in historical data will be a lot processing.

    If you change the Load data based on to Bars and set the number of bars to load at 25, does the indicator finish loading?

    Are there errors appearing on the Log tab of the Control Center?

    Add prints with the time of the bar in each logic block above each Draw.Dot() call and each RemoveDrawObject call.

    Print(string.Format("{0} | Drawing HV DtUp_1{1}", Time[0], CurrentBar));

    Print(string.Format("{0} | Removing HV DtUp_1{1}", Time[0], CurrentBar));

    Save the output to a text file and include this with your reply.

    Below is a link to a support article on using prints to understand behavior.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi ChelseaB,

      thanks for your support, TickReplay is enabled, however I reduced the Load data from 5 days to 25 bars as you suggested, and now it works perfectly.
      I didn't think it would require such resources, I come from mql4/5 coding and I have to get used to the new ecosystem.

      Than you for your help

      Comment


        #4
        Hello gyilaoliver,

        There can be a lot of ticks for each bar. Having to process and draw and remove on each one, is going to be a lot of work.

        In historical, maybe wait until the bar closes before deciding if an object should be drawn or not, instead of drawing and removing on every tick of every bar.


        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I tried to work with OnBarClose, but my indicator uses Buy Sell Volume indicator, which requires OnEachTick, otherwise I couldn't make it to work

          Comment


            #6
            Hello gyilaoliver,

            In post # 4, I am suggesting you do the drawing when IsFirstTickOfBar is true when State is State.Historical.

            I am not suggesting that you change the Calculate setting.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            563 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            329 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            547 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            547 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X