![]() |
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
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Dec 2008
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
|
The "Indicator as described in Sylvain Vervoort's 'Average True Range Trailing Stops' June 2009 S&C article."
works great!! However I'm trying to add a second condition to it with a CrossAbove an EMA(period) indicator & I can't resolve the 'Unassigned Local variable' Error for the variable 'trail'. The standard ATR script runs just fine. What am I doing wrong? [CODE] { #region Variables privateint period = 20; privatedouble multi = 3.5; privatedouble trail = 1;//I tride to assign the variable here. #endregion ///<summary> protectedoverridevoid OnBarUpdate() { if (CurrentBar < 1) return; double trail; double loss = ATR(Input, Period)[0] * Multi; if (Close[0] > Value[1] && Close[1] > Value[1]) trail = Math.Max(Value[1], Close[0] - loss); ***if (CrossAbove(trail, EMA(period), 1)); //This is where I get the ERROR saying "Unassigned Local variable 'trail'
Last edited by KLG08; 04-06-2010 at 09:34 PM.
|
|
|
|
|
|
#2 | |
|
Certified NinjaScript Consultant
|
Quote:
Set Value before returning if(CurrentBar < 1) { Value.Set(something); return; } |
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ATR -Trailing Stops | PrTester | NinjaScript File Sharing Discussion | 36 | 12-03-2012 05:31 PM |
| Error on implementing ATR Trailing Stop | cowcool | Strategy Development | 5 | 06-01-2009 06:59 AM |
| ATR Trailing Stop | cowcool | ATM Strategies (Discretionary Trading) | 4 | 05-30-2009 10:24 AM |
| ATR Trailing Stop | BigDog008 | Strategy Development | 12 | 03-12-2009 10:20 AM |
| Using atr for variable Keltner Bands | latkinso | Strategy Development | 2 | 02-05-2008 06:46 AM |