is there a way of limiting the number of trades executed per bar? Im using an intrabar strategy and I want to only execute a maximum of two trades per bar. Thanks for your help in advance
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Limiting Trades per bar
Collapse
X
-
Limiting Trades per bar
Hello guys,
is there a way of limiting the number of trades executed per bar? Im using an intrabar strategy and I want to only execute a maximum of two trades per bar. Thanks for your help in advanceTags: None
-
Hi there, in order to limit the number of trades per bar, I would recommend monitoring the number of trades placed while inside the secondary (more fine) instrument's BarsInProgress index and resetting the value for every main bar update. Then you can tell the strategy to not place any more trades if it has already placed two.AustinNinjaTrader Customer Service
-
-
Same Problem
I would also like to just make 2 trades per bar in a strategy that is set to On Bar Update False. I tried the Performance.AllTrades.TradesPerformance.MaxConsecW inner < 2 but I had to manually turn it off and on to reset for the next bar. Could I possibly get a piece of sample code for the problem solve suggested here. I looked at the Sample Data Series code but I didn't see how one would reset after the main bar update also how you would keep track of the number of trades executed in the lower time frame.
Thanks for any help.
Comment
-
cre8it8, you will need some sort of counter to keep track of how many orders have been placed per bar, and then reset at the first tick of every new bar with FirstTickOfBar.
The could would probably look something like this:
Code:OnBarUpdate() { if (FirstTickOfBar) thisBarTrades = 0; if (long entry conditions are true) { EnterLong(); thisBarTrades = thisBarTrades + 1; } if (short entry conditions are true) { EnterShort(); thisBarTrades = thisBarTrades + 1; } }
Code:OnBarUpdate() { if(BarsInProgress == 1) // assuming the secondary series (1) is the smaller timeframe { // all of the code I posted above + your code } }
AustinNinjaTrader Customer Service
Comment
-
Thanks Austin for trying to help but it appears to be out of my league so I am going to use the strat I have now and if I like how things are going manually I will pay one of the pros to program it the better way for me.
Thanks again for getting back to me.
Comment
-
Limiting Trades per Bar
It took me a day to figure this out even after reading this thread. An alternative approach without using multi-series time frames (due to the use of countif() in your strategy or for any other reason) is to increment your counter within OnExecution(). Use FirstTickofBar to reset your counter within the same time frame. Within OnExecution() each order fill (buy & sell) is regarded as one count event apiece. Thus, if you want to have 2 trades per bar, the count condition would be
if(tradeCounter < 4)
{ Keep trading....}
Hope this helps...
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by sdauteuil, 09-23-2021, 10:16 AM
|
7 responses
1,247 views
0 likes
|
Last Post
by marcus2300
Today, 01:28 AM
|
||
Started by sofortune, 05-18-2024, 11:48 AM
|
2 responses
32 views
0 likes
|
Last Post Yesterday, 07:11 PM | ||
Started by Zach55, 02-19-2024, 07:22 PM
|
2 responses
65 views
0 likes
|
Last Post
by lbadisa1
Yesterday, 07:06 PM
|
||
Started by JGriff5646, Yesterday, 05:47 PM
|
1 response
14 views
0 likes
|
Last Post Yesterday, 06:45 PM | ||
Started by AlphaOptions, 06-18-2013, 08:24 AM
|
9 responses
2,203 views
0 likes
|
Last Post Yesterday, 06:36 PM |
Comment