Go Back   NinjaTrader Support Forum > NinjaTrader 8 > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 01-11-2018, 07:47 PM   #1
Deanmadar
Junior Member
 
Join Date: Dec 2017
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
Default 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?
Deanmadar is offline  
Reply With Quote
Old 01-12-2018, 12:54 AM   #2
calhawk01
Senior Member
 
Join Date: May 2013
Posts: 443
Thanks: 10
Thanked 26 times in 21 posts
Default

Quote:
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!
calhawk01 is offline  
Reply With Quote
The following user says thank you to calhawk01 for this post:
Old 01-12-2018, 09:40 PM   #3
Deanmadar
Junior Member
 
Join Date: Dec 2017
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
Smile

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
Deanmadar is offline  
Reply With Quote
Old 01-15-2018, 10:57 AM   #4
NinjaTrader_JoshG
NinjaTrader Customer Service
 
NinjaTrader_JoshG's Avatar
 
Join Date: Jun 2017
Location: Denver, CO
Posts: 547
Thanks: 16
Thanked 126 times in 122 posts
Default

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.
NinjaTrader_JoshG is offline  
Reply With Quote
Old 01-15-2018, 09:50 PM   #5
Deanmadar
Junior Member
 
Join Date: Dec 2017
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks Josh. Thats great info. I will try it and get back to you if I need further assistance.
Deanmadar is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Get the price at specific time billsingh Indicator Development 5 11-15-2015 09:16 PM
Enter at a specific time? rbrahy Strategy Development 3 03-06-2010 02:20 PM
Want to check if the computer clock time is less than a specific time mefTrader Platform Technical Support 1 01-21-2010 09:23 AM
How do I get the value of a bar at a specific time TraderFoo Strategy Development 5 06-23-2009 12:42 PM


All times are GMT -6. The time now is 01:55 AM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.