NinjaTrader Support Forum  

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 09-09-2012, 01:59 PM   #1
Thomas79
Senior Member
 
Join Date: Apr 2009
Location: Paris
Posts: 147
Thanks: 11
Thanked 0 times in 0 posts
Send a message via MSN to Thomas79
Default SetStopLoss is not dynamic ?

Hi

i would like to move my setstoploss like a trailing stop... but it is not working, here my code, can you help to return my setstoploss dynamic ? the stop loss is not moving

if (here my buying condition)


{
EnterLongLimit(1, Close[0], "divergence haussiere 1");

SetStopLoss(
"divergence haussiere 1", CalculationMode.Price, Low[1] - 1*TickSize, false);

SetProfitTarget (
"divergence haussiere 1", CalculationMode.Ticks, 200*ATR(atr)[0]);

}



if (Position.MarketPosition == MarketPosition.Long && High[0] >= (Position.AvgPrice + 200*ATR(atr)[0] - 2*TickSize))


{
// Modifies stop-loss to breakeven + 2TickSize
ExitLongStop(0, true, 1, Position.AvgPrice+2*TickSize, "Trailing Stop div haussiere 1", "divergence haussiere 1");

}
Thomas79 is offline  
Reply With Quote
Old 09-09-2012, 05:09 PM   #2
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

Thomas,

From my understanding of your code, your stop loss would only be set if your buying conditions are set. You would need to update the stop loss if you are in a position here.

Here is a reference sample you may find helpful : http://www.ninjatrader.com/support/f...ead.php?t=3222
NinjaTrader_AdamP is offline  
Reply With Quote
Old 09-10-2012, 02:06 PM   #3
Thomas79
Senior Member
 
Join Date: Apr 2009
Location: Paris
Posts: 147
Thanks: 11
Thanked 0 times in 0 posts
Send a message via MSN to Thomas79
Default

Hi Adam_P

thx for your reply, i read your reference, i did it but it doesn't like when i call on the Initialies() these Set orders:

protectedoverridevoid Initialize()
{
CalculateOnBarClose =
true;

Add(RSI(14, 3));
Add (ATR(10));

SetStopLoss(CalculationMode.Price, Low[
1] - TickSize);
SetProfitTarget (CalculationMode.Ticks,
2*ATR(10)[0]);

}

I mean when i remove the "- TickSize" from the SetStopLoss and the "2*ATR(10)[0]" from the SetProfit and i replace for example by 40 (like 40 Ticks) that works... but i would like to call the stop Low[1]-TickSize and call the value of the ATR indicator as a tick value target...

can you help ?
Thomas79 is offline  
Reply With Quote
Old 09-10-2012, 02:11 PM   #4
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

Thomas,

The Initialize() section is where you set an initial stop based usually on some static value, indicator calculations aren't available there yet. You would want to call both of these in your OnBarUpdate() method instead.

Perhaps something like :

if ( Position.MarketPosition == MarketPosition.Long)
{
SetStopLoss(CalculationMode.Price, Low[1] - TickSize);
SetProfitTarget (CalculationMode.Ticks, 2*ATR(10)[0]);
}
NinjaTrader_AdamP is offline  
Reply With Quote
Old 09-11-2012, 01:21 PM   #5
Thomas79
Senior Member
 
Join Date: Apr 2009
Location: Paris
Posts: 147
Thanks: 11
Thanked 0 times in 0 posts
Send a message via MSN to Thomas79
Default

Hi Adam_P

It is not working by this way... it is a pity than we have to initialise a static stop loss to move it them with new condition...

by the way, i find the solution with the iorder and the Iexecution... but this is a lot of script for a small stop move....

anyway, thank Adam !
Thomas79 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
SetStopLoss ScottB Strategy Development 4 02-27-2011 03:03 PM
How to See the Value of SetStopLoss NinexTim Automated Trading 7 08-04-2010 06:38 AM
SetStopLoss() with dynamic SL-offset doesn't trigger poseidon_sthlm Strategy Development 10 06-23-2010 08:55 AM
SetStopLoss 4blue Strategy Development 2 01-03-2010 12:49 AM
SetStopLoss thepcmd Strategy Development 2 12-01-2007 01:14 PM


All times are GMT -6. The time now is 11:12 PM.