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
Force Update Strategy
Collapse
X
-
Force Update Strategy
Is there a way to force update a strategy during a period in which there is no data coming in? I have a strategy that I want to cancel itself after 15 minutes if no trades occur. The issue I'm running into is that there are periods in which there is no data coming in for the stock I'm looking at(pre-and-post-market). During that time if a trade does not occur I need the strategy to re-calculate and terminate itself, but I can't figure out how to force it to calculate on a given interval.Tags: None
-
Hello magnatauren,
If there is not any data coming in that generally means your strategy is not able to execute its logic. You could potentially use a C# timer for this use case, you would need to figure out when to enable the timer so that it could execute after the data stopped.
Strategies have a CloseStrategy method that can be used to disable the strategy however I am not certain if this would work after hours due to it having to try and close positions: https://ninjatrader.com/support/help...=closestrategy
This may present an error message stating that it cannot close orders or there is no data to drive the simulation engine.
A possibly better solution would be to set a bool variable to true when you want to stop trading. If no trades occur in 15 minutes set the bool to true, later in your logic the bool can be used to prevent other logic form happening. That would allow the script to remain enabled and would otherwise just not trade going into the future sessions.
Please let me know if I may be of additional assistance.
JesseNinjaTrader Customer Service
-
Hey Jesse, that's actually what I have set up right now, The issue I'm having is that it will still execute if the stopwatch, which is created during the configure state, which I hope is where I want it, is less than the current time.
Code:else if (State == State.Configure) { AddDataSeries(Data.BarsPeriodType.Volume, 5000); stopWatch = DateTime.Now.AddMinutes(15); } if ((stopWatch <= Time[0] && BarsSinceEntryExecution(1, "Entry", 1) == -1 )) { SetState(State.Terminated); return; }
- Likes 1
Comment
-
Originally posted by magnatauren View PostHey Jesse, that's actually what I have set up right now, The issue I'm having is that it will still execute if the stopwatch, which is created during the configure state, which I hope is where I want it, is less than the current time
Good discussion here.
Comment
-
-
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Adam Klaus, 03-26-2024, 07:43 PM
|
2 responses
21 views
0 likes
|
Last Post
by mcosta72
Today, 12:54 PM
|
||
Started by spottysallrite, Today, 11:31 AM
|
4 responses
9 views
0 likes
|
Last Post Today, 12:53 PM | ||
Started by cozypinto, 12-22-2023, 10:13 AM
|
4 responses
94 views
0 likes
|
Last Post
by Harvard
Today, 12:50 PM
|
||
Started by yaniv, Today, 12:50 PM
|
0 responses
0 views
0 likes
|
Last Post
by yaniv
Today, 12:50 PM
|
||
Started by Padan, Today, 02:02 AM
|
6 responses
18 views
0 likes
|
Last Post
by Padan
Today, 12:50 PM
|
Comment