• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Sell at specific time

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

    Sell at specific time

    I have a problem with strategy sell order.

    When I try to sell 100 of my position of 700 shares at say 10:30am, it executes all of the shares in 100 share lots during that minute, So I coded it this way:

    if (Times[0][0].TimeOfDay == new TimeSpan(10, 30, 01))

    {

    ExitLong(Convert.ToInt32(100), @"1030", @"buy");

    So I programmed it to sell 100 shares at 10 am and 30 minutes and 1 second. This way it should only sell 100 shares at that point in time. But it sold nothing at that time.

    I am running one minute charts. Should I be running one second charts to get these executions?

    What am I doing wrong here?

    #2
    Originally posted by Deanmadar View Post
    I have a problem with strategy sell order.

    When I try to sell 100 of my position of 700 shares at say 10:30am, it executes all of the shares in 100 share lots during that minute, So I coded it this way:

    if (Times[0][0].TimeOfDay == new TimeSpan(10, 30, 01))

    {

    ExitLong(Convert.ToInt32(100), @"1030", @"buy");

    }

    So I programmed it to sell 100 shares at 10 am and 30 minutes and 1 second. This way it should only sell 100 shares at that point in time. But it sold nothing at that time.

    I am running one minute charts. Should I be running one second charts to get these executions?

    What am I doing wrong here?
    Why not just change it to exactly at 10 30 AM? Is there any particular reason why you're trying to execute it at 10 30 and 1 second?

    Yes, if you want to execute it at 1 second, run 1 second chart. OR you can add one second data series within your strategy code. I believe if you go to the forum section called "samples"; n8 team has provided a sample for situations like this where the user wants to execute an order at a smaller time frame even though the entry was submitted via higher time frame.

    Here is a sample:

    Code:
    			else if (State == State.Configure)
    			{
    				AddDataSeries(Data.BarsPeriodType.Second, 1);
    			}
    Then:

    Code:
    			if (Times[1][0].TimeOfDay == new TimeSpan(10, 30, 01) )
    			{
    			ExitShort(1,Convert.ToInt32(10), @"1030", @"buy");
    			}
    The bolded "1" within the ExitShort() condition is the pointer for "which" data series you want to submit your order to.. and same with the "1" within Times command.This should work.. i just tested it.

    Goodluck!

    Comment


      #3
      Thank you Cal,

      I appreciate your response. The reason I am doing seconds is because I do not want all the shares to be sold at 10:30 am.

      I really do not want to deal with seconds. I am only doing it because I do not want multiple executions at that time as the code reiterates itself on each tick.

      I only want 100 shares sold. So if I code it this way, the strategy will sell only once at 10:30 am? I have "update on each tick" ON.

      if (Times[0][0].TimeOfDay == new TimeSpan(10, 30, 00))

      {

      ExitLong(Convert.ToInt32(100), @"1030", @"buy");

      }

      Thanks

      Comment


        #4
        Hello Deanmadar,

        If your orders are not being placed, It sounds like your conditions may not be becoming true when you think they are. Have you tried placing Print() statements in your code to see when your conditions are being met?

        Debugging NinjaScript Code
        https://ninjatrader.com/support/foru...49&postcount=2

        If you want your sell condition to only execute once each day at that time you could use ToTime and IsFirstTickOfBar to do something similar to the following:

        Code:
        			if (ToTime(Time[0]) == ToTime(10, 30, 00) && IsFirstTickOfBar)
        			{
        				ExitLong( 100 , @"mySellOrder", "myEntryOrder");
        			}
        I am including links to our help guide documentation for IsFirstTickOfBar and ToTime, for your convenience.

        Help Guide- IsFirstTickOfBar
        https://ninjatrader.com/support/help...ttickofbar.htm

        Help Guide- ToTime
        https://ninjatrader.com/support/help...us/?totime.htm

        Please let me know if you have any further questions.
        JoshNinjaTrader Customer Service

        Comment


          #5
          Thanks Josh. Thats great info. I will try it and get back to you if I need further assistance.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by njesopawt, Today, 11:32 PM
          0 responses
          2 views
          0 likes
          Last Post njesopawt  
          Started by iceman2018, Today, 09:56 PM
          2 responses
          10 views
          0 likes
          Last Post samir
          by samir
           
          Started by [email protected], Today, 10:13 PM
          0 responses
          4 views
          0 likes
          Last Post garzon.javier.e@gmail.com  
          Started by iceman2018, Today, 09:51 PM
          0 responses
          5 views
          0 likes
          Last Post iceman2018  
          Started by n8dogg59, Today, 06:55 AM
          2 responses
          18 views
          0 likes
          Last Post n8dogg59  
          Working...
          X