NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

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

Reply
 
Thread Tools Display Modes
Old 05-15-2012, 02:09 PM   #1
arbuthnot
Senior Member
 
Join Date: Feb 2012
Posts: 178
Thanks: 42
Thanked 13 times in 11 posts
Default SetTrailStop with EnterLongStopLimit

Hi Guys

I've tried adding a trailing stop (by placing SetTrailStop in the Initialize method) to orders placed by EnterLongStopLimit - but it doesn't seem to work.

I know this works fine with EnterLong but maybe, for whatever reason, it isn't possible with stop and limit orders.

Thanks very much in advance for any advice you may have.
arbuthnot is offline  
Reply With Quote
Old 05-15-2012, 02:23 PM   #2
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

arbuthnot,

I am happy to assist you.

Could you perhaps post more of your code here?
NinjaTrader_AdamP is offline  
Reply With Quote
Old 05-16-2012, 11:35 AM   #3
arbuthnot
Senior Member
 
Join Date: Feb 2012
Posts: 178
Thanks: 42
Thanked 13 times in 11 posts
Default

Adam - firstly, that was a superb webinar you gave just now. Thanks very much.

The instrument is ^DJIA where 1 Dow point = 100 'Ninja' ticks.

You asked me to post some code. The order entry coding below was supplied by Joydeep and works great. However, the trailing stop in the Initialize method that I entered myself doesn't seem to have any effect.

Can trails (or just stop losses) be added to EnterLongStopLimit orders?

Thanks for letting me know and if this is possible, maybe you could show me where I've gone wrong.

---

protected override void Initialize()
{
SetTrailStop("", CalculationMode.Ticks, 1000, false);
CalculateOnBarClose = true;
}

Conditions

{
EnterLongStopLimit(0, true, 1, Close[0] + LIMITa * TickSize, Close[0] + STOPa * TickSize, "BuyStop");
}

Conditions


{
EnterShortStopLimit(0, true, 1, Close[0] - LIMITa * TickSize, Close[0] - STOPa * TickSize, "SellStop");
}
arbuthnot is offline  
Reply With Quote
Old 05-16-2012, 11:44 AM   #4
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

arbuthnot,

Thank you for the feedback, it was a good opportunity there. We do those webinars bi-weekly so you can check it out again 2 weeks from yesterday, a Tuesday at 5:00 PM EST. There is also a video in our youtube channel on NinjaScript coding.

http://www.youtube.com/watch?v=JZpo01eSO9c

It looks like you are giving your orders a signal name, but not assigning the same name in the SetTrailStop() method.

The "fromEntrySignal" below :

SetTrailStop(string fromEntrySignal, CalculationMode mode, double value, bool simulated)

Must match the "signalName" below :

EnterLongStopLimit(int quantity, double limitPrice, double stopPrice, string signalName)

Please let me know if I may assist further.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 05-16-2012, 12:56 PM   #5
arbuthnot
Senior Member
 
Join Date: Feb 2012
Posts: 178
Thanks: 42
Thanked 13 times in 11 posts
Default

That works perfectly. I really should have seen that. I've sent myself to the bottom of the class!

I'll realize the importance of the signal names for future reference.

Ref your webinar,you mentioned it would be possible to set up SMS alerts. Could you kindly indicate how this could be done? (By the way, I'm in the UK and I'm wondering if these would work on the networks here.) Thanks again.
arbuthnot is offline  
Reply With Quote
Old 05-16-2012, 01:22 PM   #6
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

arbuthnot,

No worries. Getting the hang of everything can take a little while, which is why we have a NinjaScript team--for education. I believe sending a SMS in the UK would be the same as long as your cellular provider offers it, please find a link below describing how to do it.

http://20somethingfinance.com/how-to...mail-for-free/

You can test it from your own email address and see if it works.

Please let me know if I may assist further.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 05-16-2012, 01:43 PM   #7
arbuthnot
Senior Member
 
Join Date: Feb 2012
Posts: 178
Thanks: 42
Thanked 13 times in 11 posts
Default

Thanks again and for that link re SMS.

If I can take advantage just one more time in this thread of your kind offer of assistance:

I use range bars, which are effectively untradeable at the open, as so many appear almost at once adjusting from the day before. Is there a way, in backtesting, to exclude, say,the first half-hour of every trading day? I'm sure it may well be but I can't quite figure it out.

Much obliged for your further help.
arbuthnot is offline  
Reply With Quote
Old 05-16-2012, 01:56 PM   #8
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

arbuthnot,

You could use a time filter or could keep track of the bars.

http://www.ninjatrader.com/support/h...rofsession.htm

Code:
if( Bars.FirstBarOfSession )
{
   time = DateTime.Now;
   time = time.AddMinutes(30);
}

if( ToTime(Time[0]) <= ToTime(time))
{
return;
}
Something like that may work for you.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 05-16-2012, 02:17 PM   #9
arbuthnot
Senior Member
 
Join Date: Feb 2012
Posts: 178
Thanks: 42
Thanked 13 times in 11 posts
Default

Thanks as always, Adam. I'm sure I'll be able to insert that in my strategy.

Much obliged.
arbuthnot is offline  
Reply With Quote
Old 03-19-2013, 12:09 PM   #10
arbuthnot
Senior Member
 
Join Date: Feb 2012
Posts: 178
Thanks: 42
Thanked 13 times in 11 posts
Default

Hi everyone

What I want to try to achieve is to exclude the first half-hour, say, of the session from a strategy.

I've been trying to apply the following code that Adam kindly supplied in this thread simply by pasting it into OnBarUpdate of a strategy :
Code:
if( Bars.FirstBarOfSession )
{    
time = DateTime.Now;
time = time.AddMinutes(30);
} 
if( ToTime(Time[0]) <= ToTime(time))
{
return;
}
However, it doesn't compile correctly. I've tried adding 'time' as a variable but it doesn't help.

Any further advice about this would be greatly appreciated.
arbuthnot is offline  
Reply With Quote
Old 03-19-2013, 12:35 PM   #11
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,218
Thanks: 24
Thanked 1,231 times in 1,002 posts
Send a message via Skype™ to koganam
Default

Quote:
Originally Posted by arbuthnot View Post
Hi everyone

What I want to try to achieve is to exclude the first half-hour, say, of the session from a strategy.

I've been trying to apply the following code that Adam kindly supplied in this thread simply by pasting it into OnBarUpdate of a strategy :
Code:
if( Bars.FirstBarOfSession )
{    
time = DateTime.Now;
time = time.AddMinutes(30);
} 
if( ToTime(Time[0]) <= ToTime(time))
{
return;
}
However, it doesn't compile correctly. I've tried adding 'time' as a variable but it doesn't help.

Any further advice about this would be greatly appreciated.
What is the error message when it does not compile?
koganam is offline  
Reply With Quote
Old 03-19-2013, 12:48 PM   #12
arbuthnot
Senior Member
 
Join Date: Feb 2012
Posts: 178
Thanks: 42
Thanked 13 times in 11 posts
Default

Quote:
What is the error message when it does not compile
Thanks for getting back to me on this, Koganam.

There is the same error message that comes up each time the term 'time' appears:

Quote:
The name 'time' does not exist in the current context
I've tried adding

Code:
int time = 0;
but this didn't help.

I get the impression that coding to deal with time issues is quite difficult unless you're a real C# expert.

Much obliged in advance for any advice on how to crack this.
arbuthnot is offline  
Reply With Quote
Old 03-19-2013, 12:53 PM   #13
NinjaTrader_Matthew
NinjaTrader Customer Service
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,786
Thanks: 160
Thanked 567 times in 558 posts
Default

The variable "time" needs to be a DateTime type

Code:
DateTime time;
This should allow you to set time to a DateTime object:

Code:
time = DateTime.Now;
NinjaTrader_Matthew is online now  
Reply With Quote
The following user says thank you to NinjaTrader_Matthew for this post:
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
SetTRailStop binwang2 General Programming 1 10-18-2010 01:53 AM
EnterLongStopLimit() / EnterShortStopLimit() Guides Jim-Boulder Miscellaneous Support 1 08-05-2010 02:57 PM
SetTrailStop stefy Strategy Development 3 07-21-2010 07:54 AM
SetTrailStop Help jvaughn General Programming 5 03-07-2009 08:14 PM
EnterLongStopLimit() and EnterShortStopOrder() ltemme Automated Trading 3 07-31-2008 10:37 PM


All times are GMT -6. The time now is 10:58 AM.