![]() |
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 |
|
Junior Member
Join Date: Jul 2008
Posts: 16
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
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
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Jul 2008
Posts: 16
Thanks: 0
Thanked 0 times in 0 posts
|
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); } |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |