![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Dec 2008
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Dwayne,
You can use if (BarsSinceExit() > 5) for instance to prevent reentry.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Dec 2008
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
|
Thanks Josh! I owe you a Super Grande Dr. Pepper next time I see you. Thanks for the info.
|
|
|
|
|
|
#4 |
|
Junior Member
Join Date: Dec 2008
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
|
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? |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Dec 2008
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
|
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? |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |