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 07-17-2008, 09:19 PM   #1
moon_rainz
Junior Member
 
Join Date: Jul 2008
Posts: 16
Thanks: 0
Thanked 0 times in 0 posts
Default ATR based Stop Loss

I am trying to have a ATR based stop loss. For example, if I entered a long EURUSD position at 1.5600 at close of bar, and ATR(14) at close of bar is 0.0020, my static stop loss will be 1.5600 - 0.0020 = 1.5580.

Under Initialize(), I included the following:

SetStopLoss("", CalculationMode.Ticks, ATR(14)[0], false);

However, when I tried to run the strategy, the log says:

"Failed to call method "Initialize for strategy 'SimpleMACross': ATR[barsAgo]: barsAgo out of valid range 0 through -2, was 0.


I would appreciate any advice.
moon_rainz is offline  
Reply With Quote
Old 07-17-2008, 10:14 PM   #2
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

a) please make sure there is historical data available for the instrument you backtest by e.g. pulling up a chart while connected.
b) try moving your SetStopLoss statement to the OnBarUpdate method
NinjaTrader_Dierk is offline  
Reply With Quote
Old 07-17-2008, 11:42 PM   #3
moon_rainz
Junior Member
 
Join Date: Jul 2008
Posts: 16
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi Dierk,

Thanks. Your statement (b) works.

Here's my sample for readers facing the same problem:

if (CrossAbove(EMA(14), EMA(24), 1))
{
EnterLong(1, "");
SetStopLoss("", CalculationMode.Price, Close[0]-ATR(14)[0], false);
}
moon_rainz 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
Recalculating position size based on account size, % risked and stop loss clivehunt Strategy Development 18 03-22-2009 11:25 AM
stop loss, trailing stop modification in NT6 alfie Strategy Development 1 03-26-2008 03:46 PM
Create a parked STOP order with simple stop loss skynetman Strategy Development 3 03-14-2008 12:36 AM
Order Entry Property: Use stop market for stop loss orders higler SuperDOM and other Order Entry Windows 7 07-02-2007 09:06 AM
Stop Loss Orders activated by number of trades past stop level DoveforUsAll Suggestions And Feedback 1 02-08-2006 01:19 AM


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