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

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[[B]1[/B]][0].TimeOfDay == new TimeSpan(10, 30, 01) )
    			{
    			ExitShort([B]1[/B],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.
        Josh G.NinjaTrader 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 jeronymite, 04-12-2024, 04:26 PM
          3 responses
          40 views
          0 likes
          Last Post jeronymite  
          Started by bill2023, Today, 08:51 AM
          2 responses
          16 views
          0 likes
          Last Post bill2023  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          167 responses
          2,260 views
          0 likes
          Last Post jeronymite  
          Started by warreng86, 11-10-2020, 02:04 PM
          7 responses
          1,362 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by Perr0Grande, Today, 08:16 PM
          0 responses
          5 views
          0 likes
          Last Post Perr0Grande  
          Working...
          X