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

Input value

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

    Input value

    Hello,

    I want to ask how one can add a value to a script that is enabled.


    An idea would be to use the y-value of a horizontal line. Is it possible to calculate in a script with the y-value of an horizontal line, how can this be accessed from a script please?

    Thank you!
    Tony

    #2
    Hello tonynt,

    Thank you for the post.

    You can use either of the following collections to locate drawing objects:
    https://ninjatrader.com/support/help...b=drawingtools
    https://ninjatrader.com/support/help...b=chartobjects

    Once you have an object, you could access the properties of the object like its anchors. https://ninjatrader.com/support/help...rawingtool.htm

    When trying to locate a drawing object, keep in mind this will only work going forward in realtime. Using this type of logic in a backtest or historical data will not work. If your use case is to manually draw a object and then detect it, you could do that going forward in realtime.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello,

      thank you for your reply. To generate a horizontal line I tried in the script using a bool like
      if(Closes[0][0]>Lows[0][0] && linedraw==false) {Draw.HorizontalLine(this, "TxLine", Closes[0][0], Brushes.Black); linedraw=true;}
      so that its drawn only once. But it doesnt draw the horizontal line with replay. Whats wrong there please?

      I thought this way I dont need to locate a drawing object(?)

      Thank you!
      Tony
      Last edited by tonynt; 07-29-2019, 02:31 PM. Reason: adding information with replay

      Comment


        #4
        Hello tonynt,

        If your script is drawing the object, you wouldn't need to locate it you just need to access the values you passed to the drawing object. I couldn't tell from what you provided why that is not drawing, are you certain the condition became true?


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello,

          thank you for your reply. I had to add state..Historical..return. Now it plots. But it is locked. I have to go to properties and uncheck locked. I can not find in the helpguide "horizontalline" the syntax for adding a "non-locked" horizontal line. There is no sample for Idrawings how to use those properties.

          Thank you!
          Tony
          Last edited by tonynt; 07-29-2019, 03:03 PM. Reason: add info

          Comment


            #6
            Hello tonynt,

            The object being locked is correct if it was script drawn. What is the overall goal you are trying to accomplish here? Are you trying to draw a line at a value or have some form of manually drawn line?

            Please let me know if I may be of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Hello Jesse,

              I want to use the y-value of a horizontal line. From what I learnt from your replies here I can draw the line with close of first bar, and from my understanding I add a bool so that its drawn only one time. Then I want to move the line manually, but using the y-value of the line in the code. Thats all. (and with this I dont need to locate a drawing tool, however there should not be a difference, with my idea I dont need to draw it manually because its drawn with close of first bar. yes?
              From the helpguide with Idrawing tool properties I dont see any example how to use the properties so that I can draw it "unlocked".

              And following the logic from your link I have now
              if(Closes[0][0]>Lows[0][0] && linedraw==false)
              {HorizontalLine TxLine = Draw.HorizontalLine(this, "TxLine", Closes[0][0], Brushes.Black);linedraw=true;}

              if (DrawObjects["TxLine"] as DrawingTools.HorizontalLine != null)
              {double linePrice = Instrument.MasterInstrument.RoundToTickSize(TxLine .StartAnchor.Price);}

              but I get the error message that "TxLine does not exist in context. Why? (I have done it same as the sample with myText)

              Add: there is not one sample how to use the properties. Not one! I dont know how to toggle.

              Thank you!
              Tony
              Last edited by tonynt; 07-29-2019, 03:37 PM.

              Comment


                #8
                Hello tonynt,

                Thank you for the reply.

                From the last link in post #2 you can see the objects default properties, you can toggle the IsLocked property if you wanted to make it not locked.

                Please let me know if I may be of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Hello Jesse,

                  thank you fro your reply. Maybe I wrote it same time as you posted, so I do my question again:
                  Hello Jesse,

                  I want to use the y-value of a horizontal line. From what I learnt from your replies here I can draw the line with close of first bar, and from my understanding I add a bool so that its drawn only one time. Then I want to move the line manually, but using the y-value of the line in the code. Thats all. (and with this I dont need to locate a drawing tool, however there should not be a difference, with my idea I dont need to draw it manually because its drawn with close of first bar. yes?
                  From the helpguide with Idrawing tool properties I dont see any example how to use the properties so that I can draw it "unlocked".

                  And following the logic from your link I have now
                  if(Closes[0][0]>Lows[0][0] && linedraw==false)
                  {HorizontalLine TxLine = Draw.HorizontalLine(this, "TxLine", Closes[0][0], Brushes.Black);linedraw=true;}

                  if (DrawObjects["TxLine"] as DrawingTools.HorizontalLine != null)
                  {double linePrice = Instrument.MasterInstrument.RoundToTickSize(TxLine .StartAnchor.Price);}

                  but I get the error message that "TxLine does not exist in context. Why? (I have done it same as the sample with myText)

                  Thank you!
                  Tony

                  Comment


                    #10
                    Hello tonynt,

                    Yes it looks like your edit was after I had posted my reply, going forward I would suggest to not edit your existing posts as we will not likely reply to an edit. I will only be notified if you reply, if you edit the post I will not be back to respond.

                    The error you are seeing is because you are using conditions and have not included the variable in the second condition. These two conditions need to be combined if you wanted to use the variable in the second condition.

                    Please let me know if I may be of additional assistance.


                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Hello,

                      with threads in the forum I could resolve in the meantime everything except the toggle Islocked. There is not one example how to use the properties. If there would be one sample as with other topics I would not need to ask.

                      TxLine = Draw.HorizontalLine(this, "TxLine", Closes[0][0], Brushes.Black, IsLocked);

                      ??? I get an error message that IsLocked does not exist.

                      Thank you!
                      Tony

                      Comment


                        #12
                        Hello tonynt,

                        Correct that is not valid syntax, there is no overload which takes IsLocked as a parameter. If you are unsure what parameters you can use, please see the help guide for the drawing tool being used.

                        IsLocked is a property of all drawing objects which can be set. There is an example of setting drawing object properties in the link I provided in post 2 along with the available properties, is there some confusion surrounding that sample?

                        Please let me know if I may be of additional assistance.
                        JesseNinjaTrader Customer Service

                        Comment


                          #13
                          Hello,

                          I dont see a sample there. From the helpguide it is not clear how to use this properties.
                          The myText sample is different from the use with IsLocked (as I know already from another thread BUT NOT FROM THE HELP GUIDE!)

                          Show me the sample you are referring to from where a non-programmer can understand the logic.

                          Thank you!
                          Tony

                          Comment


                            #14
                            Hello tonynt,

                            Here is the sample from the help guide, the same page also lists the properties you can use with drawing objects such as IsLocked. As a side note, the help guide samples are targeted at programmers, if you are looking for a more simplistic or non-programming related sample I am not aware of that type of item.

                            Code:
                            Text myText;
                            protected override void OnBarUpdate()
                            {  
                              if(CurrentBar == 50)
                                myText = Draw.Text(this, "tag", "test", 0, High[0]);    
                            
                              if(myText != null)
                              {          
                                Print(myText.Anchor.DrawnOnBar); // drawn on bar 50
                              }
                            
                            }
                            This is a blanket example showing how to access properties of a drawing object. The help guide does not contain a sample of every property. In a lot of cases you may need to use the more broad sample to learn how use the object in question. Once you understand how to access one of the properties of the object you can access all of the properties of the object. NinjaScript/C# are object oriented so the reference shown above this sample in the help guide explains the object you are working with and its properties that can be used.

                            If you wanted to use one of the other properties a drawing object has, you can replace the ".Anchor.DranOnBar" syntax with whatever property you wanted to use. This sample just demonstrates how to make a variable of your object which you can then access its properties using that variable. Take note how the overload is one of the supported Draw.Text overloads and the proeprty is later being accessed.

                            I would suggest trying to edit this sample in your script and change it to IsLocked syntax, if you are still having trouble please post what you tried and we can work from that.



                            Please let me know if I may be of additional assistance.
                            JesseNinjaTrader Customer Service

                            Comment


                              #15
                              Hello,

                              thank you for your reply. I dont want to have a sample of every property. Only one!

                              The islocked property has to be added in the script with "nameHorizontalLine.IsLocked=false;". This I found from the question in another thread.
                              And from the help guide there is no idea that it has to be done this way. How does the example above show how to use the properties?
                              eg like "Draw.HorizontalLine(NinjaScriptBaseowner,stringtag,boolisAutoScale,doubley,Brushbrush,DashStyleHelperdashStyle,intwidth)" ?

                              OK I have resolved everything and I can add the horizontal line "automatically", set the autodraw to false with a bool and then I can move it manually and I can use it for calculating in my code as I want. Great!

                              The bool sets to true when its drawn so that it does not plot from the initial condition and I can move it manually. I can do in ES, NQ...
                              But when I enable the script with CL 09-19 and I grab the line to move it, the line jumps like a rabbit, it jumps to prices I am not with the cursor.

                              I have for the line: if(conditions)....{TxLine = Draw.HorizontalLine(this, "TxLine", true, Closes[1][0], Brushes.Blue, DashStyleHelper.Dash,2);linedraw=true; TxLine.IsLocked=false;}
                              and then
                              if(linedraw==true)
                              {if (DrawObjects["TxLine"] != null && DrawObjects["TxLine"] is DrawingTools.HorizontalLine)
                              {double linePrice = Instrument.MasterInstrument.RoundToTickSize(TxLine .StartAnchor.Price); linevalue = linePrice;}

                              // the linevalue is what I´m calculating with in onbarupdate.


                              What might be the reason for this "jump-behavior" in CL please?

                              Thank you!
                              Tony

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by andrewtrades, Today, 04:57 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post andrewtrades  
                              Started by chbruno, Today, 04:10 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by josh18955, 03-25-2023, 11:16 AM
                              6 responses
                              436 views
                              0 likes
                              Last Post Delerium  
                              Started by FAQtrader, Today, 03:35 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post FAQtrader  
                              Started by rocketman7, Today, 09:41 AM
                              5 responses
                              19 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X