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 06-01-2009, 04:53 AM   #1
cowcool
Junior Member
 
Join Date: May 2009
Posts: 23
Thanks: 0
Thanked 0 times in 0 posts
Default Error on implementing ATR Trailing Stop

Here is the code (attached). Where did I make mistake ... argggh .... and I am new to this ..... help please

Basically, I want ATR Trailing stop with size of 2 times ATR
Attached Images
File Type: jpg dmi3.jpg (66.7 KB, 18 views)
cowcool is offline  
Reply With Quote
Old 06-01-2009, 05:33 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

cowcool, please try moving your Math.Ceiling calculations to the OnBarUpdate() section.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 06-01-2009, 05:48 AM   #3
cowcool
Junior Member
 
Join Date: May 2009
Posts: 23
Thanks: 0
Thanked 0 times in 0 posts
Default

Thx but the problem is if it is moved to onBarUpdate, the ATR value is constantly changing. I want it to be static , i.e. the ATR value just before a trade is entered.

Quote:
Originally Posted by NinjaTrader_Bertrand View Post
cowcool, please try moving your Math.Ceiling calculations to the OnBarUpdate() section.
cowcool is offline  
Reply With Quote
Old 06-01-2009, 05:57 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

Well, then set this variable with the ATR value at the point your trade entry triggers, then it's using this value forward as stop amount.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 06-01-2009, 06:44 AM   #5
cowcool
Junior Member
 
Join Date: May 2009
Posts: 23
Thanks: 0
Thanked 0 times in 0 posts
Default

Tried to move all the variables to onbarupdate but got error (please see the attached image ) thx


Quote:
Originally Posted by NinjaTrader_Bertrand View Post
Well, then set this variable with the ATR value at the point your trade entry triggers, then it's using this value forward as stop amount.
Attached Images
File Type: jpg dmi4.jpg (61.7 KB, 15 views)
cowcool is offline  
Reply With Quote
Old 06-01-2009, 06:59 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

This is most likely because you miss the matching curly bracket to end the OnBarUpdate(). However, you can leave the Variables declaration where you had them previously. Then just set the value for your stop amount when your trade triggers -

Code:
 
if (Close[0] > Close[5])
{
EnterLong(1, "");
myStopValue = Close[0] - 2 * ATR(10)[0];
}

if (Position.MarketPosition == MarketPosition.Long)
SetStopLoss(CalculationMode.Price, myStopValue);
You can also check into this reference sample -

http://www.ninjatrader-support2.com/...ead.php?t=3222
NinjaTrader_Bertrand 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
ATR -Trailing Stops PrTester NinjaScript File Sharing Discussion 36 12-03-2012 05:31 PM
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
ATM ATR Trailing stop net01 ATM Strategies (Discretionary Trading) 1 10-23-2008 10:34 AM
ATR Stop ATI user Strategy Development 8 09-29-2008 10:12 AM


All times are GMT -6. The time now is 10:50 PM.