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-01-2009, 11:16 PM   #1
paschall
Junior Member
 
Join Date: Dec 2008
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
Default if Target Profit reached on previous bar, dont trade current bar

I have a strategy that is working nicely except for one situation. In a trend, I can get multiple signals during that trend. That's fine, but what I am trying to avoid is once my profit target is reached (and the positions is closed out), do not enter a new position on the VERY next bar. I want to force the strategy to wait X-number of bars before being ok to enter a long or short position again. What is the best way to approach this?

Thanks,
Dwayne
paschall is offline  
Reply With Quote
Old 09-02-2009, 07:25 AM   #2
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

Dwayne,

You can use if (BarsSinceExit() > 5) for instance to prevent reentry.
NinjaTrader_Josh is offline  
Reply With Quote
Old 09-02-2009, 08:10 AM   #3
paschall
Junior Member
 
Join Date: Dec 2008
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks Josh! I owe you a Super Grande Dr. Pepper next time I see you. Thanks for the info.
paschall is offline  
Reply With Quote
Old 09-02-2009, 10:08 PM   #4
paschall
Junior Member
 
Join Date: Dec 2008
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
Default

HI Josh,
The code you recommended is going to work, I think. Here's how I implemented it:

bool tradeallowed = false;
.
.
.
if (BarsSinceExit() > 2)
tradeallowed = true;
.
.
.
if(<several set up conditions> && tradeallowed) { execute trade}

However, when I start the strategy, it has obviously not exited ANY trades because I just turned it on, right? SO it will never satisfy the condition BarsSinceExit() > 0. But if I set the basic boolean condition to true, it will bypass the "dont trade again so soon" condition that I am trying to avoid.

Any suggestions on how to get the strategy going to first make a trade then do the update?
paschall is offline  
Reply With Quote
Old 09-02-2009, 10:34 PM   #5
paschall
Junior Member
 
Join Date: Dec 2008
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
Default

Glad the sun didn't rise before you read my last post! I think I figured it out. I'll post here for other people who have the same question.

Before you enter & exit the first trade, BarsSinceExit() == -1. So you just have to add an OR statement to the if() clause:

if (BarsSinceExit() == -1 || BarsSinceExit() > 2)
tradeallowed = true;

Then BOOM! See how your strategy now works?
paschall 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
Profit target depending on last bar MasterSepp General Programming 32 07-30-2009 05:31 AM
Current Bar Open Equals Previous Bar Close ramacan Charting 6 05-23-2009 11:07 AM
Target then Stop Reached in Same Bar RJay Strategy Development 1 05-07-2009 08:23 AM
High and Low of previous bar and actual bar Fernando Miscellaneous Support 1 03-18-2009 10:54 AM
Profit target reached, how to stop strategy? eb486 Automated Trading 3 06-05-2008 09:31 AM


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