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

DrawingObjects with Time

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

    DrawingObjects with Time

    Hello,

    I dont understand from the helpguide how to draw objects with time. I can draw with bars to the left and to the right, starting with the sample code below the syntax.

    But I have no idea - after trying now for hours - how to draw a horizontal line eg from 09:30 to 11:00 EST time.

    From this syntax I cant make it working: Draw.Line(NinjaScriptBaseowner,stringtag,boolisAutoScale,DateTimestartTime,doublestartY,DateTimeendTime,doubleendY,Brushbrush,DashStyleHelperdashStyle,intwidth

    DateTime0930 ??

    Thank you!
    Tony

    #2
    Hello tonynt,

    Thank you for your post.

    You could instantiate a DateTime startTime and DateTime endTime variable and in OnBarUpdate, assign each variable a DateTime value to be used for the Draw.Line method. This may be accomplished using code that looks like the following snippet below. What this snippet does is assigns a DateTime of 9:30 AM for the variable startTime and a DateTime of 11:00 AM for the variable endTime followed by using those values for our Draw.Line startTime and endTime properties

    protected override void OnBarUpdate()
    {
    if (CurrentBar == 0)
    {
    startTime = new DateTime(Time[0].Year,Time[0].Month,Time[0].Day,9,30,0,0);
    endTime = new DateTime(Time[0].Year,Time[0].Month,Time[0].Day,11,0,0,0);
    }

    if (CurrentBar < 10)
    return;

    NinjaTrader.NinjaScript.DrawingTools.Line myLine = Draw.Line(this, "tag1", false, startTime, Close[0], endTime, Close[0], Brushes.Cyan, DashStyleHelper.Dot, 2);

    }

    Please see the attached example indicator which demonstrates how to use Draw.Line(NinjaScriptBase owner, string tag, bool isAutoScale, DateTime startTime, double startY, DateTime endTime, double endY, Brush brush, DashStyleHelper dashStyle, int width).

    Let us know if we may be of further assistance.
    Attached Files
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hello,

      thank you for your reply. I added this code for the time to my indicator with calculations and it works ok. But I have another question now please, I never understood about
      "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;"
      Even from the help guide I do not understand. When should be IsSuspendedWhileInactive = true and when = false?

      Thank you!
      Tony

      Comment


        #4
        Hello tonynt,

        Thank you for your inquiry.

        When an indicator is not in use (suspended) and has IsSuspendedWhileInactive set to true, events in OnBarUpdate() will not be processed until the indicator is no longer suspended. This means that since OnBarUpdate() will not be processed when the indicator is suspended, functions such as Alert(), PlaySound(), Share(), Print(), or any other NinjaScript method used to notify a user of activity will not process until the indicator is unsuspended.

        Please note that this property is overridden to true automatically by the NinjaScript Code Wizard. You would need to remove the property or manually set it to false to disable this behavior.

        Let us know if we may further assist.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Hello,

          I can print in output window the limits and this works ok. I tried to find how to print the last traded quantity but I couldnt find it.
          Can you please give me a snippet what will print the last traded quantity in output window?

          Thank you!
          Tony

          Comment


            #6
            Hello tonynt,

            Thank you for your post.

            Please clarify the following so we may accurately assist you.

            When you state you are printing 'the limits', does this refer to printing price values? For example, the open or close value of a bar.

            Are you wanting to print the quantity of the last trade execution that was made on your account?

            Thanks in advance, I look forward to your reply.
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Hello Brandon,

              thank you for your reply. Sorry my inaccurate translation and question. I mean I can print ok now the limit price and the limit volume of bid and ask.
              I would like to print the sum of traded quantity at a certain price, when it moves eg 1 tick up then add up the trades at this price, when it moves down then add up the ticks at this price...(with reset to 0 when moving up or down to the next price) I mean instead of the size filter in T&S I want to add up on a price.

              Thank you!
              Tony

              Comment


                #8
                Hello tonynt,

                Thank you for your note.

                The VolumeProfile indicator that comes default with NinjaTrader contains open source code that you could reference for accomplishing your goal. This indicator accumulates volume for buys and sells separately based on bid and ask price. You could modify the script to combine and print the accumulated buy and sell volume together.

                Additionally, the example in the OnMarketData help guide link below shows how you could print either the Last, Bid, or Ask prices and volume.

                OnMarketData - https://ninjatrader.com/support/help...marketdata.htm

                Something else you could do is create a new indicator that creates a Dictionary. The Dictionary is a fast way to remember things. A key (like a string) maps to a value (like an int). Add() can be used to inserts keys and values. You could then loop through the Dictionary to check for last trades based on price and if that price is not found in the Dictionary, it could be added.

                Here are some publicly available C# resources about creating a Dictionary.

                MSDN - https://docs.microsoft.com/en-us/dot...ew=netcore-3.1
                TutorialsTeacher - https://www.tutorialsteacher.com/csh...arp-dictionary
                DotNetPearls - https://www.dotnetperls.com/dictionary

                Let us know if we may further assist.
                Brandon H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by terofs, Yesterday, 04:18 PM
                1 response
                21 views
                0 likes
                Last Post terofs
                by terofs
                 
                Started by CommonWhale, Today, 09:55 AM
                1 response
                3 views
                0 likes
                Last Post NinjaTrader_Erick  
                Started by Gerik, Today, 09:40 AM
                2 responses
                7 views
                0 likes
                Last Post Gerik
                by Gerik
                 
                Started by RookieTrader, Today, 09:37 AM
                2 responses
                13 views
                0 likes
                Last Post RookieTrader  
                Started by alifarahani, Today, 09:40 AM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X