Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Cover position on Close of the bar
Collapse
X
-
Tags: None
-
It is for a code-based strategy. Calculated on bar close is true. I want to open position on monday on market open and close on friday on market close using daily bars only.
That's code for open position. But I can't find how to close on the close of the bar.if (Time[0].DayOfWeek == DayOfWeek.Friday)
{
{
EnterLong(BarsInProgress,200,Instruments[BarsInProgress].FullName + " long");
}
}
Comment
-
nysetrader,
You can use something like :
if ( BarsSinceEntry() == 1)
{
ExitLong();
}
If you are using a multi series indicator here you may need to filter by bars in progress as well.
Last edited by NinjaTrader_AdamP; 04-16-2012, 11:48 AM.Adam P.NinjaTrader Customer Service
Comment
-
-
nysetrader,
So you want an order to exist for a whole bar, then close?Last edited by NinjaTrader_AdamP; 04-16-2012, 11:41 AM.Adam P.NinjaTrader Customer Service
Comment
-
It doesn't work
I've used this. With the previous code the position was opened on Monday Open, then it skips 3 days and cover on the open of fourth day(Friday), but I need to cover on close!if (BarsSinceEntry(BarsInProgress,Instruments[BarsInProgress].FullName + " long", 0) == 3)
{
ExitLong(BarsInProgress,200,Instruments[BarsInProgress].FullName + " position covered on " + Time[0].DayOfWeek.ToString(),Instruments[BarsInProgress].FullName + " long");
}Last edited by nysetrader; 04-16-2012, 10:03 AM.
Comment
-
-
nysetrader,
I guess I am not sure what you are doing here. Is this strategy on a daily chart?
I am not sure what you mean here. The previous code looks like it should open a position on Friday. Also, you are using the BarsInProgress item. Did you add a second data series here? Could you possible post your Initialize() section?With the previous code the position was opened on Monday Open, then it skips 3 days and cover on the open of fourth day(Friday),Adam P.NinjaTrader Customer Service
Comment
-
The strategy is on daily chart. I add daily dataseries for 500 symbols of s&p500 in my init section.
This code
calculated on friday bar close, so position opens on Monday bar open.if (Time[0].DayOfWeek == DayOfWeek.Friday)
{
{
EnterLong(BarsInProgress,200,Instruments[BarsInProgress].FullName + " long");
}
}
Comment
-
nyse,
You don't need the double brackets here.
Also, since BarsInProgress is being called for 500 symbols, if you did indeed add 500 symbols, is your strategy designed to enter 500 orders one for each symbol?
Without filtering for BarsInProgress you may have some strange behaviors here.Adam P.NinjaTrader Customer Service
Comment
-
There is no strange behavior actually. It enters one order for each symbol. But the problem is that I need to use bar close price to cover the position!Last edited by nysetrader; 04-16-2012, 11:42 AM.
Comment
-
Nysetrader,
Please find a simple example of something that does what you ask for below :
With the calculate on bar close setting, it would wait one bar before the exit is called.Code:public class Example : Strategy { #region Variables // Wizard generated variables // User defined variables (add any user defined variables below) #endregion /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { CalculateOnBarClose = true; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // Condition set 1 if (Close[0] >= Open[0]) { EnterLong(DefaultQuantity, ""); } // Condition set 2 if (BarsSinceEntry() == 0) { ExitLong("", ""); } } #region Properties #endregion }Last edited by NinjaTrader_AdamP; 04-16-2012, 11:47 AM.Adam P.NinjaTrader Customer Service
Comment
-
-
Nyse,
Apologies, I think I am misunderstanding your needs here. Please verify this is what you want so I may construct an appropriate response.
1. Enter on one bar on a Friday, using a daily chart.
2. Exit at the CLOSE price of the next bar.
You do not want to exit at the next bar, you want to exit at the CLOSE of the next bar correct?Adam P.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
661 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
375 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
110 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
574 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
579 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment