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 07-26-2010, 10:31 AM   #1
mefTrader
Senior Member
 
Join Date: Nov 2009
Posts: 205
Thanks: 0
Thanked 0 times in 0 posts
Default ExitLongStop not working

I have an initial StopLoss

protected override void Initialize()
{
CalculateOnBarClose = true;
Add(PeriodType.Minute, 5);
SetStopLoss(450);
MP = new DataSeries(this);
TT = new DataSeries(this);
PosLow = new DataSeries(this);
}

and I have a trailing stop (highlighted in orange) but the Trailing Stop does not work? Cant figure out why?

// ///////////////////////
// Trailing Stop Long
// ///////////////////////

if (Position.MarketPosition == MarketPosition.Long)
{
MyATRCalc = ATR(14)[0]*atr5min_trail_mult_long;
if ((TT[0] != TT[1]) || (MP[1] != 1))
{
PosLow[0] = Low[0] - MyATRCalc;
}
PosLow[0] = Math.Max(PosLow[1], (Low[0]-MyATRCalc));
DrawDot("TStop_Long"+ CurrentBar, true, 0, PosLow[0], Color.Orange);

}
ExitLongStop(PosLow[0]);
Attached Images
File Type: jpg ATR_TrailingStop.jpg (77.3 KB, 12 views)
mefTrader is offline  
Reply With Quote
Old 07-26-2010, 10:32 AM   #2
mefTrader
Senior Member
 
Join Date: Nov 2009
Posts: 205
Thanks: 0
Thanked 0 times in 0 posts
Default

Seems to be getting stopped out by the StopLoss and not by the Trailing Stop (orange dots)?
mefTrader is offline  
Reply With Quote
Old 07-26-2010, 12:11 PM   #3
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
Default

mefTrader, please work with TraceOrders = true in your Initialize() to debug your order behavior, likely you're running into the Internal Order Handling Rules here -

http://www.ninjatrader-support.com/H...verview36.html (botton section).

http://www.ninjatrader.com/support/f...ead.php?t=3627
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 07-27-2010, 06:52 AM   #4
mefTrader
Senior Member
 
Join Date: Nov 2009
Posts: 205
Thanks: 0
Thanked 0 times in 0 posts
Default Why cant a StopLoss and ExitLong not exist as 2 seperate stops

Methods that generate orders to exit a position will be ignored if a strategy position is open and:
  • An order submitted by an enter method (EnterLongLimit() for example) is active and this entry order is used to open a position in the opposite direction
  • An order submitted by a set method (SetStopLoss() for example) is active


I am trying to use an ExitLong in parallel with a StopLoss... I am bring ing code over from Tradestation where this worked and I dont understand why these could not co-exist?


The stop that is closer to the price action should be active - strategy calculations should know this ahead if there is a clear distinction??


Whats the workaround here?
mefTrader is offline  
Reply With Quote
Old 07-27-2010, 07:09 AM   #5
mefTrader
Senior Member
 
Join Date: Nov 2009
Posts: 205
Thanks: 0
Thanked 0 times in 0 posts
Default

How can I integrate a Currency StopLoss and a Price Stop into StopLoss() ? Any examples out there?
mefTrader is offline  
Reply With Quote
Old 07-27-2010, 07:14 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
Default

mefTrader, the order handling rules are there to protect you and your strategy of unwanted positions / inflight executions - thus if the SetStopLoss is active other Exit's will be ignored.

You could work here by adjusting the price level of your stop order as needed.

Unfortunately you can't have a currency and price based stop running on the same position with SetStopLoss().

With NinjaTrader 7 we also offer a new unmanaged order submission mode, which gives you the freedom to manage / code all on your own and 'neutralizing' the order entry rules discussed.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 07-27-2010, 07:19 AM   #7
mefTrader
Senior Member
 
Join Date: Nov 2009
Posts: 205
Thanks: 0
Thanked 0 times in 0 posts
Default

ok how do I get more information about "a new unmanaged order submission mode, which gives you the freedom to manage / code all on your own and 'neutralizing' the order entry rules discussed." ?
mefTrader is offline  
Reply With Quote
Old 07-27-2010, 07:35 AM   #8
mefTrader
Senior Member
 
Join Date: Nov 2009
Posts: 205
Thanks: 0
Thanked 0 times in 0 posts
Default

ok read http://www.ninjatrader.com/support/h...d_approach.htm

Sounds like using a sledgehammer to something that should be available a SetStopLoss() to work in parallel to TrailingStop() . Since NT7 ins still in beta could this be addressed? (wrt to below)??


The SetStopLoss() method can NOT be used concurrently with the SetTrailStop() method for the same position, if both methods are called for the same position (fromEntrySignal) the SetStopLoss() will always take precedence. You can however, use both methods in the same strategy if they reference different signal names.
mefTrader is offline  
Reply With Quote
Old 07-27-2010, 08:05 AM   #9
mefTrader
Senior Member
 
Join Date: Nov 2009
Posts: 205
Thanks: 0
Thanked 0 times in 0 posts
Default

Ok this works folks for future reference


// ///////////////////////
// Trailing Stop Long
// ///////////////////////
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(450);
}

if (Position.MarketPosition == MarketPosition.Long)
{
MyATRCalc = ATR(14)[0]*atr5min_trail_mult_long;
if ((TT[0] != TT[1]) || (MP[1] != 1))
{
PosLow[0] = Low[0] - MyATRCalc;
}
PosLow[0] = Math.Max(PosLow[1], (Low[0]-MyATRCalc));
DrawDot("TStop_Long"+ CurrentBar, true, 0, PosLow[0], Color.Orange);
if ((Position.AvgPrice - PosLow[0]) * 10 < 450)
{
SetStopLoss(CalculationMode.Price, PosLow[0]);
}
}
mefTrader is offline  
Reply With Quote
Old 07-27-2010, 08:27 AM   #10
mefTrader
Senior Member
 
Join Date: Nov 2009
Posts: 205
Thanks: 0
Thanked 0 times in 0 posts
Default

*10 multiplier is because I am tradin the Russell (@TF)
mefTrader 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
ExitLongStop madhav_ab Strategy Development 1 05-22-2010 05:25 AM
ExitLongStop and ExitShortStop not working properly suresh Strategy Development 2 05-14-2010 11:09 PM
Confusion about ExitLongStop() AnotherTrader Automated Trading 6 04-27-2010 10:19 AM
ExitLongStop() getting cancelled cheeky123 Strategy Development 5 09-18-2009 04:26 AM
ExitLongStop not executed! sammano Strategy Development 5 11-23-2008 01:08 PM


All times are GMT -6. The time now is 03:26 PM.