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

Current Day

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

    Current Day

    Hello,

    I´m trying to find how to use in a NT7 script strategy the currentDay but I can´t find it in the forum nor in the help guide. I only find DateTime.Now ....

    I have now in the scripts working OK now the time with "ToTime(Time[0]) > 93000 && ToTime(Time[0]) < 161500)" but what do I have to add please so that its only for "Today"

    Thank you
    Tony
    Last edited by tonynt; 07-07-2017, 12:46 PM. Reason: typo

    #2
    Hello Tonynt,

    You could use the following,

    Code:
    	if (new DateTime(2017, 7, 7) == Times[0][0].Date)
    Which would be true of today equaled the 7th of July.

    Another approach would be to set a DateTime variable to the current date and use a bool to prevent this variable from being set again. For example,

    Code:
    private DateTime xNow;
    private bool doOnce= false;
    Within OnBarUpdate,
    Code:
    if(doOnce==false)
    {[INDENT]xNow = DateTime.Now;[/INDENT][INDENT]doOnce =true;[/INDENT][INDENT]Print("xNow.Date"+xNow.Date.ToString());[/INDENT]
    }
    
    if (xNow.Date == Times[0][0].Date)
    { do something}
    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply.

      I have another question concerning time please. It seems that "SampleGetHighLowByTimeRange" plots the high and low only after the endtime. What has to be modified in the code please so that it plots (and stores highestHigh and lowestLow) already during starttime and endtime?

      Thank you
      Tony
      Last edited by tonynt; 07-07-2017, 04:04 PM. Reason: translation error

      Comment


        #4
        AlanP,

        thank you for your approach with the bool. I tried to add to my code but it plots me the highestHigh and the highest of all data and not the time I have in the code. What did I wrong in OnBarUpdate:

        xNow=DateTime.Now; doOnce=true;
        if(xNow == DateTime.Now && doOnce==true && ToTime(Time[0]) > 33000 && ToTime(Time[0]) < 103000)
        {if(Low[0]<lowtz1)
        {lowtz1=Low[0]; DrawHorizontalLine("lowtz1", false, lowtz1, Color.Red, DashStyle.Dash,2);}
        }

        Thank you
        Tony

        Comment


          #5
          Hello tonynt,

          I would suggest adding print statements to check the value of your variables, and give consideration for where you are setting those variables and if they are being updated on each bar. I’ve provided a link to a youtube video which covers an example of using prints to understand behavior:

          Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...


          I’ve provided a link covering debugging which you may find helpful.

          Debugging: http://ninjatrader.com/support/forum...ead.php?t=3418

          Please let us k now if you need further assistance.
          Alan P.NinjaTrader Customer Service

          Comment


            #6
            Hello Alan,

            thank you for your reply. I do print in my chart, therefore I see that it plots the high and low of the day but not of the timesettings. What did I wrong please with the code you posted.

            Thank you!
            Tony

            Comment


              #7
              Hello Tonynt,

              Please post your complete code using the steps below.

              From the Control Center window select Tools -> Export -> NinjaScript...
              Click Add>Select the indicator>OK>Export.
              Then attach that file you saved; under My Docs>NT8>Bin>Custom>Select the downloaded .zip file.

              I look forward to your reply..
              Alan P.NinjaTrader Customer Service

              Comment


                #8
                Hello Alan,

                when doing a new script only with the conditions you posted for not bothering with all my code, I found out that I had made an error by missing a line from the quote window here in the thread.

                It´s working OK!

                Thank you for your support!

                Tony
                Last edited by tonynt; 07-13-2017, 03:25 AM. Reason: translation error, clearifying

                Comment


                  #9
                  Hello Alan,

                  I have to click F5 every day so that it starts plotting. What do I have to change please so that it plots automatically each day (when in the timezone of course)

                  Thank you!
                  Tony

                  Comment


                    #10
                    Hello tonynt,

                    Are you disconnecting from your data provider?

                    Could you please send an email to platformsupport[at]ninjatrader[dot]com with Attn: Alan P in the Subject line. Also within the email please include a link to this thread, and attach the log and trace files for the day in subject which you can find in My Documents>NinjaTrader8>Log and My Documents>NinjaTrader8/Trace folders.

                    I look forward to your email.
                    Alan P.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello,

                      thank you for your reply. No, I was not disconnected from the dataprovider. It´s running on a co-located and it´s running all the time. I´m not allowed to send log and trace files from there.

                      Thank you for your support!

                      Tony
                      Last edited by tonynt; 07-27-2017, 01:36 PM. Reason: tipo

                      Comment


                        #12
                        Hello tonynt,

                        I would need more details to diagnose the issue.

                        If you'd like to upload the full code I can take a look and see if anything jumps out. Or if you'd prefer to email a copy, send to platformsupport[at]ninjatrader[dot]com with Attn: Alan P in the Subject line. Also within the email please include a link to this thread, and the files.
                        Alan P.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by yertle, Today, 08:38 AM
                        1 response
                        5 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Started by love2code2trade, Yesterday, 01:45 PM
                        3 responses
                        22 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Started by trilliantrader, Today, 08:16 AM
                        2 responses
                        6 views
                        0 likes
                        Last Post trilliantrader  
                        Started by samish18, Today, 08:31 AM
                        1 response
                        2 views
                        0 likes
                        Last Post NinjaTrader_Clayton  
                        Started by Creamers, 09-08-2023, 10:26 AM
                        6 responses
                        157 views
                        0 likes
                        Last Post JonyGurt  
                        Working...
                        X