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 > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 09-11-2009, 12:43 PM   #1
561timw
Member
 
Join Date: Dec 2008
Posts: 33
Thanks: 0
Thanked 0 times in 0 posts
Default Stop Loss based on calculation

I want to set my stop loss based on a fixed calculation of 1 tick above the high of the day or 1 tick below the low. How do I do this? Can I use:[/font]

SetStopLoss("", CalculationMode.Ticks, CurrentDayOHL().CurrentHigh[1] + 5 , false);
561timw is offline  
Reply With Quote
Old 09-11-2009, 01:28 PM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

If you want to tell it an absolute price you should be using CalculationMode.Price and not .Ticks.

Also, you should not be doing a simple "+ 5". It should be "+ 5 * TickSize" to ensure accurate tick size values.

Finally, this line would only work in OnBarUpdate(). You cannot do this from Initialize().
NinjaTrader_Josh is offline  
Reply With Quote
Old 09-11-2009, 01:33 PM   #3
561timw
Member
 
Join Date: Dec 2008
Posts: 33
Thanks: 0
Thanked 0 times in 0 posts
Default

My concern about on bar update is that if I lose connection my stop will not activate is this a true concern?
561timw is offline  
Reply With Quote
Old 09-11-2009, 01:36 PM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

No matter where in your code you put the command it will not help you if you lose connection before the order was placed. All you have to do is call the Set() method before you do the Enter() method and it will be placed. Depending on the brokerage technology you are connected with will determine whether or not that order is actually sitting at the exchange or still on your local PC. See this article for more information: http://www.ninjatrader-support2.com/...ead.php?t=5349
NinjaTrader_Josh is offline  
Reply With Quote
Old 09-11-2009, 01:47 PM   #5
561timw
Member
 
Join Date: Dec 2008
Posts: 33
Thanks: 0
Thanked 0 times in 0 posts
Default

I use IB and based on the link you provided orders are sitting on their server. So is it correct that when my program triggers my entry my stop of 1 tick below the low or above the high will be calculated and simultaneously transmitted to IB even if using the on bar update?

You also said:

"All you have to do is call the Set() method before you do the Enter() method and it will be placed"

Can you explain with a sample. I am not following.
561timw is offline  
Reply With Quote
Old 09-11-2009, 02:12 PM   #6
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

That is correct. Just call Set() before you call Enter(). When the code evaluates an Enter() and gets you into a position, the Set() will be activated exactly the same as if it were in Initialize().
NinjaTrader_Josh is offline  
Reply With Quote
Old 09-11-2009, 02:17 PM   #7
561timw
Member
 
Join Date: Dec 2008
Posts: 33
Thanks: 0
Thanked 0 times in 0 posts
Default

One last question:

How do I create a copy of a ninja script once outside of the wizard. I have created a copy in the wizard by just changing the name but cannot figure out how to do it outside the wizard.

Thanks for all your help
561timw is offline  
Reply With Quote
Old 09-11-2009, 02:21 PM   #8
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

You can go to Edit NinjaScript -> select your file and open it in the NinjaScript Editor. From there just right click and select Save As.
NinjaTrader_Josh 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
Move Stop Loss Based On Last Candle r2kTrader Strategy Development 16 06-12-2009 07:25 AM
Recalculating position size based on account size, % risked and stop loss clivehunt Strategy Development 18 03-22-2009 11:25 AM
How do I set stop loss based on low of setup bar? ninjablanks General Programming 1 12-12-2008 07:12 AM
ATR based Stop Loss moon_rainz Strategy Development 2 07-17-2008 11:42 PM
Alternative to tick based/bar based strategy calculation? (i.e every minute/X ticks) Elliott Wave Strategy Development 9 07-11-2008 03:11 AM


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