![]() |
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 |
|
Member
Join Date: Jun 2007
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
|
Hello,
Is it possible to set a stop loss or a trail stop equal to the output of an indicator. I'm trying to do this and in backtest, it does not work correctly. I'm trying to set the a Variable's value equal to the indicator and then set the stop loss equal to the Variable. This does not work as it always sets the trail stop equal to 1 tick. Does anyone know what method I would use in the Strategy builder or what code I may try? Thanks in advance, dendy. Code below: #region Variables // Wizard generated variables private int sMAFast = 6; // Default setting for SMAFast private int sMASlow = 12; // Default setting for SMASlow // User defined variables (add any user defined variables below) #endregion /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { SetTrailStop("", CalculationMode.Ticks, Variable1, false); CalculateOnBarClose = true; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // Condition set 1 if (SMA(SMAFast)[0] > SMA(SMAFast)[1] && SMA(SMASlow)[0] > SMA(SMASlow)[1] && VOLMA(12)[0] > VOLMA(12)[1] && ToTime(Time[0]) >= ToTime(13, 0, 0) && ToTime(Time[0]) <= ToTime(16, 10, 0)) { EnterLong(DefaultQuantity, ""); Variable1 = ATRStop(12)[0]; |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
How about:
Code:
SetTrailStop("", CalculationMode.Ticks, ATRStop(12)[0], false);
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Jun 2007
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
|
I'll try this...
Thanks. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Order Entry Property: Use stop market for stop loss orders | higler | SuperDOM and other Order Entry Windows | 7 | 07-02-2007 09:06 AM |
| I'm getting the stop loss error again... | funk101 | Strategy Development | 2 | 05-08-2007 11:30 PM |
| Stop Loss Orders activated by number of trades past stop level | DoveforUsAll | Suggestions And Feedback | 1 | 02-08-2006 01:19 AM |
| stop loss feature | QQQ | Suggestions And Feedback | 2 | 09-01-2005 12:04 AM |
| Stop Loss Size | JohnnyB | Suggestions And Feedback | 0 | 07-21-2005 04:04 AM |