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 10-16-2007, 06:51 AM   #1
dendy
Member
 
Join Date: Jun 2007
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
Default Need to set a stop loss equal to indicator value...

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];
dendy is offline  
Reply With Quote
Old 10-16-2007, 06:56 AM   #2
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

How about:
Code:
SetTrailStop("", CalculationMode.Ticks, ATRStop(12)[0], false);
in the OnBarUpdate method?
NinjaTrader_Dierk is offline  
Reply With Quote
Old 10-16-2007, 08:12 AM   #3
dendy
Member
 
Join Date: Jun 2007
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
Default

I'll try this...

Thanks.
dendy 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
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


All times are GMT -6. The time now is 09:13 PM.