![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Sep 2006
Location: Rome, , Italy
Posts: 131
Thanks: 2
Thanked 1 time in 1 post
|
Hello,
I'm testing a strategy and I've got a couple of questions: 1) Once in position, I'm looking to exit at the close of n bars since my entry bar. 2) I need to choose a different order, depending on the position of the next opening bar. Let's say, for example, that if the next bars opens in a gap up, I want to enter short at today's high and exit at the close of the bar. Could someone help me with the code? Thanks. |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
|
Hi MAX, for #1, you could use BarsSinceEntry(). For #2, you can specify which entry signal to look for with BarsSinceEntry():
Code:
// if the signal name you're looking for is "longEntry"
int barsSinceEntry = BarsSinceEntry("longEntry");
Austin
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Sep 2006
Location: Rome, , Italy
Posts: 131
Thanks: 2
Thanked 1 time in 1 post
|
For #2, maybe I wasn't so clear.
What I need to translate is: If open of next bars is higher than actual high, then sell next bar (stop) at actual high and close the position at the end of the bar. Hope this clarify. Thanks for your kind help. |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
|
Max, I'm not sure I follow. It would almost seem like the strategy you have envisioned "looks into the future". How would you sell at the high of the next bar? Anyways, unless you add intrabar granularity to your backtest, the backtester can't be told to buy and sell at the same bar.
If next bar means current bar and if actual means previous bar, then I think this code would do what you want: Code:
// this code is untested and incomplete
// currentbarentry is a bool
protected override void OnBarUpdate()
{
if (Open[0] > High[1])
{
EnterShortStop(High[1]);
currentbarentry = true;
}
if (currentbarentry == true)
{
currentbarentry = false;
ExitShort();
}
Austin
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Sep 2006
Location: Rome, , Italy
Posts: 131
Thanks: 2
Thanked 1 time in 1 post
|
Hi,
I still didn't test your code, although I don't want to look into the future, but at the present bar (doesn't matter the time frame). If, on the next bar, the open is in gap, I want to sell the market at this bar high in stop. So I already know which my entry level is (this bar high). I just need to tell the code : If open of next bar is higher than actual bar's high then sell at actual bar's high stop. I'm just giving an order based on my actual setup, depending on next opening. Hope this clear. Thanks. |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
|
Max, thanks for clarifying - then I would suggest testing out the sample code Austin did for you.
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| entry and exit | wes7763 | Strategy Development | 3 | 07-29-2009 04:13 PM |
| Entry and EXIT an SMA | Sailor | General Programming | 10 | 07-06-2009 10:13 AM |
| How to get the entry signal or bars array index for an open position | cunparis | Strategy Development | 4 | 12-24-2008 07:04 AM |
| Enter on bars, exit on ticks and min bars requirment | coolraz | Strategy Development | 3 | 12-15-2008 09:59 AM |
| It seems to take 2 bars to Exit a position and then enter in opposite direction | scjohn | Strategy Development | 1 | 11-06-2008 03:03 PM |