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 08-19-2012, 10:55 PM   #1
comfy
Junior Member
 
Join Date: May 2011
Posts: 6
Thanks: 1
Thanked 0 times in 0 posts
Unhappy How do you create such a stop & exit?

Hi,

For a long position that I've entered,

I need to know how to create a stop for : (1 x ATR) - low of entry bar

and

Target exit : (2 x ATR) + entry price or Market on Close (MOC), whichever comes first.

If stop is 2 x ATR or more under the entry price, the setup should be ignored until the next opportunity comes along.

Can anyone help me with this?
comfy is offline  
Reply With Quote
Old 08-19-2012, 11:34 PM   #2
NinjaTrader_Matthew
NinjaTrader Customer Service
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,781
Thanks: 159
Thanked 565 times in 556 posts
Default

Hello,

You can store these bar values in a double, and then use that double as the price level for your stop and your profit target:

Code:
			double stop1 = Low[0] - ATR(14)[0];
			double target1 = Position.AvgPrice + (ATR(14)[0] * 2);
						
			SetStopLoss(stop1);
			SetProfitTarget(target1);
Please let me know if you have additional questions.
NinjaTrader_Matthew is offline  
Reply With Quote
The following 2 users say thank you to NinjaTrader_Matthew for this post:
Old 08-20-2012, 01:41 AM   #3
comfy
Junior Member
 
Join Date: May 2011
Posts: 6
Thanks: 1
Thanked 0 times in 0 posts
Default

Thanks for the swift reply, really appreciate it.

However, I noticed for this line :

Code:
double target1 = Position.AvgPrice + (ATR(14)[0] * 2);
It is based on average price and not on entry price? I am bad at programming so I'm rather just assuming based on the terms used. Also, how do I add in an additional condition where if Low[0] - ATR(14)[0] is lower than 2 x ATR(14)[0], then the trade should be ignored. Is there a way to do that?

By the way, this code written here, is this done via editing the code of a strategy directly or can it be built with the condition builder when creating a strategy?

Thank you very much for taking the time to help me, really appreciate it (:
Last edited by comfy; 08-20-2012 at 01:47 AM.
comfy is offline  
Reply With Quote
Old 08-20-2012, 06:08 AM   #4
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

Hello comfy,
It might not be possible to do it via the strategy wizard and you have to do it by further coding it via the NinjaScript Editor.
NinjaTrader_Joydeep 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
2 things: Opposing Stop entries & Trade entry/exit info displayed on chart... Barefoot Hank Charting 2 09-22-2011 06:24 AM
Stop Loss & Target Exit & winning strategies johnbastawros Strategy Development 1 03-16-2011 03:50 PM
Partial Exit - named signal exit stop not updated MicroTrends Strategy Development 5 02-08-2011 10:17 AM
Create a parked STOP order with simple stop loss skynetman Strategy Development 3 03-14-2008 12:36 AM
Stop Loss & Managed Exit fire together CashCache Strategy Development 11 01-18-2008 10:39 AM


All times are GMT -6. The time now is 12:37 PM.