![]() |
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
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Feb 2012
Posts: 178
Thanks: 42
Thanked 13 times in 11 posts
|
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. |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
arbuthnot,
I am happy to assist you. Could you perhaps post more of your code here?
Adam P.
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Feb 2012
Posts: 178
Thanks: 42
Thanked 13 times in 11 posts
|
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"); } |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
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.
Adam P.
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Feb 2012
Posts: 178
Thanks: 42
Thanked 13 times in 11 posts
|
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. |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
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.
Adam P.
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Feb 2012
Posts: 178
Thanks: 42
Thanked 13 times in 11 posts
|
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. |
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
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;
}
Adam P.
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Feb 2012
Posts: 178
Thanks: 42
Thanked 13 times in 11 posts
|
Thanks as always, Adam. I'm sure I'll be able to insert that in my strategy.
Much obliged. |
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Feb 2012
Posts: 178
Thanks: 42
Thanked 13 times in 11 posts
|
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;
}
Any further advice about this would be greatly appreciated. |
|
|
|
|
|
#11 | |
|
Senior Member
|
Quote:
|
|
|
|
|
|
|
#12 | ||
|
Senior Member
Join Date: Feb 2012
Posts: 178
Thanks: 42
Thanked 13 times in 11 posts
|
Quote:
There is the same error message that comes up each time the term 'time' appears: Quote:
Code:
int time = 0; 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. |
||
|
|
|
|
|
#13 |
|
NinjaTrader Customer Service
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,786
Thanks: 160
Thanked 567 times in 558 posts
|
The variable "time" needs to be a DateTime type
Code:
DateTime time; Code:
time = DateTime.Now;
Matthew
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_Matthew for this post: |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |