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

Draw Line or Make Plot? Can I do NaN stuff in Ninjascript?

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

    Draw Line or Make Plot? Can I do NaN stuff in Ninjascript?

    I'm a convert to NinjaTrader, coming over from Thinkorswim after months of frustrating workarounds in their Thinkscript language. It's a tragically stunted scripting language that doesn't include basic things like loops or all but the most basic math functions.

    But one thing it did that I haven't figured out in NinjaScript yet relates to drawing horizontal lines.

    I'd like to draw lines on my chart to mark certain levels of support/resistance but be able to turn the lines off if certain conditions aren't met.

    In thinkscript this was done with an if statement whose ELSE section returned Nan (not a number). So you'd have something that went:

    if (mycondition) then 140 else Nan;

    That sort of statement would draw a line if the condition was met and nothing if it wasn't met. Is there a way to do this in NinjaScript?

    I'm not so sure when to use static number plots to draw horizontal lines and when to draw line objects, or whether either of these could do this for me.

    #2
    noevictorian,

    To draw horizontal lines in NT, you can use the method DrawHorizontalLine(). When you want to get rid of the lines you can use RemoveDrawObject().

    It really is up to you what your preference is between Plots vs draw object lines. Plots cannot be moved, but draw object lines can be dragged and dropped by the user.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks josh... I guess what's confusing me is that DrawHorizontalLine specifies a start and a stop point but I want to have a start point and have the stop point continually moving along with each current bar until the condition that's drawing it changes. So if the line starts drawing on bar 50 it would keep extending along with bar 51, 52, 53, 54, 55, 56, 57, 58, etc. But if conditions change on bar 78, the line would stop drawing.

      To do that with DrawHorizontal line would require removing the drawing each bar and redrawing it, yes?

      Or can I do it more easily with a plot? I'd prefer a plot so users can move it. Thanks!

      Comment


        #4
        noevictorian,

        Not sure what you mean. DrawHorizontalLine() does not take two points. http://www.ninjatrader-support.com/H...ontalLine.html

        Once you draw a horizontal line it extends left and right indefinitely.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Sorry I was thinking DrawLine(). Well I don't want the line extending forever. I want to be able to terminate it at some point. So how would I do that?

          Is there a way to terminate a horizontal line X bars away from its start point?

          Comment


            #6
            Yes, just specify endBars in relation to your startBars setting - http://www.ninjatrader-support.com/H.../DrawLine.html

            Just add / subtract the bars needed to the bars paramter in startBars.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              hello,guys,

              any examples on how to convert drawline into plot?any examples, technics,guidance are appreciated!

              Comment


                #8
                Hello outsource, and thank you for your questions. When an existing thread is over a year old, please create a new thread instead of replying to an old thread, as our system will not automatically track replies to very old threads.

                Can you clarify our goals? If you have enough information to draw an object on a chart, you should have enough information to instead assign the same values to a plot. One of our techs will be happy to assist further.
                Jessica P.NinjaTrader Customer Service

                Comment


                  #9
                  Hello, outsource.

                  It isn't possible to convert drawline into plot.
                  And You have to decide beforehand what You prefer to use.

                  When using DrawLine() You need to set coordinates of 2 dots: begin and end of the desired line. One command, 2 dots.

                  When using Plot You need to set coordinates of each dot between begin and end of Your line (look at attached image).

                  I, personally, trying to avoid using DrawLine() and use indicator plot instead.

                  Here my simple function that plot line by 2 coordinates:

                  Code:
                  public static void Connect_2_Points( DataSeries ds, int x1, double y1, int x2, double y2, ref string errorMsg )
                  		{
                  			if( x1 < x2 ){ errorMsg = "Common_class.Connect_2_points.i_Lib_Common: x1 must be greater then x2"; return; }
                  			double d = (y2 - y1) / ( x1 - x2 );
                  			
                  			double y = y1;
                  			for( int x = x1; x >= x2; x-- )
                  			{
                  				ds.Set( x, y );
                  				y += d;
                  			}
                  		}
                  Attached Files
                  fx.practic
                  NinjaTrader Ecosystem Vendor - fx.practic

                  Comment


                    #10
                    Originally posted by NinjaTrader_JessicaP View Post
                    Hello outsource, and thank you for your questions. When an existing thread is over a year old, please create a new thread instead of replying to an old thread, as our system will not automatically track replies to very old threads.

                    Can you clarify our goals? If you have enough information to draw an object on a chart, you should have enough information to instead assign the same values to a plot. One of our techs will be happy to assist further.
                    Hi Jessica,

                    the problem that i have an indicator that i`m trying to get into strategy,but it doesn`t work properly.I`m not sure,but i think it`s because Drawline method,that used to draw trend lines.I tried everything ILine,bools,convert double to dataseries but it just shoots entries randomly.I attached the indicator in case someone would want to assist.
                    Attached Files

                    Comment


                      #11
                      Originally posted by fx.practic View Post
                      Hello, outsource.

                      It isn't possible to convert drawline into plot.
                      And You have to decide beforehand what You prefer to use.

                      When using DrawLine() You need to set coordinates of 2 dots: begin and end of the desired line. One command, 2 dots.

                      When using Plot You need to set coordinates of each dot between begin and end of Your line (look at attached image).

                      I, personally, trying to avoid using DrawLine() and use indicator plot instead.

                      Here my simple function that plot line by 2 coordinates:

                      Code:
                      public static void Connect_2_Points( DataSeries ds, int x1, double y1, int x2, double y2, ref string errorMsg )
                      		{
                      			if( x1 < x2 ){ errorMsg = "Common_class.Connect_2_points.i_Lib_Common: x1 must be greater then x2"; return; }
                      			double d = (y2 - y1) / ( x1 - x2 );
                      			
                      			double y = y1;
                      			for( int x = x1; x >= x2; x-- )
                      			{
                      				ds.Set( x, y );
                      				y += d;
                      			}
                      		}
                      Thanks,Fx.Drawline is just a pain in the neck when it comes to use it with strategies.

                      Comment


                        #12
                        I am attaching a copy of your source where a single line's current Y value is added as a plot value. Look for my initials (JDP) in your code. Code samples we provide are for educational purposes, and are not intended for live trading, and are not guaranteed to accomplish any user goal or to be maintained. Please let us know if there are any other ways we can help.
                        Attached Files
                        Jessica P.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_JessicaP View Post
                          I am attaching a copy of your source where a single line's current Y value is added as a plot value. Look for my initials (JDP) in your code. Code samples we provide are for educational purposes, and are not intended for live trading, and are not guaranteed to accomplish any user goal or to be maintained. Please let us know if there are any other ways we can help.
                          Jessica,do i have to do the same with the other instacies and the call it via strategy?

                          Comment


                            #14
                            Yes, it was intended that you do the same with other instances. From a strategy you will need to use

                            Code:
                            AddChartIndicator(TrendSpotter(STPeriod, LTPeriod, STUTbool, LTUTbool, STDTbool, LTDTbool, STUTColor, LTUTColor, STDTColor, LTDTColor))
                            In your Initialize routine.
                            Jessica P.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by thanajo, 05-04-2021, 02:11 AM
                            3 responses
                            465 views
                            0 likes
                            Last Post tradingnasdaqprueba  
                            Started by Christopher_R, Today, 12:29 AM
                            0 responses
                            10 views
                            0 likes
                            Last Post Christopher_R  
                            Started by sidlercom80, 10-28-2023, 08:49 AM
                            166 responses
                            2,235 views
                            0 likes
                            Last Post sidlercom80  
                            Started by thread, Yesterday, 11:58 PM
                            0 responses
                            4 views
                            0 likes
                            Last Post thread
                            by thread
                             
                            Started by jclose, Yesterday, 09:37 PM
                            0 responses
                            9 views
                            0 likes
                            Last Post jclose
                            by jclose
                             
                            Working...
                            X