Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

imported values in script

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

    imported values in script

    Hello,

    I want to ask please how I can work in a script with values from a csv, or xls, or txt file.

    When trying to get a solution I found indicators that plot lines from a txt file, but I dont know how to use values in a script strategy.

    Thank you
    Tony

    #2
    Hello,

    Thank you for the question.

    It depends on the file format and how you will ultimately parse the file on how you would need to code this.

    I would suggest if you already have an indicator that does this, to either determine if the indicators plot can just be used from the strategy or mirror the logic used in the indicator in your own strategy instead.

    To use the indicator in the strategy a simple example is if you call the Bollinger from a strategy and want the Lower line, you would use:

    Code:
    Bollinger(1,12).Lower[0]
    The same concept should apply to the indicator you are using, You would call the Indicator name and parameters followed by the Plot name and [0] to access the currentbar value. So assuming the indicator is named "LoadFromFile" and the plot is "LoadedData", it would look similar to the following:

    Code:
    LoadFromFile().LoadedData[0]
    If instead you would like to mirror the logic in your own script, you would need to view the code to the indicator to see how the file is loaded and parsed. From this information you could build your own logic in the strategy to accomplish the same task.

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

    Comment


      #3
      Hello Jesse,

      thank you for your reply. Sorry that I do not understand correctly what y mean. Please let me give you a very short example and maybe you can show me with this. I have a txt file "levels.txt" (or whatever file format NinjaTrader "likes" to get the values from) with "ES" "Support1" "1910,50"

      In the script eg simply I want to use from this file if(close[0] < "Support1" then golong

      Thank you
      Tony

      Comment


        #4
        Hello,

        Thank you for the example.

        There would be no exact sample for this as the data would be unique to your needs, also there are no built in methods to do what you are asking, this would require your own custom programming using C#.

        For this you would either need to use the existing indicator you had mentioned to follow was has already been coded, or create your own logic to read and parse the file yourself.

        We have examples on reading text files using NinjaScript, but because this is just a general C# concept there are no built in NinjaScript methods or documentation related to this.

        To be simple, what needs to happen would be to read the text file. The read data would need to be parsed line by line likely into a DataSeries. From there you could manage the data just like any other DataSeries in NinjaScript.

        I would suggest first trying the sample we have and apply the concepts used from that script in your own script. if you have specific questions on specific syntax used please let me know.





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

        Comment


          #5
          Hello,

          when trying to work this out there appears another question concerning "values from outside" please:

          how can I export the values from an indicator and use them in a script please. I can not join the indicator with a script, so I thought I can use the plot values in the script other way without adding this "heavy" indicator in the code.

          Thank you
          Tony

          Comment


            #6
            Hello,

            How can I export the values from an indicator and use them in a script please.
            For strategies and indicators, this is already possible. When using a strategy or indicator you can Call on any other indicators to access their Plot values, so this type of system is already in place for strategies and indicators. For other data such as a Text file, you would need to use the Reading from file example and create your own logic that parses the data into a format you can use.

            Can you further explain what you are trying to do? If you are trying to avoid calling an indicator from a strategy, this would likely be less efficient to try and go around the ways that are already in place. Calling another script from your current script will keep everything in sync as well so this is another item to consider.

            I can not join the indicator with a script, so I thought I can use the plot values in the script other way without adding this "heavy" indicator in the code.
            If you instead want to write the data out of the indicator to file and then later parse the data from another script, this would be extra work for the platform as you are now also writing and reading in addition to what the scripts are normally doing. You can certainly do this but you would need to follow the two examples for Writing data and for Reading data and create your own logic to parse the data as needed.



            Can you please explain further for the need of writing and reading the data? If that is not needed and the standard model of data access can be used, that would likely be a better way to code this rather than doing extra work that may not be needed.

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

            Comment


              #7
              Hello,

              thank you for your reply. I can not join a big indicator suite with a script-strategy.

              So I want to use the Plot0 and Plot1 Values from that indicator in a script so that I only need to refer these Plot Values - without Adding the Indicator to the script. This is what I need with the indicator. (The other idea with values from a file I try to get out the next days).

              The access to the plot values might be a easy thing - if one knows how to do.

              Indicator A: sets Value Plot0[0]=1;
              Another Indicator refers to this Value, or holds this Value, or.......
              And this "another Indicator" I can simply add to my script as I do with SMA, MACD......
              This would be what I need for the indicator values, means like a "bridge" indicator in between as I can not join the original indicator.

              I hope I could translate and explain now better.

              Thank you for your support!
              Tony

              Comment


                #8
                Hello,

                Thank you for the reply. I am sorry but this does not clarify the question for me.

                Lets say you have a pack of purchased indicators and want to use one with the strategy. You said "I can not join a big indicator suite with a script-strategy"

                I would like to ask, how are you going to get this data if you can not access the indicator from script?

                A bridge indicator would still need to call the purchased indicator in the same way a strategy would to get data from it, so the strategy would be able to add the purchased indicator if an indicator can access it.

                If you have a different reason to do this you certainly can try to use the file write/read method or whatever works for you really, NinjaScript is flexible so that you can do basically what you would like. The standard approach for any indicator in a strategy would be that the strategy calls the indicator to get data.

                If the indicator is unable to be used in NinjaScript, this indicator would not be a supported item based on the way it was programmed. If this is the case you can look for other un supported methods which may or may not work but I can only recommend using the standard model of calling the indicator from the strategy for items that are capable or programmed to allow this.

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

                Comment


                  #9
                  Hello,

                  thank you for your reply. I tried to work with this Streamreader but I dont understand it. Sorry!

                  Can you please shortly post me the 2 lines when I need to work with values from a text file

                  ES 1963.75 or (ES, 1963.75) <- value1
                  ES 1968.00 or (ES, 1968.00) <- value2

                  "if GetCurrentAsk()<value1 then drawrectangle"
                  "if GetCurrentAsk()<value2 then drawtriangle"

                  Thank you so much for your support!

                  Best regards
                  Tony
                  Last edited by tonynt; 09-09-2015, 03:50 PM. Reason: translation error

                  Comment


                    #10
                    Hello,

                    I am unsure I understand what you are asking,

                    Are you asking to convert the provided lines into correct syntax?

                    "if GetCurrentAsk()<value1 then drawrectangle"
                    "if GetCurrentAsk()<value2 then drawtriangle"

                    Can you please clarify this question?

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

                    Comment


                      #11
                      Hello,

                      thank you for your reply. I forwarded this already to a NT-consultant as it is to difficult for me to do.

                      Best
                      Tony

                      Comment


                        #12
                        Hello,

                        another question referring write and read please: when writing to a file from an indicator and reading from that file in a script, is there time-delay? Is this same speed as to add the indicator to the script strategy? What when its only a true or false given by the indicator to the file and this to use in the script-strategy. Does this work OK or with time-delay please?

                        Thank you
                        Tony

                        Comment


                          #13
                          Hello tonynt,

                          There is no time delay once the line of code to write/read to/from a file is executed.

                          Can you please clarify what you mean by "What when its only a true or false given by the indicator to the file and this to use in the script-strategy."?
                          Zachary G.NinjaTrader Customer Service

                          Comment


                            #14
                            Hello,

                            thank you for your reply. Sorry for doing my question maybe not accurately in english. For clarifying:

                            a.) one part of the question is if there is a time-delay when writing values from an indicator and reading it in a script. I mean a time-delay compared to a "normal and simple" add(Indicator) in the script.

                            b.) the other part of the question concerns my thoughts about indicator values or only "true/false": I thought that maybe its faster when there is not a value given by the indicator but only a true or false. And if so that this might be also faster to read and work in the script when there is a simple true or false instead of eg if(Variable1=4000). I dont know how NT reads, counts and analysis the imported or read value, so I thought that simple true/false would be faster, less cpu-intensive....than a value.

                            Like its always faster to answer with "yes" or "no" instead of "thinking and comparing a value"

                            I hope I could explain better in english this time.

                            Thank you for your support.
                            Tony

                            Comment


                              #15
                              Hello tonynt,

                              A. The speed of reading from and writing to a file on your hard drive would depend on the drive's speed, but there will be no noticeable time delay when reading and writing to a file from a script.

                              B. There will be no noticeable difference in speed between comparing values or just using a true or false boolean.
                              Last edited by NinjaTrader_ZacharyG; 09-15-2015, 06:59 AM.
                              Zachary G.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by FrazMann, Today, 11:21 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post FrazMann  
                              Started by geddyisodin, Yesterday, 05:20 AM
                              8 responses
                              52 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by cmtjoancolmenero, Yesterday, 03:58 PM
                              10 responses
                              36 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by DayTradingDEMON, Today, 09:28 AM
                              4 responses
                              24 views
                              0 likes
                              Last Post DayTradingDEMON  
                              Started by George21, Today, 10:07 AM
                              1 response
                              19 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Working...
                              X