Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Entries Count per minute
Collapse
X
-
Hello zachj,
Thank you for your post.
Is the strategy ran on 1 minute bars? If so, you can use BarsSinceEntry() to ensure one bar has passed before submitting a new order. BarsSinceEntry(): http://www.ninjatrader.com/support/h...sinceentry.htm
There are other methods to do this if not using 1 minute bars; such as a ToTime() check: http://www.ninjatrader.com/support/h...nt7/totime.htm
Please let me know if you have any questions.
-
I actually would like to do only one entry per 10min per instrument. 5min is primary series so I would just do?..
if (BarsSinceEntry() > 2)
I'm running a backtest on the whole Nasdaq 100, will this stop it from entering any new positions within 10min for all instruments or will this be only one entry per 10min per instrument? I was looking for just per instrument.
Comment
-
Hello zachj,
Thank you for your response.
If you are using a larger time frame than one minute you can use CalculateOnBarClose = false for real-time data and add a ToTime() check to check if one minute had passed. For backtesting you would have to add in an additional data series (1 minute) as backtesting is always done on historical data so CalculateOnBarClose is always true.
For a reference sample on adding an a smaller timeframe for backtesting please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=6652
Comment
-
I am using... if (BarsSinceEntry() > 5). Just using a 10min time frame, not looking at any other time frame. So basically I want to stop it from triggering a trade if it's already traded in the last 50-60min. When I add this to the script though it doesn't pick up any trades now. I put this in the OnBarUpdate() section. Any idea what could be happening? Code below
update: I found this from another post.. "You cannot use that condition like that because for the very first trade there was no BarsSinceEntry() > 5. You will need to code a set for the first trade and a separate set for subsequent trades you wish to use the BarsSinceEntry logic with. "
So how would I accomplish what is being suggested?
Code:if (BarsSinceEntry() > 5) { if (Close[0] > (Open[0]*percmove)) { EnterLong(Convert.ToInt32(Math.Round(1000/Close[0]))); } else if (Close[0] > (Open[1]*percmove)) { EnterLong(Convert.ToInt32(Math.Round(1000/Close[0]))); } }Last edited by zachj; 08-08-2013, 12:15 PM.
Comment
-
Hello zachj,
Thank you for your post.
The thread you quoted is absolutely correct, you will need to enter that first trade without that condition check. So you could create a bool that is true when the strategy starts, the first trade checks for the bool to be true and enters the first trade as well as sets the bool to false.
Please let me know if you have any questions.
Comment
-
I tried this below but still is not entering any trades, is anything off?
Code:bool entertradecondition = false; Trade firstTrade = Performance.AllTrades[0]; if (firstTrade == null)[INDENT] [LEFT]{ entertradecondition = true; }[/LEFT] [/INDENT]else[INDENT]{ entertradecondition = BarsSinceEntry()>5; } [/INDENT]if (entertradecondition) {[INDENT]if (Close[0] > (Open[0]*percmove)) { EnterLong(Convert.ToInt32(Math.Round(1000/Close[0]))); } else if (Close[0] > (Open[1]*percmove)) { EnterLong(Convert.ToInt32(Math.Round(1000/Close[0]))); } [/INDENT]}
Comment
-
Hello,
Thank you for your response.
I would have done something more similar to the following:
Code:bool entertradecondition = true; if(entertradecondition) { if(YourFirstEntryCondition) { //Your Entry entertradecondition = false; } } if(!entertradecondition) { if (Close[0] > (Open[0]*percmove)) { EnterLong(Convert.ToInt32(Math.Round(1000/Close[0]))); } else if (Close[0] > (Open[1]*percmove)) { EnterLong(Convert.ToInt32(Math.Round(1000/Close[0]))); } }
Comment
-
Hello zachj,
You may be getting an OnBarUpdate error in your log tab about accessing an index with a value that is invalid.
This would be due to the Performance.AllTrades[0] call.
Instead use if (Performance.AllTrades.Count < 1).
Attached is a sample strategy I have made to demonstrate this.
Be sure to open your Output window so that you can see the prints I added.Attached FilesChelsea B.NinjaTrader Customer Service
Comment
-
I tried incorporating your example into my script below but still not getting a trade. See anything obvious I may be missing?....
Code:protected override void OnBarUpdate() { if (Historical) return; bool enterTrade = false; if (Performance.AllTrades.Count <1) { enterTrade = true; } else { enterTrade = BarsSinceEntry() > 5; } if (enterTrade) { if (Position.MarketPosition == MarketPosition.Flat) { if (Close[0] > (Open[0]*percmove)) { EnterLong(Convert.ToInt32(Math.Round(1000/Close[0]))); } else if (Close[0] > (Open[1]*percmove)) { EnterLong(Convert.ToInt32(Math.Round(1000/Close[0]))); } } } //If profit is >=1 set trail at 100 ticks if (Position.MarketPosition == MarketPosition.Long && Close[0] > Position.AvgPrice + 1) { SetTrailStop(CalculationMode.Ticks, 100); } if (Position.MarketPosition == MarketPosition.Long && ToTime(Time[0]) >= 155000) { ExitLong(); } }
Comment
-
Well I was using an extreme amount but I would just go with 5% to be able to get some trades to trigger especially seeing it's only looking back 1 bar. I left the additional else if's out that looked back as far as 6 bars in relation to the current bar Close just to simplify the code.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
577 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
334 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 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
553 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
551 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment