Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

About sessions

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

    About sessions

    How can I output only the first session of multiple market sessions (only 9:01 in the attached image)?
    Attached Files

    #2
    hello,

    The script processes all bars for the timeframe you selected which generally covers multiple sessions. to stop outputting after 1 session you would need to make logic which prevents the print after the first time it happens. you could use a bool variable for that type of use case.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply.


      Can I have a sample code please?​

      Comment


        #4
        Hello ラリー,

        I don't know of a specific sample of stopping on the first session, that would be something you would have to make if you wanted to do that. If you are unsure about how to use bool variables in C# I would suggest to research C# educational tutorials on external resources. A very simple example of using a bool would be like the following:

        private bool myBoolVariable;
        protected override OnBarUpdate()
        {
        if(someCondition)
        {
        myBoolVariable = true;
        }

        if(myBoolVariable == true)
        {

        }

        }
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thank you for your reply.

          Only the end time of the second session was output, but I would like to output only the first session (9:01).
          If so, do I need to add any additional conditions?​
          Attached Files

          Comment


            #6
            Hello ラリー,

            In the image it looks like you just copied/pasted the code that I had provided as a sample and modified the condition. For the print to work once you need to still use that condition for the print. If you are having trouble understanding where to put the different code you see I would suggest using external C# tutorials and guides to first learn about C# language. That will help a lot when working with manually coded NinjaScript. You just haven't used the condition body for the print { Print(...) ;}
            JesseNinjaTrader Customer Service

            Comment


              #7
              Thank you for your reply.

              In the sample code you provided, there is an if(someCondition).
              Is it necessary to write that code as well?​

              Comment


                #8
                Hello ラリー

                I had made someCondition meaning any condition you wanted. You need to edit the code to be how you want it, I only provided what is known as pseudo code which can otherwise be though of as a placeholder. You fill in the blanks with what you need, that is just the structure in C# that you would use for that type of condition.

                The sample is just showing the basics of using a condition to control a bool variable. If the first condition becomes true, set the bool variable to true. If the bool variable is true the second condition can then be true and work.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Thank you for your reply.

                  I hope that once I have sorted out what you have taught me, I will be able to ask you about this matter again.​

                  Comment


                    #10
                    I changed the code and ran it again, but it seems to print all session times.

                    In the attached image, I wanted to output the time of the first opening price (only 9:01), what is wrong?​
                    Attached Files

                    Comment


                      #11
                      Hello ラリー,

                      You would still need add whatever additional logic you wanted to use that variable the first time it was true. After its true once you would have to reset the variable to false and also stop setting the variable to true by preventing the first condition from happening again.

                      If you are having a hard time understanding how to make conditions or write conditional logic in manually coded NinjaScript I would suggest to use external C# tutorials to learn C# before working with manually coded NinjaScript. NinjaScript is C# language so having a firm understanding of how to program in C# would be necessary to manually code scripts. You can also reach out to a third party developer to have the item you want created for you.
                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        Thank you for your reply.

                        You mentioned that we need to add additional logic that uses variables, could you please give us an example?

                        Comment


                          #13
                          Hello ラリー,

                          I would be unable to provide a full sample here as that would just be coding the item for you, our support cannot create custom sample upon request but we can provide general educational information on topics.

                          I would suggest to research external C# educational websites and tutorials to learn general C# conditional logic before trying to work with manually coded NinjaScript. Our support won't be able to create code upon request for you so it is important that you have a firm understanding of C# language and how that works before trying to work with manually coded NinjaScript.

                          There are numerous ways to do a task one time in C#, a very common way would be to use bool variables to make logic with states. You can search online for C# examples of using bool conditions or other conditional logic if you are unsure how to do that. Here is one example, I had used google to search for "c# bool conditions example" and here is a public resource that has basic condition examples: https://www.universalclass.com/artic...rogramming.htm

                          Once you have a good understanding of how if conditions work with C# you can create any number of conditions in your script to accomplish tasks.

                          Learning about C# conditions and C# variables would be two very important concepts to start with if you plan to manually code in NinjaScript.
                          JesseNinjaTrader Customer Service

                          Comment


                            #14
                            Thank you for your reply.
                            I referred to the link you provided.

                            I think I understand that the code in the wave brackets will be executed if the code describing the condition with if meets the condition.

                            As for the else statement, I understand that it is to be executed if the condition is not met by the if.

                            I was not sure if someCondition in if(someCondition) was a function or a variable and searched the Ninja Trader documentation but could not find any hits.

                            Is someCondition a function?

                            Comment


                              #15
                              Hello ラリー,

                              No that is not a function, please refer back to my previous comment in post 8, you have already asked about "someCondition" previously and I had provided a reply about that.

                              JesseNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by f.saeidi, Yesterday, 12:14 PM
                              9 responses
                              23 views
                              0 likes
                              Last Post f.saeidi  
                              Started by Tim-c, Today, 03:54 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post Tim-c
                              by Tim-c
                               
                              Started by FrancisMorro, Today, 03:24 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post FrancisMorro  
                              Started by Segwin, 05-07-2018, 02:15 PM
                              10 responses
                              1,772 views
                              0 likes
                              Last Post Leafcutter  
                              Started by Rapine Heihei, 04-23-2024, 07:51 PM
                              2 responses
                              31 views
                              0 likes
                              Last Post Max238
                              by Max238
                               
                              Working...
                              X