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 06-10-2008, 04:04 PM   #1
ssierra
Member
 
Join Date: Jan 2008
Posts: 96
Thanks: 0
Thanked 0 times in 0 posts
Default Profit Target and Stop loss change the number of trades


Hi I have a strategy that I am testing that is always in the market. Now I have added some stop loss and profit targets conditions and I have realized that the number of trades changes based on them. How can this be possible?

Assume that if it’s flat the enter condition is the same that if it is on market and it is changing the direction.

Thanks
Last edited by ssierra; 06-10-2008 at 04:08 PM.
ssierra is offline  
Reply With Quote
Old 06-10-2008, 04:21 PM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Your strategy does what you tell it to do...You will have to debug to understand how the changes you have made impact your strategy.
NinjaTrader_Ray is offline  
Reply With Quote
Old 06-10-2008, 05:06 PM   #3
ssierra
Member
 
Join Date: Jan 2008
Posts: 96
Thanks: 0
Thanked 0 times in 0 posts
Default

Ok but I don’t see any problem. As example I took your SampleMACrossOver strategy and added a stop and a target. As it is it works fine, whatever the stop and targets are the number of trades is the same. But if I want to have a crossover with a the MA delayed is where I get problems.
The code is as follows:

{
if (CrossAbove(SMA(Fast), SMA(Fast)[2], 1))
EnterLong();
elseif (CrossBelow(SMA(Fast), SMA(Fast)[2], 1))
EnterShort();
}


And the original is:

{
if (CrossAbove(SMA(Fast), SMA(Slow), 1))
EnterLong();
elseif (CrossBelow(SMA(Fast), SMA(Slow), 1))
EnterShort();
}

What is wrong for changing the number of trades?

Edited with message 4.
Last edited by ssierra; 06-11-2008 at 01:38 AM.
ssierra is offline  
Reply With Quote
Old 06-11-2008, 01:32 AM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

The code you modified it to will definitely produce different results. The original code makes little sense in logical terms because you are asking for when the SMA(Fast) crosses over itself. In your modified code you are asking when the SMA(Fast) crosses the SMA(Fast) of 2 bars ago. This makes more sense and it will behave accordingly.
NinjaTrader_Josh is offline  
Reply With Quote
Old 06-11-2008, 01:37 AM   #5
ssierra
Member
 
Join Date: Jan 2008
Posts: 96
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks Johs,

sorry the original code is this one:

{
if
(CrossAbove(SMA(Fast), SMA(Slow), 1))
EnterLong();
elseif (CrossBelow(SMA(Fast), SMA(Slow), 1))
EnterShort();

That is as it is in the example and gives the same number of trades whatever the stop is. What is giving me problemes is the one that crossover a delayed media and based on your comment it is fine.

Thanks,
ssierra is offline  
Reply With Quote
Old 06-11-2008, 03:26 AM   #6
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

How are you determining what you are seeing is abnormal? You cannot compare the two situations since they are not equivalent. They will definitely produce different trades.
NinjaTrader_Josh is offline  
Reply With Quote
Old 06-11-2008, 04:27 AM   #7
ssierra
Member
 
Join Date: Jan 2008
Posts: 96
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by Josh View Post
How are you determining what you are seeing is abnormal? You cannot compare the two situations since they are not equivalent. They will definitely produce different trades.
No I am not saying that. Sorry if I dint explained myself properly.

Using the original code if I optimize the stops and targets whatever the parameters are the numbers of trades are always the same, as expected.

The problem is that with the new code optimizing the stops and targets gives different number of trades that doesn’t make sense.

I am not comparing the number of trades with the original code I am comparing the number of trades of the same strategy using different stops and targets.

Many thanks for the help
ssierra is offline  
Reply With Quote
Old 12-16-2010, 07:26 PM   #8
marcos_vitorino
Junior Member
 
Join Date: Dec 2010
Location: New Jersey - USA
Posts: 1
Thanks: 0
Thanked 0 times in 0 posts
Send a message via MSN to marcos_vitorino Send a message via Skype™ to marcos_vitorino
Default Stop Position

I wonder if something's wrong wiht this commands or if have another commands that I can close all open orders ...



if (CrossBelow(Momentum(momentumPeriod), 0, 1))
ExitShortStop(Position.MarketPosition,
"", "");


the goal is when the period line crossesover the 0 line close all orders...

Thank you.
marcos_vitorino is offline  
Reply With Quote
Old 12-17-2010, 04:32 AM   #9
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

Welcome to our forums here marcos_vitorino, your command would issue a Stop Market order, if you just want to exit the quickest way possible on your condition just call ExitShort() for a straight market order.

http://www.ninjatrader.com/support/h.../exitshort.htm
NinjaTrader_Bertrand 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
Strategy: Monitoring Stop-Loss and Profit Target Orders NinjaTrader_Josh Reference Samples 0 02-23-2008 11:15 PM
Profit Target and Stop Loss not honored pjwinner Strategy Analyzer 6 11-30-2007 09:45 AM
Stop Loss - profit target settings deanldavis475 Miscellaneous Support 1 11-26-2007 07:31 AM
Default stop loss and profit target as GTC equitydealer General Programming 4 06-18-2007 11:31 PM
Stop Loss Orders activated by number of trades past stop level DoveforUsAll Suggestions And Feedback 1 02-08-2006 01:19 AM


All times are GMT -6. The time now is 02:48 AM.