![]() |
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: May 2009
Posts: 23
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
cowcool, please try moving your Math.Ceiling calculations to the OnBarUpdate() section.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: May 2009
Posts: 23
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: May 2009
Posts: 23
Thanks: 0
Thanked 0 times in 0 posts
|
Tried to move all the variables to onbarupdate but got error (please see the attached image ) thx
|
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
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);
http://www.ninjatrader-support2.com/...ead.php?t=3222
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| 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 |
| 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 |